OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Issue with Plotting Predicted Masks

  • Thread starter Thread starter Urwa Shanza
  • Start date Start date
U

Urwa Shanza

Guest
I am currently working on a deep learning project 'leaf disease segmentation'. I have trained a model over 50 epochs and obtained the following accuracy and loss metrics: Train Loss: 19.4736, Train Accuracy: 0.9395 Validation Loss: 19.6197, Validation Accuracy: 0.9100 Test Loss: 19.6148, Test Accuracy: 0.9123

However, when I plot the predicted masks, they appear inaccurate. Is there any issue with my plotting code.

Code:
def plot_predictions(model, images, masks, num_samples=5):
    predictions = model.predict(images[:num_samples])
    for i in range(num_samples):
        plt.figure(figsize=(15, 5))
        plt.subplot(1, 3, 1)
        plt.title('Real Image')
        plt.imshow(images[i])
        plt.subplot(1, 3, 2)
        plt.title('Ground Truth Mask')
        plt.imshow(masks[i], cmap='gray')  # Assuming masks are already binary
        plt.subplot(1, 3, 3)
        plt.title('Predicted Mask')
        plt.imshow(predictions[i][:, :, 0], cmap='gray')  # Convert predicted mask to binary
        plt.show()

plot_predictions(model, test_images.numpy(), test_masks_L, num_samples=5)

Original Image-Mask-Predicted Mask

Please review my code and help identify any errors that might be causing this issue?
<p>I am currently working on a deep learning project 'leaf disease segmentation'. I have trained a model over 50 epochs and obtained the following accuracy and loss metrics:
Train Loss: 19.4736, Train Accuracy: 0.9395
Validation Loss: 19.6197, Validation Accuracy: 0.9100
Test Loss: 19.6148, Test Accuracy: 0.9123</p>
<p>However, when I plot the predicted masks, they appear inaccurate. Is there any issue with my plotting code.</p>
<pre><code>def plot_predictions(model, images, masks, num_samples=5):
predictions = model.predict(images[:num_samples])
for i in range(num_samples):
plt.figure(figsize=(15, 5))
plt.subplot(1, 3, 1)
plt.title('Real Image')
plt.imshow(images)
plt.subplot(1, 3, 2)
plt.title('Ground Truth Mask')
plt.imshow(masks, cmap='gray') # Assuming masks are already binary
plt.subplot(1, 3, 3)
plt.title('Predicted Mask')
plt.imshow(predictions[:, :, 0], cmap='gray') # Convert predicted mask to binary
plt.show()

plot_predictions(model, test_images.numpy(), test_masks_L, num_samples=5)
</code></pre>
<p><a href="https://i.sstatic.net/65klcuaB.png" rel="nofollow noreferrer">Original Image-Mask-Predicted Mask</a></p>
<p>Please review my code and help identify any errors that might be causing this issue?</p>
 

Latest posts

Top