Spaces:
Runtime error
Runtime error
Commit
·
d89f518
1
Parent(s):
c313ec6
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
import torch
|
| 3 |
from sahi.prediction import ObjectPrediction
|
| 4 |
from sahi.utils.cv import visualize_object_predictions, read_image
|
| 5 |
-
from ultralyticsplus import YOLO
|
| 6 |
|
| 7 |
# Images
|
| 8 |
torch.hub.download_url_to_file('https://huggingface.co/spaces/foduucom/table-extraction-yolov8/resolve/main/test/table1.jpg', 'document1.jpg')
|
|
@@ -28,35 +28,14 @@ def yolov8_inference(
|
|
| 28 |
Rendered image
|
| 29 |
"""
|
| 30 |
model = YOLO(model_path)
|
| 31 |
-
model.conf = conf_threshold
|
| 32 |
-
model.iou
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
for _, image_results in enumerate(results):
|
| 36 |
-
if len(image_results)!=0:
|
| 37 |
-
image_predictions_in_xyxy_format = image_results['det']
|
| 38 |
-
for pred in image_predictions_in_xyxy_format:
|
| 39 |
-
x1, y1, x2, y2 = (
|
| 40 |
-
int(pred[0]),
|
| 41 |
-
int(pred[1]),
|
| 42 |
-
int(pred[2]),
|
| 43 |
-
int(pred[3]),
|
| 44 |
-
)
|
| 45 |
-
bbox = [x1, y1, x2, y2]
|
| 46 |
-
score = pred[4]
|
| 47 |
-
category_name = model.model.names[int(pred[5])]
|
| 48 |
-
category_id = pred[5]
|
| 49 |
-
object_prediction = ObjectPrediction(
|
| 50 |
-
bbox=bbox,
|
| 51 |
-
category_id=int(category_id),
|
| 52 |
-
score=score,
|
| 53 |
-
category_name=category_name,
|
| 54 |
-
)
|
| 55 |
-
object_prediction_list.append(object_prediction)
|
| 56 |
-
|
| 57 |
image = read_image(image)
|
| 58 |
-
|
| 59 |
-
|
|
|
|
| 60 |
|
| 61 |
|
| 62 |
inputs = [
|
|
|
|
| 2 |
import torch
|
| 3 |
from sahi.prediction import ObjectPrediction
|
| 4 |
from sahi.utils.cv import visualize_object_predictions, read_image
|
| 5 |
+
from ultralyticsplus import YOLO, render_result
|
| 6 |
|
| 7 |
# Images
|
| 8 |
torch.hub.download_url_to_file('https://huggingface.co/spaces/foduucom/table-extraction-yolov8/resolve/main/test/table1.jpg', 'document1.jpg')
|
|
|
|
| 28 |
Rendered image
|
| 29 |
"""
|
| 30 |
model = YOLO(model_path)
|
| 31 |
+
model.overrides['conf'] = conf_threshold
|
| 32 |
+
model.overrides['iou']= iou_threshold
|
| 33 |
+
model.overrides['agnostic_nms'] = False # NMS class-agnostic
|
| 34 |
+
model.overrides['max_det'] = 1000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
image = read_image(image)
|
| 36 |
+
render = render_result(model=model, image=image, result=results[0])
|
| 37 |
+
|
| 38 |
+
return render
|
| 39 |
|
| 40 |
|
| 41 |
inputs = [
|