4-Channel CYMK with single output segmentation map - Error during inference: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0 #3567
I'm currently working on implementing a PSPNET (ResNet50) for segmentation. My goal is to process multimodal images with 4 channels encoded as a .png file with CYMK coding and output a single-channel segmentation map.
During training, everything seems to be functioning well. When training with RGB images (3 channels), I achieve a convergence at 0.7 Dice coefficient. However, when using the same configuration with a fourth channel, the convergence is slightly higher at 0.76 Dice coefficient. It's worth noting that I'm not using a pretrained network.
My intention behind adding this fourth channel is to incorporate another hybrid MRI modality for prostate tumor segmentation. Previously, when working solely with RGB images, the process worked smoothly, and I could compute metrics on the volume.
To be clear, R, G, and B channels represent different MRI modalities.
Now, when I attempt to load CYMK images (4 channels), I encounter a warning:
warnings.warn(
Loads checkpoint by local backend from path: /content/drive/MyDrive/results_hybrid_images/iter_18000.pth
The model and loaded state dict do not match exactly
size mismatch for backbone.stem.0.weight: copying a param with shape torch.Size([32, 3, 3, 3]) from checkpoint, the shape in the current model is torch.Size([32, 4, 3, 3]).
Then, in the script I get this error.
result = inference_model(model,cymk_image) <------
pred_label = result.pred_sem_seg.data.squeeze()
pred_label = pred_label.cpu().numpy().astype(np.uint8)
RuntimeError: The size of tensor a (3) must match the size of tensor b (4) at non-singleton dimension 0
To provide context, I'm calculating the real performance metrics on a test set. I preprocess the original images into hybrid images with 4 channels, maintaining the same field of view (FOV), resulting in images with a shape of (256,256,4). This automation is crucial as I'll be evaluated on a blind test set. Although I process single slices, I eventually reconstruct the volume.
Below is the configuration I'm using, with "<------" highlighting the modifications from the original 3-channel configuration:
Thank you very much for any tips or insights you can provide. I've searched for similar issues, but they are mostly about training rather than inference models.
Hello,
I'm currently working on implementing a PSPNET (ResNet50) for segmentation. My goal is to process multimodal images with 4 channels encoded as a .png file with CYMK coding and output a single-channel segmentation map.
During training, everything seems to be functioning well. When training with RGB images (3 channels), I achieve a convergence at 0.7 Dice coefficient. However, when using the same configuration with a fourth channel, the convergence is slightly higher at 0.76 Dice coefficient. It's worth noting that I'm not using a pretrained network.
My intention behind adding this fourth channel is to incorporate another hybrid MRI modality for prostate tumor segmentation. Previously, when working solely with RGB images, the process worked smoothly, and I could compute metrics on the volume. To be clear, R, G, and B channels represent different MRI modalities.
Now, when I attempt to load CYMK images (4 channels), I encounter a warning:
Then, in the script I get this error.
To provide context, I'm calculating the real performance metrics on a test set. I preprocess the original images into hybrid images with 4 channels, maintaining the same field of view (FOV), resulting in images with a shape of (256,256,4). This automation is crucial as I'll be evaluated on a blind test set. Although I process single slices, I eventually reconstruct the volume.
Below is the configuration I'm using, with "<------" highlighting the modifications from the original 3-channel configuration:
Thank you very much for any tips or insights you can provide. I've searched for similar issues, but they are mostly about training rather than inference models.