下载模型https://github.com/ultralytics/yolov5
环境要求
安装了所有requirements.txt依赖项的Python 3.8或更高版本,包括torch>=1.6
。要安装运行:
没有3.8的要安装内容torch和torchvision链接https://download.pytorch.org/whl/torch_stable.html
# pip install -U -r requirements.txt
Cython
matplotlib>=3.2.2
numpy>=1.18.5
opencv-python>=4.1.2
pillow
# pycocotools>=2.0
PyYAML>=5.3
scipy>=1.4.1
tensorboard>=2.2
torch>=1.6.0
torchvision>=0.7.0
tqdm>=4.41.0
# Conda commands (in place of pip) ---------------------------------------------
# conda update -yn base -c defaults conda
# conda install -yc anaconda numpy opencv matplotlib tqdm pillow ipython
# conda install -yc conda-forge scikit-image pycocotools tensorboard
# conda install -yc spyder-ide spyder-line-profiler
# conda install -yc pytorch pytorch torchvision
# conda install -yc conda-forge protobuf numpy && pip install onnx==1.6.0 # https://github.com/onnx/onnx#linux-and-macos
先conda list看一下,如果有了就不用装了
可以直接$ pip install -r requirements.txt
1.更新 yaml文件中的参数(nc: 80)
以匹配步骤数据集中的类数
data / coco128.yaml是一个小型教程数据集,由COCO train2017 中的前128张图像组成。在此示例中,这些相同的128张图像用于训练和验证。coco128.yaml
定义1)训练图像目录的路径(或带有训练图像列表的* .txt文件的路径),2)与我们的验证图像相同的路径,3)类数,4)类列表名称:
# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
train: ../coco128/images/train2017/
val: ../coco128/images/train2017/
coco128/images/train2017/ #班级数量
nc: 80
# number of classes
nc: 80
# class names
names: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow',
'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard',
'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors',
'teddy bear', 'hair drier', 'toothbrush']
使用Labelbox或CVAT等工具标记图像后,将标签导出为darknet格式,*.txt
每个图像一个文件(如果图像中没有对象,则不需要*.txt
文件)。该*.txt
文件规格有:
- 每个对象一行
- 每行都是
class x_center y_center width height
格式。 - 框坐标必须采用归一化的xywh格式(从0到1)。如果您的框以像素为单位,划分
x_center
和width
通过width,y_center
和height
通过图像height。 - 类号是零索引的(从0开始)。
-
每个图像的标签文件应该可以通过简单地在其路径名中替换
/images/*.jpg
为/labels/*.txt
来定位。示例图像和标签对为:dataset/images/train2017/000000109622.jpg # image dataset/labels/train2017/000000109622.txt # label
Organize your train and val images and labels according to the example below. Note
/coco128
should be next to the/yolov5
directory. Make surecoco128/labels
folder is next tococo128/images
folder.这句不翻译从
./models
文件夹中选择一个模型。在这里,我们选择yolov5s.yaml,这是最小,最快的模型。有关所有型号的完整比较,请参见我们的自述表。选择模型后,如果您不训练COCO,请更新 (nc: 80
) yaml文件中的参数以匹配步骤1中数据集中的类数。模型训练
$ python train.py --data coco.yaml --cfg yolov5s.yaml --weights '' --batch-size 64 yolov5m 48 yolov5l 32 yolov5x 16
测试结果