wookimchye commited on
Commit
24a9f93
·
verified ·
1 Parent(s): 2e4d2e2

Upload 2 files

Browse files

Use Yolov8 OBB trained model

Files changed (2) hide show
  1. app.py +67 -0
  2. best.pt +2 -2
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[ ]:
5
+
6
+
7
+ from ultralytics import YOLO
8
+ from PIL import Image, ImageDraw, ImageFont
9
+ import gradio as gr
10
+ from huggingface_hub import snapshot_download
11
+ import os
12
+ import numpy as np
13
+
14
+ # Best Yolov8 trained model
15
+ best_yolo_model = "best.pt"
16
+
17
+ def load_model(repo_id):
18
+ download_dir = snapshot_download(repo_id)
19
+ print(download_dir)
20
+ path = os.path.join(download_dir, "best_int8_openvino_model")
21
+ print(path)
22
+ detection_model = YOLO(path, task='detect')
23
+ return detection_model
24
+
25
+
26
+ def predict(pilimg):
27
+
28
+ detection_model = YOLO(best_yolo_model, task='detect')
29
+
30
+ result = detection_model.predict(pilimg, conf=0.4, iou=0.5)
31
+ #result = detection_model.predict(pilimg)
32
+
33
+ obb = result[0].obb
34
+ confs = obb.conf
35
+ #print("obb : ", obb)
36
+ #print( confidence : ", confs)
37
+
38
+ img_bgr = result[0].plot()
39
+ out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB-order PIL image
40
+
41
+ # Show warning if no object is detected
42
+ if len(result[0].obb.cls) == 0:
43
+ gr.Warning("No object detected!")
44
+
45
+ return out_pilimg
46
+
47
+
48
+ REPO_ID = "ITI107-2024S2/8035531F"
49
+ #detection_model = load_model(REPO_ID)
50
+
51
+ title = "Detect Durian and Mangosteen (King and Queen of Fruits) In The Image"
52
+ interface = gr.Interface(
53
+ fn=predict,
54
+ inputs=gr.Image(type="pil", label="Input Image"),
55
+ outputs=gr.Image(type="pil", label="Object Detection With Confidence Level"),
56
+ title=title,
57
+ )
58
+
59
+ # Launch the interface
60
+ interface.launch(share=True)
61
+
62
+
63
+ # In[ ]:
64
+
65
+
66
+
67
+
best.pt CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:c1e9b98469c201e61f3d6f552273a7188b95158ed2d4c286af84f5f6949af4e1
3
- size 23557388
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8cff4c640a5a463493e4b2b2bba77942376d94a85c2b2824f18b73240b91ae45
3
+ size 23574796