Spaces:
Sleeping
Sleeping
obj detection seems ok, while segm is off
Browse files
app.py
CHANGED
|
@@ -100,7 +100,7 @@ def run_prediction(image, confidence_threshold, resolution, model_name):
|
|
| 100 |
image_input = image.resize((resolution, resolution))
|
| 101 |
|
| 102 |
if model_name in SEGMENTATION_MODELS:
|
| 103 |
-
return run_segmentation(model, image_input)
|
| 104 |
else:
|
| 105 |
return run_detection(model, image_input, image, confidence_threshold)
|
| 106 |
|
|
@@ -149,7 +149,6 @@ def run_detection(model, image_input, original_image, confidence_threshold):
|
|
| 149 |
return annotated, analytics_text, {"count": len(boxes), "objects": class_counts}
|
| 150 |
|
| 151 |
# Segm code opt 1
|
| 152 |
-
'''
|
| 153 |
def run_segmentation(model, image_input, original_image):
|
| 154 |
mask_tensor = model.predict(image_input)
|
| 155 |
mask_np = mask_tensor.cpu().numpy().astype(np.uint8)
|
|
@@ -196,8 +195,8 @@ def run_segmentation(model, image_input, original_image):
|
|
| 196 |
|
| 197 |
|
| 198 |
return Image.fromarray(blended), analytics_text, {"classes_found": list(found_classes)}
|
| 199 |
-
'''
|
| 200 |
|
|
|
|
| 201 |
# Segm code opt 2
|
| 202 |
def run_segmentation(model, image):
|
| 203 |
"""
|
|
@@ -225,7 +224,7 @@ def run_segmentation(model, image):
|
|
| 225 |
blended = cv2.addWeighted(image_np, 0.6, colored_mask, 0.4, 0)
|
| 226 |
return Image.fromarray(blended)
|
| 227 |
|
| 228 |
-
|
| 229 |
# --- GRADIO UI ---
|
| 230 |
|
| 231 |
theme = gr.themes.Soft(
|
|
|
|
| 100 |
image_input = image.resize((resolution, resolution))
|
| 101 |
|
| 102 |
if model_name in SEGMENTATION_MODELS:
|
| 103 |
+
return run_segmentation(model, image_input, image)
|
| 104 |
else:
|
| 105 |
return run_detection(model, image_input, image, confidence_threshold)
|
| 106 |
|
|
|
|
| 149 |
return annotated, analytics_text, {"count": len(boxes), "objects": class_counts}
|
| 150 |
|
| 151 |
# Segm code opt 1
|
|
|
|
| 152 |
def run_segmentation(model, image_input, original_image):
|
| 153 |
mask_tensor = model.predict(image_input)
|
| 154 |
mask_np = mask_tensor.cpu().numpy().astype(np.uint8)
|
|
|
|
| 195 |
|
| 196 |
|
| 197 |
return Image.fromarray(blended), analytics_text, {"classes_found": list(found_classes)}
|
|
|
|
| 198 |
|
| 199 |
+
'''
|
| 200 |
# Segm code opt 2
|
| 201 |
def run_segmentation(model, image):
|
| 202 |
"""
|
|
|
|
| 224 |
blended = cv2.addWeighted(image_np, 0.6, colored_mask, 0.4, 0)
|
| 225 |
return Image.fromarray(blended)
|
| 226 |
|
| 227 |
+
'''
|
| 228 |
# --- GRADIO UI ---
|
| 229 |
|
| 230 |
theme = gr.themes.Soft(
|