剪枝出来模型如何正确进行评估和推理
Created by: TianyouChen
我用prune.py对自己的模型进行剪枝 指令如下: python3 slim/prune/prune.py -c ./configs/yolov3_mobilenet_v1_Headshoulder.yml --pruned_params "yolo_block.0.0.0.conv.weights,yolo_block.0.0.1.conv.weights,yolo_block.0.1.0.conv.weights,yolo_block.0.1.1.conv.weights,yolo_block.0.2.conv.weights,yolo_block.0.tip.conv.weights,yolo_block.1.0.0.conv.weights,yolo_block.1.0.1.conv.weights,yolo_block.1.1.0.conv.weights,yolo_block.1.1.1.conv.weights,yolo_block.1.2.conv.weights,yolo_block.1.tip.conv.weights,yolo_block.2.0.0.conv.weights,yolo_block.2.0.1.conv.weights,yolo_block.2.1.0.conv.weights,yolo_block.2.1.1.conv.weights,yolo_block.2.2.conv.weights,yolo_block.2.tip.conv.weights" --pruned_ratios="0.9,0.767521525363963,0.8383905099520552,0.7719316528375244,0.8042826460550732,0.9,0.6189280062094187,0.7051951955078442,0.6327583985461308,0.7343364754462861,0.6076576193384153,0.8220366225740144,0.6563790840842497,0.6738003057951206,0.7175286881862358,0.751879617563028,0.6784306812657529,0.8018514871597572" --eval
模型保存在下面路径: 2020-03-26 13:22:13,972-INFO: Save model to output/prue_Headshoulder/yolov3_mobilenet_v1_Headshoulder/2000. output/prue_Headshoulder/yolov3_mobilenet_v1_Headshoulder/best_model.
然后我用下面指令进行评估: python3 slim/prune/eval.py -c ./configs/yolov3_mobilenet_v1_Headshoulder.yml --pruned_params "yolo_block.0.0.0.conv.weights,yolo_block.0.0.1.conv.weights,yolo_block.0.1.0.conv.weights,yolo_block.0.1.1.conv.weights,yolo_block.0.2.conv.weights,yolo_block.0.tip.conv.weights,yolo_block.1.0.0.conv.weights,yolo_block.1.0.1.conv.weights,yolo_block.1.1.0.conv.weights,yolo_block.1.1.1.conv.weights,yolo_block.1.2.conv.weights,yolo_block.1.tip.conv.weights,yolo_block.2.0.0.conv.weights,yolo_block.2.0.1.conv.weights,yolo_block.2.1.0.conv.weights,yolo_block.2.1.1.conv.weights,yolo_block.2.2.conv.weights,yolo_block.2.tip.conv.weights" --pruned_ratios="0.9,0.767521525363963,0.8383905099520552,0.7719316528375244,0.8042826460550732,0.9,0.6189280062094187,0.7051951955078442,0.6327583985461308,0.7343364754462861,0.6076576193384153,0.8220366225740144,0.6563790840842497,0.6738003057951206,0.7175286881862358,0.751879617563028,0.6784306812657529,0.8018514871597572" -o weights=./output/prue_Headshoulder/yolov3_mobilenet_v1_Headshoulder/best_model
报以下错:
2020-03-26 14:32:18,693-INFO: 1690 samples in file dataset/voc/test.txt 2020-03-26 14:32:18,695-INFO: places would be ommited when DataLoader is not iterable 2020-03-26 14:32:18,695-INFO: pruned params: ['yolo_block.0.0.0.conv.weights', 'yolo_block.0.0.1.conv.weights', 'yolo_block.0.1.0.conv.weights', 'yolo_block.0.1.1.conv.weights', 'yolo_block.0.2.conv.weights', 'yolo_block.0.tip.conv.weights', 'yolo_block.1.0.0.conv.weights', 'yolo_block.1.0.1.conv.weights', 'yolo_block.1.1.0.conv.weights', 'yolo_block.1.1.1.conv.weights', 'yolo_block.1.2.conv.weights', 'yolo_block.1.tip.conv.weights', 'yolo_block.2.0.0.conv.weights', 'yolo_block.2.0.1.conv.weights', 'yolo_block.2.1.0.conv.weights', 'yolo_block.2.1.1.conv.weights', 'yolo_block.2.2.conv.weights', 'yolo_block.2.tip.conv.weights'] 2020-03-26 14:32:18,695-INFO: pruned ratios: [0.9, 0.767521525363963, 0.8383905099520552, 0.7719316528375244, 0.8042826460550732, 0.9, 0.6189280062094187, 0.7051951955078442, 0.6327583985461308, 0.7343364754462861, 0.6076576193384153, 0.8220366225740144, 0.6563790840842497, 0.6738003057951206, 0.7175286881862358, 0.751879617563028, 0.6784306812657529, 0.8018514871597572] 2020-03-26 14:32:19,467-INFO: pruned FLOPS: 0.8246378200023888 W0326 14:32:21.048223 22386 device_context.cc:237] Please NOTE: device: 0, CUDA Capability: 70, Driver API Version: 10.1, Runtime API Version: 9.0 W0326 14:32:21.055415 22386 device_context.cc:245] device: 0, cuDNN Version: 7.6. 2020-03-26 14:32:25,089-INFO: Loading parameters from /home/chenchaocun/PaddleDetection_slim/output/prue_Headshoulder/yolov3_mobilenet_v1_Headshoulder/best_model... Traceback (most recent call last): File "slim/prune/eval.py", line 229, in main() File "slim/prune/eval.py", line 179, in main checkpoint.load_params(exe, eval_prog, cfg.weights) File "/home/chenchaocun/PaddleDetection_slim/slim/prune/ppdet/utils/checkpoint.py", line 142, in load_params fluid.io.set_program_state(prog, state) File "/usr/local/lib/python3.5/dist-packages/paddle/fluid/io.py", line 1942, in set_program_state .format(orig_para_np.shape, para.name, new_para_np.shape) AssertionError: Shape not matching: the Program requires a parameter with a shape of ((512,)), while the loaded parameter (namely [ yolo_block.0.2.bn.mean ]) has a shape of ((100,)). 显示参数不匹配,请问这是哪个环节出问题了?