change model
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ rf = Roboflow(api_key="Otg64Ra6wNOgDyjuhMYU")
|
|
11 |
project = rf.workspace("alat-pelindung-diri").project("nescafe-4base")
|
12 |
model = project.version(16).model
|
13 |
|
14 |
-
# Fungsi untuk deteksi objek menggunakan SAHI
|
15 |
def detect_objects(image):
|
16 |
# Menyimpan gambar sementara
|
17 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
|
@@ -29,21 +29,12 @@ def detect_objects(image):
|
|
29 |
overlap_width_ratio=0.1
|
30 |
)
|
31 |
|
32 |
-
#
|
33 |
-
predictions =
|
34 |
-
image_path=temp_file_path,
|
35 |
-
model_path="path_to_your_model",
|
36 |
-
model_type="yolov8", # Adjust based on your model
|
37 |
-
slice_height=256,
|
38 |
-
slice_width=256,
|
39 |
-
overlap_height_ratio=0.1,
|
40 |
-
overlap_width_ratio=0.1,
|
41 |
-
model_confidence_threshold=0.25
|
42 |
-
)
|
43 |
|
44 |
# Postprocess dan gabungkan hasil prediksi
|
45 |
postprocessed_predictions = postprocess_predictions(
|
46 |
-
predictions=predictions,
|
47 |
postprocess_type='NMS',
|
48 |
iou_threshold=0.5
|
49 |
)
|
@@ -58,7 +49,7 @@ def detect_objects(image):
|
|
58 |
# Menghitung jumlah objek per kelas
|
59 |
class_count = {}
|
60 |
for detection in postprocessed_predictions:
|
61 |
-
class_name = detection
|
62 |
if class_name in class_count:
|
63 |
class_count[class_name] += 1
|
64 |
else:
|
|
|
11 |
project = rf.workspace("alat-pelindung-diri").project("nescafe-4base")
|
12 |
model = project.version(16).model
|
13 |
|
14 |
+
# Fungsi untuk deteksi objek menggunakan SAHI dan Roboflow Model
|
15 |
def detect_objects(image):
|
16 |
# Menyimpan gambar sementara
|
17 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
|
|
|
29 |
overlap_width_ratio=0.1
|
30 |
)
|
31 |
|
32 |
+
# Prediksi menggunakan model Roboflow
|
33 |
+
predictions = model.predict(image_path=temp_file_path).json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
# Postprocess dan gabungkan hasil prediksi
|
36 |
postprocessed_predictions = postprocess_predictions(
|
37 |
+
predictions=predictions['predictions'],
|
38 |
postprocess_type='NMS',
|
39 |
iou_threshold=0.5
|
40 |
)
|
|
|
49 |
# Menghitung jumlah objek per kelas
|
50 |
class_count = {}
|
51 |
for detection in postprocessed_predictions:
|
52 |
+
class_name = detection['class']
|
53 |
if class_name in class_count:
|
54 |
class_count[class_name] += 1
|
55 |
else:
|