I have a question about the on_validation_epoch_end. My code snipped is here:
self.metric_val_iou = torchmetrics.JaccardIndex(task='multiclass', num_classes=self.network.num_classes)
# logging
epoch = self.trainer.current_epoch
self.logger.experiment.add_scalars('loss', {'val': val_loss_avg}, epoch)
self.log('val_loss', val_loss_avg, on_epoch=True, sync_dist=False)
# compute final metrics over all batches
iou_per_class = self.metric_val_iou.compute()
mIoU = iou_per_class.mean()
self.metric_val_iou.reset()
for class_index, iou_class in enumerate(iou_per_class):
self.logger.experiment.add_scalars(f'iou_class_{class_index}', {'val': iou_class}, epoch)
self.logger.experiment.add_scalars('mIoU', {'val': mIoU}, epoch)
self.log('val_mIoU', mIoU, on_epoch=True, sync_dist=False)
path_to_classwise_iou_dir = os.path.join(self.trainer.log_dir, 'val', 'evaluation', 'iou-classwise',
f'epoch-{epoch:06d}')
save_iou_metric(iou_per_class, path_to_classwise_iou_dir)
self.validation_step_outputs.clear()
When I running, the code is implemented in the "for class_index, iou_class in enumerate(iou_per_class):" incur the Error, my understanding is here iou_per_classes should be a list or other generator,but I got a tensor value.
So do you have any suggestions? I would greatly appreciate it.