端侧目标检测算法 YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite https://github.com/ultralytics/yolov5
天问 82f33a8b75 Update 'README.md' | 6 months ago | |
---|---|---|
.gitignore | 2 years ago | |
LICENSE | 2 years ago | |
README.md | 6 months ago |
YOLOv3 in PyTorch > ONNX > CoreML > TFLite https://github.com/ultralytics/yolov3
YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite https://github.com/ultralytics/yolov5
YOLOv6论文:https://arxiv.org/abs/2209.02976
YOLOv6代码:https://github.com/meituan/YOLOv6
YOLOSeries代码:https://github.com/nemonameless/PaddleDetection_YOLOSeries
PPYOLOE论文:https://arxiv.org/abs/2203.16250
PaddleDetection代码:https://github.com/PaddlePaddle/PaddleDetection
引入了双重标签分配策略,训练阶段使用一对多的检测头提供更多的正样本来丰富模型的训练;推理阶段则通过梯度截断的方式,切换为一对一的检测头,如此一来便不在需要 NMS 后处理,在保持性能的同时减少了推理开销。
YOLOv10-N:用于资源极其有限的环境下的版本。
推理:
# 安装依赖
!pip install supervision git+https://github.com/THU-MIG/yolov10.git
# 下载模型
from modelscope import snapshot_download
MODEL_PATH = snapshot_download('THU-MIG/Yolov10')
# 推理代码
from ultralytics import YOLOv10
import supervision as sv
import cv2
from IPython.display import Image
#下载示例图片
!wget -P /mnt/workspace/ -q https://modelscope.oss-cn-beijing.aliyuncs.com/resource/image_detection.png
IMAGE_PATH = '/mnt/workspace/image_detection.png'
model = YOLOv10(f'{MODEL_PATH}/yolov10n.pt')
image = cv2.imread(IMAGE_PATH)
results = model(source=image, conf=0.25, verbose=False)[0]
detections = sv.Detections.from_ultralytics(results)
box_annotator = sv.BoxAnnotator()
category_dict = {
0: 'person', 1: 'bicycle', 2: 'car', 3: 'motorcycle', 4: 'airplane', 5: 'bus',
6: 'train', 7: 'truck', 8: 'boat', 9: 'traffic light', 10: 'fire hydrant',
11: 'stop sign', 12: 'parking meter', 13: 'bench', 14: 'bird', 15: 'cat',
16: 'dog', 17: 'horse', 18: 'sheep', 19: 'cow', 20: 'elephant', 21: 'bear',
22: 'zebra', 23: 'giraffe', 24: 'backpack', 25: 'umbrella', 26: 'handbag',
27: 'tie', 28: 'suitcase', 29: 'frisbee', 30: 'skis', 31: 'snowboard',
32: 'sports ball', 33: 'kite', 34: 'baseball bat', 35: 'baseball glove',
36: 'skateboard', 37: 'surfboard', 38: 'tennis racket', 39: 'bottle',
40: 'wine glass', 41: 'cup', 42: 'fork', 43: 'knife', 44: 'spoon', 45: 'bowl',
46: 'banana', 47: 'apple', 48: 'sandwich', 49: 'orange', 50: 'broccoli',
51: 'carrot', 52: 'hot dog', 53: 'pizza', 54: 'donut', 55: 'cake',
56: 'chair', 57: 'couch', 58: 'potted plant', 59: 'bed', 60: 'dining table',
61: 'toilet', 62: 'tv', 63: 'laptop', 64: 'mouse', 65: 'remote', 66: 'keyboard',
67: 'cell phone', 68: 'microwave', 69: 'oven', 70: 'toaster', 71: 'sink',
72: 'refrigerator', 73: 'book', 74: 'clock', 75: 'vase', 76: 'scissors',
77: 'teddy bear', 78: 'hair drier', 79: 'toothbrush'
}
labels = [
f"{category_dict[class_id]} {confidence:.2f}"
for class_id, confidence in zip(detections.class_id, detections.confidence)
]
annotated_image = box_annotator.annotate(
image.copy(), detections=detections, labels=labels
)
cv2.imwrite('annotated_demo.jpeg', annotated_image)
Image(filename='annotated_demo.jpeg', height=600)
# 预测
yolo predict model=yolov10s.pt source=ultralytics/assets/bus.jpg
# 导出onnx格式模型
yolo export model=yolov10s.pt format=onnx opset=13 simplify
import netron
netron.start('/path/to/yolov10s.onnx')
yolo predict model=yolov10s.onnx source=ultralytics/assets/bus.jpg
训练:
!mkdir /mnt/workspace/datasets
%cd /mnt/workspace/datasets
# Refer to: https://modelscope.cn/datasets/AI-ModelScope/tumor-dj2a1/summary
!git clone https://www.modelscope.cn/datasets/AI-ModelScope/tumor-dj2a1.git
%cd /mnt/workspace/
!yolo task=detect mode=train epochs=10 batch=32 plots=True \
model={MODEL_PATH}/yolov10n.pt \
data=/mnt/workspace/datasets/tumor-dj2a1/data.yaml
from ultralytics import YOLOv10
model = YOLOv10('/mnt/workspace/runs/detect/train2/weights/best.pt')
dataset = sv.DetectionDataset.from_yolo(
images_directory_path="/mnt/workspace/datasets/tumor-dj2a1/valid/images",
annotations_directory_path="/mnt/workspace/datasets/tumor-dj2a1/valid/labels",
data_yaml_path="/mnt/workspace/datasets/tumor-dj2a1/data.yaml"
)
bounding_box_annotator = sv.BoundingBoxAnnotator()
label_annotator = sv.LabelAnnotator()
import random
random_image = random.choice(list(dataset.images.keys()))
random_image = dataset.images[random_image]
results = model(source=random_image, conf=0.25)[0]
detections = sv.Detections.from_ultralytics(results)
annotated_image = bounding_box_annotator.annotate(
scene=random_image, detections=detections)
annotated_image = label_annotator.annotate(
scene=annotated_image, detections=detections)
sv.plot_image(annotated_image)