Skip to content

Commit b78eaaa

Browse files
committed
sample script for inference
1 parent df7b3f6 commit b78eaaa

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*/__pycache__
1+
**/*/__pycache__
22
/.idea
33
*.pt
44
*.onnx

README.md

+5-18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Differences between original repository and fork:
44

55
* Compatibility with PyTorch >=2.0. (🔥)
6+
* Sample script [detect.py](detect.py) for inference.
67

78
# Installation
89

@@ -20,22 +21,8 @@ pip install -r requirements.txt
2021
| yolov8s | 640 | 96.0 | 94.2 | 82.6 | - | - |
2122
| yolov8m | 640 | 96.6 | 95.0 | 84.1 | - | - |
2223

24+
# Inference
2325

24-
25-
#### yolov8n-face
26-
27-
![yolov8n-face](data/test.jpg)
28-
29-
30-
#### demo
31-
32-
* [yolov8-face-landmarks-opencv-dnn](https://github.com/hpc203/yolov8-face-landmarks-opencv-dnn)
33-
34-
35-
#### References
36-
37-
* [https://github.com/ultralytics/ultralytics](https://github.com/ultralytics/ultralytics)
38-
39-
* [https://github.com/deepcam-cn/yolov5-face](https://github.com/deepcam-cn/yolov5-face)
40-
41-
* [https://github.com/derronqi/yolov7-face](https://github.com/derronqi/yolov7-face)
26+
```shell
27+
python detect.py --weights yolov8n-face.pt --source ultralytics/assets/bus.jpg --save-img
28+
```

detect.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import argparse
2+
from ultralytics import YOLO
3+
4+
5+
if __name__ == '__main__':
6+
parser = argparse.ArgumentParser()
7+
parser.add_argument('--weights', type=str, default='./yolov8n-face.pt', help='model.pt path(s)')
8+
parser.add_argument('--source', type=str, default='./ultralytics/assets/bus.jpg', help='source')
9+
parser.add_argument('--img-size', nargs='+', type=int, default=640, help='inference size (pixels)')
10+
parser.add_argument('--conf-thres', type=float, default=0.6, help='object confidence threshold')
11+
parser.add_argument('--iou-thres', type=float, default=0.5, help='IOU threshold for NMS')
12+
parser.add_argument('--device', default='0', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
13+
parser.add_argument('--save-img', action='store_true', help='save results')
14+
opt = parser.parse_args()
15+
16+
model = YOLO(opt.weights)
17+
model.predict(
18+
source=opt.source,
19+
imgsz=opt.img_size,
20+
conf=opt.conf_thres,
21+
iou=opt.iou_thres,
22+
device=opt.device,
23+
save=opt.save_img
24+
)

test_widerface.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
if __name__ == '__main__':
66
parser = argparse.ArgumentParser()
7-
parser.add_argument('--weights', nargs='+', type=str, default='runs/pose/yolov8n-face/weights/best.pt', help='model.pt path(s)')
7+
parser.add_argument('--weights', nargs='+', type=str, default='./yolov8n-face.pt', help='model.pt path(s)')
88
parser.add_argument('--img-size', nargs= '+', type=int, default=640, help='inference size (pixels)')
99
parser.add_argument('--conf-thres', type=float, default=0.01, help='object confidence threshold')
1010
parser.add_argument('--iou-thres', type=float, default=0.5, help='IOU threshold for NMS')

0 commit comments

Comments
 (0)