Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ from PIL import Image, ImageDraw
|
|
10 |
# Initialize Roboflow
|
11 |
rf = Roboflow(api_key="Otg64Ra6wNOgDyjuhMYU")
|
12 |
project = rf.workspace("alat-pelindung-diri").project("nescafe-4base")
|
13 |
-
model = project.version(
|
14 |
|
15 |
# Apply NMS (Non-Maximum Suppression)
|
16 |
def apply_nms(predictions, iou_threshold=0.5):
|
@@ -85,17 +85,27 @@ def detect_objects(image):
|
|
85 |
print("Failed to access sliced_image_paths attribute.")
|
86 |
sliced_image_paths = []
|
87 |
|
88 |
-
#
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
-
# Predict on each sliced image
|
92 |
-
for sliced_image_path in sliced_image_paths:
|
93 |
-
if isinstance(sliced_image_path, str):
|
94 |
-
predictions = model.predict(image_path=sliced_image_path).json()
|
95 |
-
all_predictions.extend(predictions['predictions'])
|
96 |
-
else:
|
97 |
-
print(f"Skipping invalid image path: {sliced_image_path}")
|
98 |
-
|
99 |
# Apply NMS to remove duplicate detections
|
100 |
postprocessed_predictions = apply_nms(all_predictions, iou_threshold=0.5)
|
101 |
|
|
|
10 |
# Initialize Roboflow
|
11 |
rf = Roboflow(api_key="Otg64Ra6wNOgDyjuhMYU")
|
12 |
project = rf.workspace("alat-pelindung-diri").project("nescafe-4base")
|
13 |
+
model = project.version(16).model
|
14 |
|
15 |
# Apply NMS (Non-Maximum Suppression)
|
16 |
def apply_nms(predictions, iou_threshold=0.5):
|
|
|
85 |
print("Failed to access sliced_image_paths attribute.")
|
86 |
sliced_image_paths = []
|
87 |
|
88 |
+
# Check predictions for the whole image first
|
89 |
+
print("Predicting on the whole image (without slicing)...")
|
90 |
+
whole_image_predictions = model.predict(image_path=temp_file_path).json()
|
91 |
+
print(f"Whole image predictions: {whole_image_predictions}")
|
92 |
+
|
93 |
+
# If there are predictions, return them
|
94 |
+
if whole_image_predictions['predictions']:
|
95 |
+
print("Using predictions from the whole image.")
|
96 |
+
all_predictions = whole_image_predictions['predictions']
|
97 |
+
else:
|
98 |
+
print("No predictions found for the whole image. Predicting on slices...")
|
99 |
+
# If no predictions for the whole image, predict on slices
|
100 |
+
all_predictions = []
|
101 |
+
|
102 |
+
for sliced_image_path in sliced_image_paths:
|
103 |
+
if isinstance(sliced_image_path, str):
|
104 |
+
predictions = model.predict(image_path=sliced_image_path).json()
|
105 |
+
all_predictions.extend(predictions['predictions'])
|
106 |
+
else:
|
107 |
+
print(f"Skipping invalid image path: {sliced_image_path}")
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
# Apply NMS to remove duplicate detections
|
110 |
postprocessed_predictions = apply_nms(all_predictions, iou_threshold=0.5)
|
111 |
|