bnsreenu / python_for_microscopists

https://www.youtube.com/channel/UC34rW-HtPJulxr5wp2Xa04w?sub_confirmation=1
MIT License
3.78k stars 2.35k forks source link

Challenges in Displaying Prediction Results for Full Images (Unpatchify Issue) #68

Open SouCh305 opened 1 year ago

SouCh305 commented 1 year ago

Hello everyone,

I am working on an image segmentation project in the healthcare domain using the UNet model. Due to the lack of data, I have employed data augmentation by dividing the images into smaller patches of dimensions 256 x 256. After training the model, I proceeded to test it on the test data. Unfortunately, I encountered an issue when displaying the prediction result of the full image. However, when I display the patches individually, the prediction results are correct.

Note: I used the code "206_sem_segm_large_images_using_unet_with_patchify.py" for the testing phase.

This is the testing phase of my code:

`patches = patchify(test_img, (256, 256, 3), step = 128) predicted_patches = []

for i in range(patches.shape[0]): for j in range(patches.shape[1]): print(i,j) single_patch = patches[i,j,:,:,:,:] single_patch_prediction = (model.predict(single_patch)[0,:,:,0] > 0.5).astype(np.uint8) predicted_patches.append(single_patch_prediction)

predicted_patches = np.array(predicted_patches)

predicted_patches_reshaped = np.reshape(predicted_patches, (patches.shape[0], patches.shape[1], 256, 256)) new_array = np.expand_dims(predicted_patches_reshaped, axis=2) expnd_array = np.repeat(np.expand_dims(new_array, axis=-1), 3, axis=-1)

reconstructed_image = unpatchify(expnd_array, large_image.shape)`

The prediction result of the full image

image

The prediction results of the patches

image

Thank you for helping me!