开始训练!
本次训练epoch
为2
,为了执行教程教学,根据实际需求调整次数,该次数在文件夹下的default_config.yaml
中进行修改,请根据业务逻辑自行调整
数据已经准备好了,我们把刚才下载的压缩包Train_coco.zip
先进行解压
首先,==点此下载==一键训练大礼包
如果失效,==点击这里下载==
使用命令
unzip Train_coco.zip
然后切换到程序目录
cd yolov5moto
执行训练
python3 train.py
::: tip
如果需要打印日志
到文件
,可以使用,因为训练时间较长,可以使用&
挂起
python3 train.py > train.log 2>&1 &
:::
::: warning
如果在训练过程的时候出现了如下错误
AttributeError: module 'yaml' has no attribute 'FullLoader'
使用如下命令安装 PyYAML
即可
pip3 install --ignore-installed PyYAML
:::
以下为返回结果
INFO:Args:
INFO:--> enable_modelarts: False
INFO:--> data_url:
INFO:--> train_url:
INFO:--> checkpoint_url:
INFO:--> output_dir: /cache
INFO:--> data_path: /cache/data
INFO:--> output_path: /cache/train
INFO:--> load_path: /cache/checkpoint_path
INFO:--> device_target: Ascend
INFO:--> need_modelarts_dataset_unzip: True
INFO:--> modelarts_dataset_unzip_name: coco
INFO:--> data_dir: motorcycle-coco/
INFO:--> per_batch_size: 32
INFO:--> yolov5_version: yolov5s
INFO:--> pretrained_backbone:
INFO:--> resume_yolov5:
INFO:--> pretrained_checkpoint:
INFO:--> lr_scheduler: cosine_annealing
INFO:--> lr: 0.013
INFO:--> lr_epochs: [220, 250]
2INFO:--> lr_gamma: 0.1
INFO:--> eta_min: 0.0
INFO:--> T_max: 300
INFO:--> max_epoch: 2
INFO:--> warmup_epochs: 20
INFO:--> weight_decay: 0.0005
INFO:--> momentum: 0.9
INFO:--> loss_scale: 1024
INFO:--> label_smooth: 0
INFO:--> label_smooth_factor: 0.1
INFO:--> log_interval: 100
INFO:--> ckpt_path: outputs/
INFO:--> ckpt_interval: 1
INFO:--> is_save_on_master: 1
INFO:--> is_distributed: 0
INFO:--> rank: 0
INFO:--> group_size: 1
INFO:--> need_profiler: 0
INFO:--> training_shape:
INFO:--> resize_rate: 10
INFO:--> is_modelArts: 0
INFO:--> pretrained:
INFO:--> log_path: outputs/
INFO:--> ann_val_file:
INFO:--> eval_nms_thresh: 0.6
INFO:--> eval_shape:
INFO:--> ignore_threshold: 0.7
INFO:--> test_ignore_threshold: 0.001
INFO:--> multi_label: True
INFO:--> multi_label_thresh: 0.1
INFO:--> device_id: 0
INFO:--> batch_size: 1
INFO:--> testing_shape: 640
INFO:--> ckpt_file:
INFO:--> file_name: yolov5
INFO:--> file_format: MINDIR
INFO:--> dataset_path:
INFO:--> ann_file:
INFO:--> hue: 0.015
INFO:--> saturation: 1.5
INFO:--> value: 0.4
INFO:--> jitter: 0.3
INFO:--> multi_scale: [[320, 320], [352, 352], [384, 384], [416, 416], [448, 448], [480, 480], [512, 512], [544, 544], [576, 576], [608, 608], [640, 640], [672, 672], [704, 704], [736, 736], [768, 768]]
INFO:--> num_classes: 80
INFO:--> max_box: 150
INFO:--> anchor_scales: [[12, 16], [19, 36], [40, 28], [36, 75], [76, 55], [72, 146], [142, 110], [192, 243], [459, 401]]
INFO:--> out_channel: 255
INFO:--> input_shape: [[3, 32, 64, 128, 256, 512, 1], [3, 48, 96, 192, 384, 768, 2], [3, 64, 128, 256, 512, 1024, 3], [3, 80, 160, 320, 640, 1280, 4]]
INFO:--> test_img_shape: [640, 640]
INFO:--> labels: ['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']
INFO:--> coco_ids: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90]
INFO:--> result_files: ./result_Files
INFO:--> config_path: /home/ma-user/work/lyna/model_utils/../default_config.yaml
INFO:--> data_root: motorcycle-coco/
INFO:--> annFile: motorcycle-coco/annotations/train.json
INFO:--> rank_save_ckpt_flag: 1
INFO:--> outputs_dir: outputs/2022-07-21_time_15_32_09
INFO:--> logger: <LOGGER YOLOV5 (NOTSET)>
INFO:
loading annotations into memory...
Done (t=0.02s)
creating index...
index created!
INFO:Finish loading dataset
INFO:epoch[0], iter[0], loss:6732.890625, fps:0.17 imgs/sec, lr:1.5116279428184498e-05
INFO:==========end training===============
使用eval.py 验证模型
使用命令
==命令解析==
python eval.py --data_dir=数据集路径
--eval_shape=推理图形大小
--pretrained="待验证的训练好的ckpt文件路径"
python3 eval.py --data_dir=motorcycle-coco/ --eval_shape=640 --pretrained="outputs/0-320_13760.ckpt"
::: warning
如果在推理过程的时候出现了如下错误
TypeError: 'numpy.float64' object cannot be interpreted as an integer
则需要降级numpy
版本,使用以下命令,即可解决float64类型
不能被安全地转换成整型
的错误
pip3 install numpy==1.17.0
:::
INFO:Creating Network....
INFO:outputs/2022-07-21_time_15_32_09/ckpt_0/0-2_86.ckpt
INFO:load_model outputs/2022-07-21_time_15_32_09/ckpt_0/0-2_86.ckpt success
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
INFO:testing shape : [640, 640]
INFO:total 120 images to eval
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
INFO:Start inference....
INFO:Processing... 0.00%
INFO:Calculating mAP...
INFO:result file path: outputs/2022-07-21_time_16_23_51/predict_2022_07_21_16_40_02.json
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
Loading and preparing results...
DONE (t=7.75s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=0.33s).
Accumulating evaluation results...
DONE (t=0.02s).
INFO:
=============coco eval result=========
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.170
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.251
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.190
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.046
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.311
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.211
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.195
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.399
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.407
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.550
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.381
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.409
2022-10-27 17:56:09,278:INFO:testing cost time 0.04 h