Soft_Dice_Loss and Tensorflow v1 /v2 MRI segmentation

Hi,
I’m trying to implement the multi-class version of soft_dice_loss but facing the difficulty that test cases include both single-class and multi-class inputs, for example :
print(“Case 4:\n”)
print(“Pred:\n”)
print(pred_4[0, :, :, 0])
print(“\nLabel:\n”)
print(label_4[0, :, :, 0]) .

The function expects tensors (num_classes, x_dim, y_dim, z_dim) but the test cases use a mixture . I need a way to handle both 3D and 4D inputs with the same function. Do I need to add 1 dim to the 3D tensors ?

2dly , the code seems to run in Tensorflow 1 , with sessions and tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
Is it compatible with Tensorflow 2 code we might use somewhere in the notebook ?
@Deepti_Prasad
Thanks

hi @user440

is this assignment codes you are talking about?

can you post screenshot of your failed unittest so I can understand what are you trying?

I also didn’t understand tensorflow 1 and tensorflow 2 question.

Please post screenshot of your unittest output and/or error you have encountered. Keep in mind while you post screenshot, no part of grade function codes should be posted on public post here as it is against community guidelines.

You can refer to this thread which explains hard-coding implementation can cause issues in implementation, also about adding dim, the comment has explain ation, that each value added is about not adding dim, but selective value mentioning, adds the correct dimention to the output.

regards

Dr. Deepti

Hello Dr Deepti, @Deepti_Prasad
Indeed, this is about C1W3 assignment.
Re the multi class version for Dice_coefficient (Exercise 4) and Soft_Dice_loss (Exercise 5), I encountered a problem due partly to the instructions : “Compute mean soft dice loss over all abnormality classes.” This made me write the function a certain way but resulted in errors.
I tried another way and managed to get the expected results. But I don’t quite understand, so I will send you a screenshot of the results with 1st method I used.
Regarding Tensorflow, in the import packages section we have import support_files.keras_sessions as keras_sessions and tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) and in Exercise 1 we have “Please use the [Keras.sum(x,axis=)]” which links to https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/backend/sum so Tensorflow 1
The current version is Tensorflow 2. If we were to rewrite the # Verification of implementation in Tensorflow 2 ,would it require a lot of changes? I think sessions have been deprecated in TF2.

@user440

The labs of this course probably uses only some part of tensorflow version, limited to categorical choice of labels and shouldn’t be issue as long as you are running the codes in course provided platform.

Ofcourse one will have to make many changes with many of tensorflow libraries being deprecated.

You can try and let me know how was the experience :zany_face:

Regards
Dr. Deepti

1 Like