1ngsm0del commited on
Commit
7a5d030
1 Parent(s): 26946a9

first commit

Browse files
RXBASE-600_00071-1014-68_NLMIMAGE10_5715ABFD.jpg ADDED
RXBASE-600_00074-7126-13_NLMIMAGE10_C003606B.jpg ADDED
RXNAV-600_13668-0095-90_RXNAVIMAGE10_D145E8EF.jpg ADDED
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import supervision as sv
4
+ from ultralytics import YOLOv10
5
+ # https://www.youtube.com/watch?v=h53XYgKzYYE&t=1534s
6
+ # https://github.com/Codewello/Yolo-v8-and-hugginface/blob/main/hugginface/app.py
7
+ # https://www.youtube.com/watch?v=29tnSxhB3CY&t=564s
8
+ # https://colab.research.google.com/drive/1Sv3_0S4zhZT763bBMjYxf0HhTit4Bvh6?usp=sharing#scrollTo=kAi4PvrItTCf
9
+ # https://github.com/roboflow/supervision/blob/develop/demo.ipynb
10
+ def yoloV10_func(image: gr.Image() = None,
11
+ image_size: gr.Slider() = 640,
12
+ conf_threshold: gr.Slider() = 0.25,
13
+ iou_threshold: gr.Slider() = 0.45):
14
+ """This function performs YOLOv10 object detection on the given image.
15
+
16
+ Args:
17
+ image (gr.Image, optional): Input image to detect objects on. Defaults to None.
18
+ image_size (gr.Slider, optional): Desired image size for the model. Defaults to 640.
19
+ conf_threshold (gr.Slider, optional): Confidence threshold for object detection. Defaults to 0.4.
20
+ iou_threshold (gr.Slider, optional): Intersection over Union threshold for object detection. Defaults to 0.50.
21
+ """
22
+ # Load the YOLOv10 model from the 'best.pt' checkpoint
23
+ model_path = './drug_yolov10.pt'
24
+ model = YOLOv10(model_path)
25
+
26
+ # Perform object detection on the input image using the YOLOv10 model
27
+ results = model.predict(image,
28
+ conf=conf_threshold,
29
+ iou=iou_threshold,
30
+ imgsz=image_size)
31
+
32
+ # Print the detected objects' information (class, coordinates, and probability)
33
+ box = results[0].boxes
34
+ print("Object type:", box.cls)
35
+ print("Coordinates:", box.xyxy)
36
+ print("Probability:", box.conf)
37
+
38
+ # Render the output image with bounding boxes around detected objects
39
+ # render = render_result(model=model, image=image, result=results[0])
40
+ # results = model(image)[0]
41
+ detections = sv.Detections.from_ultralytics(results[0])
42
+ box_annotator = sv.BoxAnnotator()
43
+ labels = [
44
+ f"{model.model.names[class_id]} {confidence:.2f}"
45
+ for class_id, confidence in zip(detections.class_id, detections.confidence)
46
+ ]
47
+ image = cv2.imread(image)
48
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
49
+ annotated_image = box_annotator.annotate(
50
+ image.copy(), detections=detections, labels=labels
51
+ )
52
+ return annotated_image
53
+ inputs = [
54
+ gr.Image(type="filepath", label="Input Image"),
55
+ gr.Slider(minimum=120, maximum=1280, value=640,
56
+ step=32, label="Image Size"),
57
+ gr.Slider(minimum=0.0, maximum=1.0, value=0.25,
58
+ step=0.05, label="Confidence Threshold"),
59
+ gr.Slider(minimum=0.0, maximum=1.0, value=0.45,
60
+ step=0.05, label="IOU Threshold"),
61
+ ]
62
+ outputs = gr.Image(type="filepath", label="Output Image")
63
+
64
+ title = "YOLOv10 101: Custom Object Detection on Pill Types"
65
+
66
+
67
+ examples = [['RXNAV-600_13668-0095-90_RXNAVIMAGE10_D145E8EF.jpg', 640, 0.2, 0.7],
68
+ ['RXBASE-600_00071-1014-68_NLMIMAGE10_5715ABFD.jpg', 280, 0.2, 0.6],
69
+ ['RXBASE-600_00074-7126-13_NLMIMAGE10_C003606B.jpg', 640, 0.2, 0.8]]
70
+ yolo_app = gr.Interface(
71
+ fn=yoloV10_func,
72
+ inputs=inputs,
73
+ outputs=outputs,
74
+ title=title,
75
+ examples=examples,
76
+ cache_examples=True,
77
+ )
78
+ # Launch the Gradio interface in debug mode with queue enabled
79
+ yolo_app.launch(debug=True)
drug_yolov10.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d953e3db8e56519197a3e6d74d2b078226f7f1cf1de07064631003acb4a493f3
3
+ size 33211887
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio==4.32.1
2
+ opencv_python==4.8.1.78
3
+ opencv_python_headless==4.8.0.74
4
+ supervision==0.20.0
5
+ git+https://github.com/THU-MIG/yolov10.git