-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Replies: 1 comment · 7 replies
-
Hi @jnc13 , Thanks for your interest here. Thanks. |
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks Nic. Yes, here you go:
Thanks in advance! |
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi, from your code, I'm finding it hard to understand what is being visualised. You have two plots that have the title You should also be able to check with something like |
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi @jnc13 , Thanks for providing the test code, please make sure to use both model.eval()
with torch.no_grad():
# select one image to evaluate and visualize the model output
val_image_to_check = 0 #choose which to observe
example_slice = 40
saver_monai = SegmentationSaver(output_dir="./172modeloutput")
val_input = val_ds[val_image_to_check]["image"].unsqueeze(0).to(device)
val_output = model(val_input)
plt.figure("image", (10, 4))
for i in range(1):
plt.subplot(1, 1, i + 1)
plt.title(f"image channel {i}")
plt.imshow(val_ds[val_image_to_check]["image"][i, :, :, example_slice].detach().cpu(), cmap="gray")
plt.show()
# visualize the 2 channels label corresponding to this image
plt.figure("label", (10, 4))
for i in range(2):
plt.subplot(1, 2, i + 1)
plt.title(f"label channel {i}")
plt.imshow(val_ds[val_image_to_check]["label"][i, :, :, example_slice].detach().cpu())
plt.show()
# visualize the 2 channels model output corresponding to this image
plt.figure("output", (10, 4))
for i in range(2):
plt.subplot(1, 2, i + 1)
plt.title(f"output channel {i}")
plt.imshow(val_output[0, i, :, :, example_slice].detach().cpu())
plt.figure("output binarised", (10, 4))
for i in range(2):
plt.subplot(1, 2, i + 1)
plt.title(f"output channel {i}")
argmax = AsDiscrete(argmax=True,
#n_classes=(2),
logit_thresh=0.1,
)(val_output)
plt.imshow(argmax[0, 0, :, :, example_slice].detach().cpu()) Thanks. |
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks so much @rijobro and @Nic-Ma as ever for coming to the rescue. You're right @rijobro sorry I didn't make it clear in the code. The original screenshot was of the former visualisation block. I was getting a little confused because from how I interpret the BRATS tutorial the transformation "post_trans = Compose([Activations(sigmoid=True), AsDiscrete(threshold_values=True)])" is used within the model creation loop and after which for visualiation just "val_output = model(val_input)" was used without the transforms, I'm not sure how it works in that scenario and not mine? Nevertheless, I've added the transforms for visualisation and it is working as expected. :)
I chose to create a new variable val_output_bin because I quite like seeing the untransformed version output too but you you could instead overwrite val_output. Ignore the poor quality, I've only trained on a few images and didn't use KeepLargestConnectedComponent yet, the important thing is that the pipeline now works. Thanks again both of you, us novices really do appreciate you helping us out! |
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Sounds great! |
Beta Was this translation helpful? Give feedback.
-
Hi,
I've successfully used MONAI for some single-label segmentation and have now moved on to a more complicated multi-label problem for which I've been following the BRATS Brain tutorial.
It runs without any errors and seemingly works fine, the training loader images/labels look good, loss and Dice score both progressing as I'd expect but then have a problem when I get to the end and use the trained model on validation cases. For now I'm using only a few cases at a low res so don't worry about the actual segmentation quality, but I don't know why the result is not binarised?
I have two labels, with greyscale intensity 1 and 2 following the convention as in the BRATS database using "ConvertToMultiChannelBasedOnBratsClassesd" as in the tutorial.
Here is the model:
Edit to add:
Here is the code I used for creating the segmentation figure:
I've tried using argmax & AsDiscrete but think the problem I'm facing occurs before this point.
I'm sure I'm missing something simple but have spent quite a few hours now looking for it! Thanks
Beta Was this translation helpful? Give feedback.
All reactions