Spaces:
Sleeping
Sleeping
fix: normalization of viz
Browse files
app.py
CHANGED
|
@@ -78,8 +78,19 @@ def interface(classifier):
|
|
| 78 |
mask = results["segmentation_mask"]
|
| 79 |
print(mask)
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
overlay = image_np.copy()
|
| 82 |
-
overlay[
|
| 83 |
|
| 84 |
output_str = f"Predicted Class: {results['predicted_class']}\n"
|
| 85 |
output_str += f"Confidence: {results['confidence']*100:.2f}%\n\n"
|
|
|
|
| 78 |
mask = results["segmentation_mask"]
|
| 79 |
print(mask)
|
| 80 |
|
| 81 |
+
# Normalize the mask to 0-1 range based on its min/max values
|
| 82 |
+
if mask.max() > mask.min(): # Avoid division by zero if mask is perfectly flat
|
| 83 |
+
normalized_mask = (mask - mask.min()) / (mask.max() - mask.min())
|
| 84 |
+
else:
|
| 85 |
+
normalized_mask = np.zeros_like(mask) # If flat, just make it all black
|
| 86 |
+
|
| 87 |
+
# Use the normalized mask for visualization
|
| 88 |
+
mask_viz = (normalized_mask * 255).astype(np.uint8)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
binary_for_overlay = normalized_mask > 0.5
|
| 92 |
overlay = image_np.copy()
|
| 93 |
+
overlay[~binary_for_overlay] = (overlay[~binary_for_overlay] * 0.3).astype(np.uint8)
|
| 94 |
|
| 95 |
output_str = f"Predicted Class: {results['predicted_class']}\n"
|
| 96 |
output_str += f"Confidence: {results['confidence']*100:.2f}%\n\n"
|