add support for HuggingFace Hub for cli

This commit is contained in:
wa22 2024-06-03 23:04:27 +08:00
parent 060af8b8c1
commit dfed201384
2 changed files with 23 additions and 14 deletions

View File

@ -68,17 +68,17 @@ python app.py
## Validation ## Validation
[`yolov10n`](https://huggingface.co/jameslahm/yolov10n) [`yolov10s`](https://huggingface.co/jameslahm/yolov10s) [`yolov10m`](https://huggingface.co/jameslahm/yolov10m) [`yolov10b`](https://huggingface.co/jameslahm/yolov10b) [`yolov10l`](https://huggingface.co/jameslahm/yolov10l) [`yolov10x`](https://huggingface.co/jameslahm/yolov10x) [`yolov10n`](https://huggingface.co/jameslahm/yolov10n) [`yolov10s`](https://huggingface.co/jameslahm/yolov10s) [`yolov10m`](https://huggingface.co/jameslahm/yolov10m) [`yolov10b`](https://huggingface.co/jameslahm/yolov10b) [`yolov10l`](https://huggingface.co/jameslahm/yolov10l) [`yolov10x`](https://huggingface.co/jameslahm/yolov10x)
``` ```
wget https://github.com/THU-MIG/yolov10/releases/download/v1.1/yolov10s.pt yolo val model=jameslahm/yolov10{n/s/m/b/l/x} data=coco.yaml batch=256
yolo val model=yolov10n/s/m/b/l/x.pt data=coco.yaml batch=256
``` ```
Or Or
```python ```python
from ultralytics import YOLOv10 from ultralytics import YOLOv10
model = YOLOv10('yolov10{n/s/m/b/l/x}.pt')
# or
model = YOLOv10.from_pretrained('jameslahm/yolov10{n/s/m/b/l/x}') model = YOLOv10.from_pretrained('jameslahm/yolov10{n/s/m/b/l/x}')
# or
# wget https://github.com/THU-MIG/yolov10/releases/download/v1.1/yolov10{n/s/m/b/l/x}.pt
model = YOLOv10('yolov10{n/s/m/b/l/x}.pt')
model.val(data='coco.yaml', batch=256) model.val(data='coco.yaml', batch=256)
``` ```
@ -96,9 +96,10 @@ from ultralytics import YOLOv10
model = YOLOv10() model = YOLOv10()
# If you want to finetune the model with pretrained weights, you could load the # If you want to finetune the model with pretrained weights, you could load the
# pretrained weights like below # pretrained weights like below
# model = YOLOv10('yolov10{n/s/m/b/l/x}.pt')
# or
# model = YOLOv10.from_pretrained('jameslahm/yolov10{n/s/m/b/l/x}') # model = YOLOv10.from_pretrained('jameslahm/yolov10{n/s/m/b/l/x}')
# or
# wget https://github.com/THU-MIG/yolov10/releases/download/v1.1/yolov10{n/s/m/b/l/x}.pt
# model = YOLOv10('yolov10{n/s/m/b/l/x}.pt')
model.train(data='coco.yaml', epochs=500, batch=256, imgsz=640) model.train(data='coco.yaml', epochs=500, batch=256, imgsz=640)
``` ```
@ -118,16 +119,17 @@ model.push_to_hub("<your-hf-username-or-organization/yolov10-finetuned-crop-dete
## Prediction ## Prediction
Note that a smaller confidence threshold can be set to detect smaller objects or objects in the distance. Please refer to [here](https://github.com/THU-MIG/yolov10/issues/136) for details. Note that a smaller confidence threshold can be set to detect smaller objects or objects in the distance. Please refer to [here](https://github.com/THU-MIG/yolov10/issues/136) for details.
``` ```
yolo predict model=yolov10n/s/m/b/l/x.pt yolo predict model=jameslahm/yolov10{n/s/m/b/l/x}
``` ```
Or Or
```python ```python
from ultralytics import YOLOv10 from ultralytics import YOLOv10
model = YOLOv10('yolov10{n/s/m/b/l/x}.pt')
# or
model = YOLOv10.from_pretrained('jameslahm/yolov10{n/s/m/b/l/x}') model = YOLOv10.from_pretrained('jameslahm/yolov10{n/s/m/b/l/x}')
# or
# wget https://github.com/THU-MIG/yolov10/releases/download/v1.1/yolov10{n/s/m/b/l/x}.pt
model = YOLOv10('yolov10{n/s/m/b/l/x}.pt')
model.predict() model.predict()
``` ```
@ -135,12 +137,12 @@ model.predict()
## Export ## Export
``` ```
# End-to-End ONNX # End-to-End ONNX
yolo export model=yolov10n/s/m/b/l/x.pt format=onnx opset=13 simplify yolo export model=jameslahm/yolov10{n/s/m/b/l/x} format=onnx opset=13 simplify
# Predict with ONNX # Predict with ONNX
yolo predict model=yolov10n/s/m/b/l/x.onnx yolo predict model=yolov10n/s/m/b/l/x.onnx
# End-to-End TensorRT # End-to-End TensorRT
yolo export model=yolov10n/s/m/b/l/x.pt format=engine half=True simplify opset=13 workspace=16 yolo export model=jameslahm/yolov10{n/s/m/b/l/x} format=engine half=True simplify opset=13 workspace=16
# or # or
trtexec --onnx=yolov10n/s/m/b/l/x.onnx --saveEngine=yolov10n/s/m/b/l/x.engine --fp16 trtexec --onnx=yolov10n/s/m/b/l/x.onnx --saveEngine=yolov10n/s/m/b/l/x.engine --fp16
# Predict with TensorRT # Predict with TensorRT
@ -151,9 +153,10 @@ Or
```python ```python
from ultralytics import YOLOv10 from ultralytics import YOLOv10
model = YOLOv10('yolov10{n/s/m/b/l/x}.pt') model = YOLOv10.from_pretrained('jameslahm/yolov10{n/s/m/b/l/x}')
# or # or
model = YOLOv10.from_pretrained('jameslahm/yolov10{n/s/m/b/l/x}.pt') # wget https://github.com/THU-MIG/yolov10/releases/download/v1.1/yolov10{n/s/m/b/l/x}.pt
model = YOLOv10('yolov10{n/s/m/b/l/x}.pt')
model.export(...) model.export(...)
``` ```

View File

@ -1,6 +1,7 @@
# Ultralytics YOLO 🚀, AGPL-3.0 license # Ultralytics YOLO 🚀, AGPL-3.0 license
import contextlib import contextlib
import os
import shutil import shutil
import subprocess import subprocess
import sys import sys
@ -553,7 +554,12 @@ def entrypoint(debug=""):
elif "yolov10" in stem: elif "yolov10" in stem:
from ultralytics import YOLOv10 from ultralytics import YOLOv10
model = YOLOv10(model) # Special case for the HuggingFace Hub
split_path = model.split('/')
if len(split_path) == 2 and (not os.path.exists(model)):
model = YOLOv10.from_pretrained(model)
else:
model = YOLOv10(model)
else: else:
from ultralytics import YOLO from ultralytics import YOLO