https://github.com/WongKinYiu/yolov7
pip install -r requirements.txt
pip install pycocotools
删除原有的cache文件,整理成这个结构:
在yolov7项目下面使用ln -s /ssd/xiedong/datasets/coco2017/coco coco
把数据软链接过来。
releases资源:https://github.com/WongKinYiu/yolov7/releases
下载自己想要的预训练权重放于新建的weights目录下。
测试yolov7-tiny.pt:
(py37c) xiedong@ubuntu:/ssd/xiedong/workplace/yolov7$ python test.py --data data/coco.yaml --img 640 --batch 32 --conf 0.001 --iou 0.65 --device 0 --weights weights/yolov7-tiny.pt --name yolov7_640_val
Namespace(augment=False, batch_size=32, conf_thres=0.001, data='data/coco.yaml', device='0', exist_ok=False, img_size=640, iou_thres=0.65, name='yolov7_640_val', no_trace=False, project='runs/test', save_conf=False, save_hybrid=False, save_json=True, save_txt=False, single_cls=False, task='val', v5_metric=False, verbose=False, weights=['weights/yolov7-tiny.pt'])
YOLOR 2022-11-4 torch 1.12.1+cu116 CUDA:0 (NVIDIA A100-PCIE-40GB, 40390.0625MB)
Fusing layers...
Model Summary: 200 layers, 6219709 parameters, 6219709 gradients
Convert model to Traced-model...
/ssd/xiedong/miniconda3/envs/py37c/lib/python3.7/site-packages/torch/_tensor.py:1083: UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad attribute won't be populated during autograd.backward(). If you indeed want the .grad field to be populated for a non-leaf Tensor, use .retain_grad() on the non-leaf Tensor. If you access the non-leaf Tensor by mistake, make sure you access the leaf Tensor instead. See github.com/pytorch/pytorch/pull/30531 for more informations. (Triggered internally at aten/src/ATen/core/TensorBody.h:477.)
return self._grad
traced_script_module saved!
model is traced!
/ssd/xiedong/miniconda3/envs/py37c/lib/python3.7/site-packages/torch/functional.py:478: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:2894.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
val: Scanning 'coco/val2017.cache' images and labels... 4952 found, 48 missing, 0 empty, 0 corrupted: 100%|██████████████████████████████████| 5000/5000 [00:00<?, ?it/s]
Class Images Labels P R [email protected] [email protected]:.95: 100%|████████████████████████████████████| 157/157 [00:39<00:00, 4.01it/s]
all 5000 36335 0.646 0.51 0.545 0.36
Speed: 0.8/1.0/1.8 ms inference/NMS/total per 640x640 image at batch-size 32
Evaluating pycocotools mAP... saving runs/test/yolov7_640_val4/yolov7-tiny_predictions.json...
loading annotations into memory...
Done (t=0.33s)
creating index...
index created!
Loading and preparing results...
DONE (t=6.10s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=61.05s).
Accumulating evaluation results...
DONE (t=10.66s).
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.375
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.552
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.403
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.191
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.418
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.527
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.311
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.519
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.571
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.355
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.632
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.745
Results saved to runs/test/yolov7_640_val4
(py37c) xiedong@ubuntu:/ssd/xiedong/workplace/yolov7$ python test.py --data data/coco.yaml --img 416 --batch 32 --conf 0.001 --iou 0.65 --device 0 --weights weights/yolov7-tiny.pt --name yolov7_tiny_416
Namespace(augment=False, batch_size=32, conf_thres=0.001, data='data/coco.yaml', device='0', exist_ok=False, img_size=416, iou_thres=0.65, name='yolov7_tiny_416', no_trace=False, project='runs/test', save_conf=False, save_hybrid=False, save_json=True, save_txt=False, single_cls=False, task='val', v5_metric=False, verbose=False, weights=['weights/yolov7-tiny.pt'])
YOLOR 2022-11-4 torch 1.12.1+cu116 CUDA:0 (NVIDIA A100-PCIE-40GB, 40390.0625MB)
Fusing layers...
Model Summary: 200 layers, 6219709 parameters, 6219709 gradients
Convert model to Traced-model...
/ssd/xiedong/miniconda3/envs/py37c/lib/python3.7/site-packages/torch/_tensor.py:1083: UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad attribute won't be populated during autograd.backward(). If you indeed want the .grad field to be populated for a non-leaf Tensor, use .retain_grad() on the non-leaf Tensor. If you access the non-leaf Tensor by mistake, make sure you access the leaf Tensor instead. See github.com/pytorch/pytorch/pull/30531 for more informations. (Triggered internally at aten/src/ATen/core/TensorBody.h:477.)
return self._grad
traced_script_module saved!
model is traced!
/ssd/xiedong/miniconda3/envs/py37c/lib/python3.7/site-packages/torch/functional.py:478: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:2894.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
val: Scanning 'coco/val2017.cache' images and labels... 4952 found, 48 missing, 0 empty, 0 corrupted: 100%|██████████████████████████████████| 5000/5000 [00:00<?, ?it/s]
Class Images Labels P R mAP@.5 mAP@.5:.95: 100%|████████████████████████████████████| 157/157 [00:33<00:00, 4.72it/s]
all 5000 36335 0.619 0.468 0.494 0.321
Speed: 0.5/0.8/1.3 ms inference/NMS/total per 416x416 image at batch-size 32
Evaluating pycocotools mAP... saving runs/test/yolov7_tiny_416/yolov7-tiny_predictions.json...
loading annotations into memory...
Done (t=0.33s)
creating index...
index created!
Loading and preparing results...
DONE (t=4.45s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=60.30s).
Accumulating evaluation results...
DONE (t=11.39s).
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.333
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.499
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.353
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.121
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.361
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.544
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.290
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.466
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.512
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.241
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.577
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.752
Results saved to runs/test/yolov7_tiny_416
测yolov7:
(py37c) xiedong@ubuntu:/ssd/xiedong/workplace/yolov7$ python test.py --data data/coco.yaml --img 640 --batch 32 --conf 0.001 --iou 0.65 --device 0 --weights weights/yolov7.pt --name yolov7_tiny_640
Namespace(augment=False, batch_size=32, conf_thres=0.001, data='data/coco.yaml', device='0', exist_ok=False, img_size=640, iou_thres=0.65, name='yolov7_tiny_640', no_trace=False, project='runs/test', save_conf=False, save_hybrid=False, save_json=True, save_txt=False, single_cls=False, task='val', v5_metric=False, verbose=False, weights=['weights/yolov7.pt'])
YOLOR 2022-11-4 torch 1.12.1+cu116 CUDA:0 (NVIDIA A100-PCIE-40GB, 40390.0625MB)
Fusing layers...
RepConv.fuse_repvgg_block
RepConv.fuse_repvgg_block
RepConv.fuse_repvgg_block
Model Summary: 306 layers, 36905341 parameters, 36905341 gradients
Convert model to Traced-model...
/ssd/xiedong/miniconda3/envs/py37c/lib/python3.7/site-packages/torch/_tensor.py:1083: UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad attribute won't be populated during autograd.backward(). If you indeed want the .grad field to be populated for a non-leaf Tensor, use .retain_grad() on the non-leaf Tensor. If you access the non-leaf Tensor by mistake, make sure you access the leaf Tensor instead. See github.com/pytorch/pytorch/pull/30531 for more informations. (Triggered internally at aten/src/ATen/core/TensorBody.h:477.)
return self._grad
traced_script_module saved!
model is traced!
/ssd/xiedong/miniconda3/envs/py37c/lib/python3.7/site-packages/torch/functional.py:478: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:2894.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
val: Scanning 'coco/val2017.cache' images and labels... 4952 found, 48 missing, 0 empty, 0 corrupted: 100%|██████████████████████████████████| 5000/5000 [00:00<?, ?it/s]
Class Images Labels P R mAP@.5 mAP@.5:.95: 100%|████████████████████████████████████| 157/157 [00:38<00:00, 4.10it/s]
all 5000 36335 0.723 0.636 0.691 0.497
Speed: 1.8/0.7/2.4 ms inference/NMS/total per 640x640 image at batch-size 32
Evaluating pycocotools mAP... saving runs/test/yolov7_tiny_640/yolov7_predictions.json...
loading annotations into memory...
Done (t=0.64s)
creating index...
index created!
Loading and preparing results...
DONE (t=3.58s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=46.80s).
Accumulating evaluation results...
DONE (t=7.83s).
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.512
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.697
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.555
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.352
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.559
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.666
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.384
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.638
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.688
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.538
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.736
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.838
Results saved to runs/test/yolov7_tiny_640
python -m torch.distributed.launch --nproc_per_node 4 --master_port 9527 train.py --workers 16 --device 0,1,2,3 --sync-bn --batch-size 1800 --data data/coco.yaml --img 416 416 --cfg cfg/training/yolov7-tiny-silu.yaml --weights '' --name yolov7tinysilu --hyp data/hyp.scratch.tiny.yaml
convert to onnx:
python export.py --weights weights/yolov7-tiny.pt --grid --end2end --simplify \
--topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640 --max-wh 640
onnx export to mnn:
mnnconvert -f ONNX --modelFile yolov7-tiny416.onnx --MNNModel yolov7-tiny416.mnn --bizCode MNN