SpursLipu / YOLOv3v4-ModelCompression-MultidatasetTraining-Multibackbone

YOLO ModelCompression MultidatasetTraining
GNU General Public License v3.0
445 stars 136 forks source link

yolov4-tiny retrain #99

Open chingi071 opened 3 years ago

chingi071 commented 3 years ago

我在retrain 剪支過的模型時,出現了以下問題 Traceback (most recent call last): File "train.py", line 985, in train(hyp) # train normally File "train.py", line 164, in train load_darknet_weights(model, weights, pt=opt.pt, BN_Fold=opt.BN_Fold) File "/home/joy/yolo_darknet/YOLOv3v4-ModelCompression-MultidatasetTraining-Multibackbone/models.py", line 632, in load_darknet_weights conv_w = torch.from_numpy(weights[ptr:ptr + num_w]).view_as(conv_layer.weight) RuntimeError: shape '[241, 363, 3, 3]' is invalid for input of size 687660

我的指令是 python3 train.py --data ../Person_detection/cfg/person.data -pt --cfg ../prune_0.1_Person_detection/prune_0.1_cfg/prune_0.1_yolov4-tiny-obj.cfg --weights ../prune_0.1_Person_detection/prune_0.1_weights/prune_0.1_yolov4-tiny-obj_500000.weights --img-size 160

想請問一下是不是我下的指令哪邊有錯誤,謝謝。

SpursLipu commented 3 years ago

你把 -pt去掉就可以了。

chingi071 commented 3 years ago

您好, 想請問一下 -pt 不是指使用 pretrain model嗎? 另外,我有試過將 -pt 去掉,但這樣mAP幾乎都變成0了,請問這樣該如何解決呢?謝謝您。

SpursLipu commented 3 years ago

-pt是在使用coco80类预训练文件的时候使用。mAP训练也无法提升吗?

chingi071 commented 3 years ago

您好,我剛剛又重新試了一次不加 -pt 的指令,發現mAP有變化了 但是他訓練時 mAP 會突然變得很低 請問這是正常的現象嗎? 謝謝您。

Epoch gpu_mem GIoU obj cls total targets img_size 82/299 0.273G 1.21 5.78 0 6.99 4 160: 100%|██| 547/547 [00:17<00:00, 31.75it/s] Class Images Targets P R mAP@0.5 F1: 100%|██| 137/137 [00:09<00:00, 15.12it/s] all 2.18e+03 3.88e+03 0.655 0.559 0.538 0.603

 Epoch   gpu_mem      GIoU       obj       cls     total   targets  img_size
83/299    0.273G       1.2      5.76         0      6.97         1       160: 100%|██| 547/547 [00:17<00:00, 31.42it/s]
           Class    Images   Targets         P         R   mAP@0.5        F1: 100%|██| 137/137 [00:09<00:00, 14.15it/s]
             all  2.18e+03  3.88e+03     0.151     0.283      0.21     0.197

 Epoch   gpu_mem      GIoU       obj       cls     total   targets  img_size
84/299    0.273G      1.22       5.7         0      6.92         2       160: 100%|██| 547/547 [00:17<00:00, 31.04it/s]
           Class    Images   Targets         P         R   mAP@0.5        F1: 100%|██| 137/137 [00:09<00:00, 14.18it/s]
             all  2.18e+03  3.88e+03     0.476     0.421      0.36     0.447

 Epoch   gpu_mem      GIoU       obj       cls     total   targets  img_size
85/299    0.273G       1.2      5.73         0      6.93         1       160: 100%|██| 547/547 [00:17<00:00, 31.19it/s]
           Class    Images   Targets         P         R   mAP@0.5        F1: 100%|██| 137/137 [00:09<00:00, 14.74it/s]
             all  2.18e+03  3.88e+03     0.657     0.545     0.523     0.596

 Epoch   gpu_mem      GIoU       obj       cls     total   targets  img_size
86/299    0.273G      1.21      5.72         0      6.93         1       160: 100%|██| 547/547 [00:17<00:00, 30.74it/s]
           Class    Images   Targets         P         R   mAP@0.5        F1: 100%|██| 137/137 [00:09<00:00, 14.40it/s]
             all  2.18e+03  3.88e+03     0.533     0.483     0.418     0.507

 Epoch   gpu_mem      GIoU       obj       cls     total   targets  img_size
87/299    0.273G       1.2      5.67         0      6.87         2       160: 100%|██| 547/547 [00:41<00:00, 13.10it/s]
           Class    Images   Targets         P         R   mAP@0.5        F1: 100%|██| 137/137 [00:24<00:00,  5.57it/s]
             all  2.18e+03  3.88e+03     0.139    0.0649    **0.0265**    0.0885
SpursLipu commented 3 years ago

不会一直很低吧?还是要看最后的best.pt,有突变的很低也正常

chingi071 commented 3 years ago

您好,後來我retrain完後 mAP有上升一點。 另外我想請教一下,retrain完的 .pt 是否可以轉換為 onnx 或是 darknet weights呢? 謝謝您。

SpursLipu commented 3 years ago

转化是darknet weights是可以的,你可以用我的convert.py这个文件。

chingi071 commented 3 years ago

您好,我試了轉換 .pt 的指令 python3 convert.py --cfg ../prune_0.1_Person_detection_normal/prune_0.1_cfg/prune_0.1_yolov4-tiny-obj.cfg --weights weights/normal_1218/best.pt --img_size 160 --source ../Person_detection/tiff_data

但出現以下錯誤,請問是有哪邊需要修改的嗎? 謝謝您。

Traceback (most recent call last): File "convert.py", line 218, in convert() File "convert.py", line 24, in convert model.load_state_dict(torch.load(weights, map_location=device)['model']) File "/home/hamlet6379/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 1052, in load_state_dict self.class.name, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for Darknet: Missing key(s) in state_dict: "total_ops", "total_params", "module_list.total_ops", "module_list.total_params", "module_list.0.total_ops", "module_list.0.total_params", "module_list.1.total_ops", "module_list.1.total_params", "module_list.2.total_ops", "module_list.2.total_params", "module_list.3.total_ops", "module_list.3.total_params", "module_list.4.total_ops", "module_list.4.total_params", "module_list.5.total_ops", "module_list.5.total_params", "module_list.6.total_ops", "module_list.6.total_params", "module_list.7.total_ops", "module_list.7.total_params", "module_list.8.total_ops", "module_list.8.total_params", "module_list.10.total_ops", "module_list.10.total_params", "module_list.11.total_ops", "module_list.11.total_params", "module_list.12.total_ops", "module_list.12.total_params", "module_list.13.total_ops", "module_list.13.total_params", "module_list.14.total_ops", "module_list.14.total_params", "module_list.15.total_ops", "module_list.15.total_params", "module_list.16.total_ops", "module_list.16.total_params", "module_list.18.total_ops", "module_list.18.total_params", "module_list.19.total_ops", "module_list.19.total_params", "module_list.20.total_ops", "module_list.20.total_params", "module_list.21.total_ops", "module_list.21.total_params", "module_list.22.total_ops", "module_list.22.total_params", "module_list.23.total_ops", "module_list.23.total_params", "module_list.24.total_ops", "module_list.24.total_params", "module_list.26.total_ops", "module_list.26.total_params", "module_list.27.total_ops", "module_list.27.total_params", "module_list.28.total_ops", "module_list.28.total_params", "module_list.29.total_ops", "module_list.29.total_params", "module_list.30.total_ops", "module_list.30.total_params", "module_list.31.total_ops", "module_list.31.total_params", "module_list.32.total_ops", "module_list.32.total_params", "module_list.34.total_ops", "module_list.34.total_params", "module_list.35.total_ops", "module_list.35.total_params", "module_list.36.total_ops", "module_list.36.total_params", "module_list.37.total_ops", "module_list.37.total_params".

tarun-ssharma commented 2 years ago

Getting a similar error after quantization for tiny-yolov4 with --quantzied=1:

RuntimeError: Error(s) in loading state_dict for Darknet:
    Unexpected key(s) in state_dict: "module_list.0.Conv2d.activation_quantizer.scale", "module_list.0.Conv2d.activation_quantizer.zero_point", "module_list.0.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.0.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.0.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.0.Conv2d.weight_quantizer.scale", "module_list.0.Conv2d.weight_quantizer.zero_point", "module_list.0.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.0.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.0.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.1.Conv2d.activation_quantizer.scale", "module_list.1.Conv2d.activation_quantizer.zero_point", "module_list.1.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.1.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.1.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.1.Conv2d.weight_quantizer.scale", "module_list.1.Conv2d.weight_quantizer.zero_point", "module_list.1.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.1.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.1.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.2.Conv2d.activation_quantizer.scale", "module_list.2.Conv2d.activation_quantizer.zero_point", "module_list.2.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.2.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.2.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.2.Conv2d.weight_quantizer.scale", "module_list.2.Conv2d.weight_quantizer.zero_point", "module_list.2.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.2.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.2.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.3.scale", "module_list.3.float_max_list", "module_list.4.Conv2d.activation_quantizer.scale", "module_list.4.Conv2d.activation_quantizer.zero_point", "module_list.4.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.4.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.4.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.4.Conv2d.weight_quantizer.scale", "module_list.4.Conv2d.weight_quantizer.zero_point", "module_list.4.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.4.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.4.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.5.Conv2d.activation_quantizer.scale", "module_list.5.Conv2d.activation_quantizer.zero_point", "module_list.5.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.5.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.5.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.5.Conv2d.weight_quantizer.scale", "module_list.5.Conv2d.weight_quantizer.zero_point", "module_list.5.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.5.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.5.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.6.scale", "module_list.6.float_max_list", "module_list.7.Conv2d.activation_quantizer.scale", "module_list.7.Conv2d.activation_quantizer.zero_point", "module_list.7.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.7.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.7.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.7.Conv2d.weight_quantizer.scale", "module_list.7.Conv2d.weight_quantizer.zero_point", "module_list.7.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.7.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.7.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.8.scale", "module_list.8.float_max_list", "module_list.10.Conv2d.activation_quantizer.scale", "module_list.10.Conv2d.activation_quantizer.zero_point", "module_list.10.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.10.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.10.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.10.Conv2d.weight_quantizer.scale", "module_list.10.Conv2d.weight_quantizer.zero_point", "module_list.10.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.10.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.10.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.11.scale", "module_list.11.float_max_list", "module_list.12.Conv2d.activation_quantizer.scale", "module_list.12.Conv2d.activation_quantizer.zero_point", "module_list.12.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.12.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.12.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.12.Conv2d.weight_quantizer.scale", "module_list.12.Conv2d.weight_quantizer.zero_point", "module_list.12.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.12.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.12.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.13.Conv2d.activation_quantizer.scale", "module_list.13.Conv2d.activation_quantizer.zero_point", "module_list.13.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.13.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.13.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.13.Conv2d.weight_quantizer.scale", "module_list.13.Conv2d.weight_quantizer.zero_point", "module_list.13.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.13.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.13.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.14.scale", "module_list.14.float_max_list", "module_list.15.Conv2d.activation_quantizer.scale", "module_list.15.Conv2d.activation_quantizer.zero_point", "module_list.15.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.15.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.15.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.15.Conv2d.weight_quantizer.scale", "module_list.15.Conv2d.weight_quantizer.zero_point", "module_list.15.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.15.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.15.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.16.scale", "module_list.16.float_max_list", "module_list.18.Conv2d.activation_quantizer.scale", "module_list.18.Conv2d.activation_quantizer.zero_point", "module_list.18.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.18.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.18.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.18.Conv2d.weight_quantizer.scale", "module_list.18.Conv2d.weight_quantizer.zero_point", "module_list.18.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.18.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.18.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.19.scale", "module_list.19.float_max_list", "module_list.20.Conv2d.activation_quantizer.scale", "module_list.20.Conv2d.activation_quantizer.zero_point", "module_list.20.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.20.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.20.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.20.Conv2d.weight_quantizer.scale", "module_list.20.Conv2d.weight_quantizer.zero_point", "module_list.20.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.20.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.20.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.21.Conv2d.activation_quantizer.scale", "module_list.21.Conv2d.activation_quantizer.zero_point", "module_list.21.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.21.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.21.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.21.Conv2d.weight_quantizer.scale", "module_list.21.Conv2d.weight_quantizer.zero_point", "module_list.21.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.21.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.21.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.22.scale", "module_list.22.float_max_list", "module_list.23.Conv2d.activation_quantizer.scale", "module_list.23.Conv2d.activation_quantizer.zero_point", "module_list.23.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.23.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.23.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.23.Conv2d.weight_quantizer.scale", "module_list.23.Conv2d.weight_quantizer.zero_point", "module_list.23.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.23.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.23.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.24.scale", "module_list.24.float_max_list", "module_list.26.Conv2d.activation_quantizer.scale", "module_list.26.Conv2d.activation_quantizer.zero_point", "module_list.26.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.26.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.26.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.26.Conv2d.weight_quantizer.scale", "module_list.26.Conv2d.weight_quantizer.zero_point", "module_list.26.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.26.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.26.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.27.Conv2d.activation_quantizer.scale", "module_list.27.Conv2d.activation_quantizer.zero_point", "module_list.27.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.27.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.27.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.27.Conv2d.weight_quantizer.scale", "module_list.27.Conv2d.weight_quantizer.zero_point", "module_list.27.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.27.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.27.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.28.Conv2d.activation_quantizer.scale", "module_list.28.Conv2d.activation_quantizer.zero_point", "module_list.28.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.28.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.28.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.28.Conv2d.weight_quantizer.scale", "module_list.28.Conv2d.weight_quantizer.zero_point", "module_list.28.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.28.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.28.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.29.Conv2d.activation_quantizer.scale", "module_list.29.Conv2d.activation_quantizer.zero_point", "module_list.29.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.29.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.29.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.29.Conv2d.weight_quantizer.scale", "module_list.29.Conv2d.weight_quantizer.zero_point", "module_list.29.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.29.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.29.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.31.scale", "module_list.31.float_max_list", "module_list.32.Conv2d.activation_quantizer.scale", "module_list.32.Conv2d.activation_quantizer.zero_point", "module_list.32.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.32.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.32.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.32.Conv2d.weight_quantizer.scale", "module_list.32.Conv2d.weight_quantizer.zero_point", "module_list.32.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.32.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.32.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.34.scale", "module_list.34.float_max_list", "module_list.35.Conv2d.activation_quantizer.scale", "module_list.35.Conv2d.activation_quantizer.zero_point", "module_list.35.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.35.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.35.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.35.Conv2d.weight_quantizer.scale", "module_list.35.Conv2d.weight_quantizer.zero_point", "module_list.35.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.35.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.35.Conv2d.weight_quantizer.range_tracker.first_w", "module_list.36.Conv2d.activation_quantizer.scale", "module_list.36.Conv2d.activation_quantizer.zero_point", "module_list.36.Conv2d.activation_quantizer.range_tracker.min_val", "module_list.36.Conv2d.activation_quantizer.range_tracker.max_val", "module_list.36.Conv2d.activation_quantizer.range_tracker.first_a", "module_list.36.Conv2d.weight_quantizer.scale", "module_list.36.Conv2d.weight_quantizer.zero_point", "module_list.36.Conv2d.weight_quantizer.range_tracker.min_val", "module_list.36.Conv2d.weight_quantizer.range_tracker.max_val", "module_list.36.Conv2d.weight_quantizer.range_tracker.first_w"

@SpursLipu Any suggestions to make it work?