/// Multi-label classification output adapted for multiple metrics. /// /// Supported metrics: /// - HammingScore /// - Precision (via ConfusionStatsInput) /// - Recall (via ConfusionStatsInput) /// - FBetaScore (via ConfusionStatsInput) /// - Loss #[derive(new)] pub struct MultiLabelSoftClassificationOutput { /// The loss. pub loss: Tensor, /// The label logits or probabilities. Shape: \[batch_size, num_classes\]. pub output: Tensor, /// The ground truth labels (target values). Shape: \[batch_size, num_classes\]. pub targets: Tensor, } impl ItemLazy for MultiLabelSoftClassificationOutput { type ItemSync = MultiLabelSoftClassificationOutput; fn sync(self) -> Self::ItemSync { let [output, loss, targets] = Transaction::default() .register(self.output) .register(self.loss) .register(self.targets) .execute() .try_into() .expect("Correct amount of tensor data"); let device = &Default::default(); MultiLabelSoftClassificationOutput { output: Tensor::from_data(output, device), loss: Tensor::from_data(loss, device), targets: Tensor::from_data(targets, device), } } } impl Adaptor> for MultiLabelSoftClassificationOutput { fn adapt(&self) -> HammingScoreInput { HammingScoreInput::new(self.output.clone(), self.targets.clone()) } } impl Adaptor> for MultiLabelSoftClassificationOutput { fn adapt(&self) -> LossInput { LossInput::new(self.loss.clone()) } } impl Adaptor> for MultiLabelSoftClassificationOutput { fn adapt(&self) -> ConfusionStatsInput { ConfusionStatsInput::new(self.output.clone(), self.targets.clone().bool()) } }