UNET prediction

Question:

I use unet for image segmentation my question is what does below code mean

test_img_norm=test_img[:,:,0][:,:,None] 

and

prediction_other = (model.predict(test_img_other_input)[0,:,:,0] > 0.2).astype(np.uint8)
Asked By: Ahmed Gaber

||

Answers:

About first question test_img_norm=test_img[:,:,0][:,:,None], test_img[:,:,0] will copy first channel of image and test_img[:,:,0][:,:,None] will add one channel to it. for example if you have an image with shape (256, 256, 3), test_img_norm shape will be (256, 256, 1).

About second part of question, model.predict(test_img_other_input)[0,:,:,0] > 0.2 will give you a boolean array. For every element in output of UNet, if element is less than 0.2, output would be True, otherwise would be False. And finally .astype(np.uint8) make booleans to zero or one.

Answered By: Mohammad Khoshbin