muhammadsalmanalfaridzi commited on
Commit
2af14ab
·
verified ·
1 Parent(s): c54f5ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -5,7 +5,6 @@ import supervision as sv
5
  from roboflow import Roboflow
6
  import tempfile
7
  import os
8
- from sahi import AutoDetectionModel
9
  from sahi.predict import predict
10
  from dotenv import load_dotenv
11
 
@@ -21,9 +20,6 @@ rf = Roboflow(api_key=api_key)
21
  project = rf.workspace(workspace).project(project_name)
22
  model = project.version(model_version).model
23
 
24
- # Initialize SAHI model for inference
25
- detection_model = AutoDetectionModel.from_pretrained(model)
26
-
27
  def detect_objects(image):
28
  # Save the uploaded image to a temporary file
29
  with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
@@ -34,15 +30,15 @@ def detect_objects(image):
34
  original_image = cv2.imread(temp_file_path)
35
 
36
  try:
37
- # Perform inference using SAHI Slicer
38
  predictions = predict(
39
- detection_model=detection_model,
40
  image=original_image,
41
- slice_height=800, # Height of the slice
42
- slice_width=800, # Width of the slice
43
  overlap_height_ratio=0.2,
44
  overlap_width_ratio=0.2,
45
- return_slice_result=False,
46
  )
47
 
48
  # Initialize Supervision annotations
 
5
  from roboflow import Roboflow
6
  import tempfile
7
  import os
 
8
  from sahi.predict import predict
9
  from dotenv import load_dotenv
10
 
 
20
  project = rf.workspace(workspace).project(project_name)
21
  model = project.version(model_version).model
22
 
 
 
 
23
  def detect_objects(image):
24
  # Save the uploaded image to a temporary file
25
  with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
 
30
  original_image = cv2.imread(temp_file_path)
31
 
32
  try:
33
+ # Use SAHI to slice the image (optional for large images)
34
  predictions = predict(
35
+ detection_model=model, # Use Roboflow model for prediction
36
  image=original_image,
37
+ slice_height=800, # Height of each slice
38
+ slice_width=800, # Width of each slice
39
  overlap_height_ratio=0.2,
40
  overlap_width_ratio=0.2,
41
+ return_slice_result=False, # We don't need slice results, just detections
42
  )
43
 
44
  # Initialize Supervision annotations