Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ import os
|
|
9 |
# Load environment variables from .env file
|
10 |
load_dotenv()
|
11 |
api_key = os.getenv("ROBOFLOW_API_KEY")
|
12 |
-
model_id = os.getenv("ROBOFLOW_PROJECT")
|
13 |
model_version = os.getenv("ROBOFLOW_MODEL_VERSION")
|
14 |
|
15 |
# Initialize the Roboflow model
|
@@ -26,7 +26,7 @@ def detect_objects_with_sahi(image):
|
|
26 |
image_np = np.array(image)
|
27 |
|
28 |
# Run inference with SAHI Slicer
|
29 |
-
slicer = sv.InferenceSlicer(callback=callback)
|
30 |
sliced_detections = slicer(image=image_np)
|
31 |
|
32 |
# Annotate image with detected objects
|
@@ -37,7 +37,7 @@ def detect_objects_with_sahi(image):
|
|
37 |
|
38 |
# Count objects by class
|
39 |
class_counts = {}
|
40 |
-
for detection in sliced_detections:
|
41 |
class_name = detection.class_id
|
42 |
class_counts[class_name] = class_counts.get(class_name, 0) + 1
|
43 |
|
|
|
9 |
# Load environment variables from .env file
|
10 |
load_dotenv()
|
11 |
api_key = os.getenv("ROBOFLOW_API_KEY")
|
12 |
+
model_id = os.getenv("ROBOFLOW_PROJECT")
|
13 |
model_version = os.getenv("ROBOFLOW_MODEL_VERSION")
|
14 |
|
15 |
# Initialize the Roboflow model
|
|
|
26 |
image_np = np.array(image)
|
27 |
|
28 |
# Run inference with SAHI Slicer
|
29 |
+
slicer = sv.InferenceSlicer(callback=callback, overlap_wh=(50, 50))
|
30 |
sliced_detections = slicer(image=image_np)
|
31 |
|
32 |
# Annotate image with detected objects
|
|
|
37 |
|
38 |
# Count objects by class
|
39 |
class_counts = {}
|
40 |
+
for detection in sliced_detections.detections: # Access .detections for the actual list
|
41 |
class_name = detection.class_id
|
42 |
class_counts[class_name] = class_counts.get(class_name, 0) + 1
|
43 |
|