I tried to expand and diversify the training dataset by patchifying the images into small partitions of 256x256 pixels. Then, I applied the “Albumentations” function to create new images by making some transformations on the original image which helped augment the training images.
After training the U-Net model on the new training dataset, I wanted to see how well it performed on the test dataset. The testing process was achieved by these steps: patchifying the test image into small partitions, applying the trained U-Net model to each of these patches, unpatchifying the results to create a full image.
NB: For the testing phase, I utilized the code “206_sem_segm_large_images_using_unet_with_patchify.py” from Dr. Sreenivas Bhattiprolu's Github repository. 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 results of each patch
The prediction result of the full image
When attempting to display the predictions of the full image, they didn’t match what I expected, but when I displayed the patches individually the model’s predictions were accurate. This made me think that the problem might be related to the “unpatchify” function (You can find prediction image results above).
How can I solve this problem? Is there any solution you could suggest it for me?