fendiprime
commited on
Commit
•
c75a467
1
Parent(s):
2ce0023
Describe how to use the model
Browse files
README.md
CHANGED
@@ -7,4 +7,51 @@ language:
|
|
7 |
metrics:
|
8 |
- accuracy
|
9 |
pipeline_tag: object-detection
|
10 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
metrics:
|
8 |
- accuracy
|
9 |
pipeline_tag: object-detection
|
10 |
+
---
|
11 |
+
|
12 |
+
## How to Get Started with the Model
|
13 |
+
|
14 |
+
### Install `ultralytics YOLO` package
|
15 |
+
|
16 |
+
``` shell
|
17 |
+
$ pip install ultralytics
|
18 |
+
```
|
19 |
+
|
20 |
+
### Perform Inference as per [kurkurzz](https://github.com/kurkurzz/custom-yolov8-auto-annotation-cvat-blueprint/blob/master/main.py)
|
21 |
+
|
22 |
+
``` python
|
23 |
+
from ultralytics import YOLO
|
24 |
+
from json import dumps
|
25 |
+
|
26 |
+
checkpoint_path = "path/to/model/weight.pt" # e.g weights/best.pt in this directory
|
27 |
+
model = YOLO(checkpoint_path)
|
28 |
+
|
29 |
+
image_path = "path/to/image"
|
30 |
+
infered = model(image_path)
|
31 |
+
results = infered[0]
|
32 |
+
|
33 |
+
boxes = result.boxes.data[:,:4]
|
34 |
+
confs = result.boxes.conf
|
35 |
+
clss = result.boxes.cls
|
36 |
+
class_name = result.names
|
37 |
+
|
38 |
+
#detected = results[0].boxes.xywh # or xywhn, xyxy pr xyxyn
|
39 |
+
|
40 |
+
detections = []
|
41 |
+
threshold = 0.3 # 0 < threshold <= 1
|
42 |
+
|
43 |
+
for box, conf, cls in zip(boxes, confs, clss):
|
44 |
+
label = class_name[int(cls)]
|
45 |
+
if conf >= threshold:
|
46 |
+
# must be in this format
|
47 |
+
detections.append({
|
48 |
+
'confidence': str(float(conf)),
|
49 |
+
'label': label,
|
50 |
+
'points': box.tolist(),
|
51 |
+
'type': 'rectangle',
|
52 |
+
})
|
53 |
+
|
54 |
+
detected_objects = dumps(detections)
|
55 |
+
print(detected_objects)
|
56 |
+
|
57 |
+
```
|