Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,12 +10,12 @@ from PIL import Image
|
|
10 |
model_path = 'best.pt' # Replace with the path to your trained .pt file
|
11 |
model = YOLO(model_path)
|
12 |
|
13 |
-
# Define the class indices for figures and tables
|
14 |
figure_class_index = 3 # class index for figures
|
15 |
table_class_index = 4 # class index for tables
|
16 |
|
17 |
# Function to perform inference on an image and return bounding boxes for figures and tables
|
18 |
-
def infer_image_and_get_boxes(image):
|
19 |
# Convert the image from BGR to RGB
|
20 |
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
21 |
|
@@ -27,7 +27,8 @@ def infer_image_and_get_boxes(image):
|
|
27 |
for result in results:
|
28 |
for box in result.boxes:
|
29 |
cls = int(box.cls[0])
|
30 |
-
|
|
|
31 |
x1, y1, x2, y2 = map(int, box.xyxy[0])
|
32 |
boxes.append((x1, y1, x2, y2))
|
33 |
|
|
|
10 |
model_path = 'best.pt' # Replace with the path to your trained .pt file
|
11 |
model = YOLO(model_path)
|
12 |
|
13 |
+
# Define the class indices for figures and tables
|
14 |
figure_class_index = 3 # class index for figures
|
15 |
table_class_index = 4 # class index for tables
|
16 |
|
17 |
# Function to perform inference on an image and return bounding boxes for figures and tables
|
18 |
+
def infer_image_and_get_boxes(image, confidence_threshold=0.6):
|
19 |
# Convert the image from BGR to RGB
|
20 |
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
21 |
|
|
|
27 |
for result in results:
|
28 |
for box in result.boxes:
|
29 |
cls = int(box.cls[0])
|
30 |
+
confidence = box.conf[0]
|
31 |
+
if (cls == figure_class_index or cls == table_class_index) and confidence > confidence_threshold:
|
32 |
x1, y1, x2, y2 = map(int, box.xyxy[0])
|
33 |
boxes.append((x1, y1, x2, y2))
|
34 |
|