评估模型采用CPU方式执行报错
Created by: hexiaoting
python eval.py --model=ResNet50 --pretrained_model=workspace/ResNet50_pretrained --data_dir=ILSVRC/Data/CLS-LOC/ --batch_size=256 --use_gpu=False
2020-01-14 17:52:27,036-INFO: ------------- Configuration Arguments -------------
2020-01-14 17:52:27,036-INFO: batch_size : 256
2020-01-14 17:52:27,036-INFO: class_dim : 1000
2020-01-14 17:52:27,036-INFO: data_dir : ILSVRC/Data/CLS-LOC/
2020-01-14 17:52:27,036-INFO: image_mean : [0.485, 0.456, 0.406]
2020-01-14 17:52:27,036-INFO: image_shape : [3, 224, 224]
2020-01-14 17:52:27,036-INFO: image_std : [0.229, 0.224, 0.225]
2020-01-14 17:52:27,036-INFO: interpolation : None
2020-01-14 17:52:27,036-INFO: model : ResNet50
2020-01-14 17:52:27,036-INFO: padding_type : SAME
2020-01-14 17:52:27,036-INFO: pretrained_model : workspace/ResNet50_pretrained
2020-01-14 17:52:27,036-INFO: print_step : 1
2020-01-14 17:52:27,036-INFO: reader_buf_size : 2048
2020-01-14 17:52:27,037-INFO: reader_thread : 8
2020-01-14 17:52:27,037-INFO: resize_short_size : 256
2020-01-14 17:52:27,037-INFO: same_feed : 0
2020-01-14 17:52:27,037-INFO: save_json_path : None
2020-01-14 17:52:27,037-INFO: use_gpu : 0
2020-01-14 17:52:27,037-INFO: use_se : True
2020-01-14 17:52:27,037-INFO: ----------------------------------------------------
Traceback (most recent call last):
File "eval.py", line 199, in <module>
main()
File "eval.py", line 195, in main
eval(args)
File "eval.py", line 124, in eval
test_program).with_data_parallel(places=places)
UnboundLocalError: local variable 'places' referenced before assignment
原因分析:在eval.py的代码中 由于设置了use_gpu=Flase, 使得places未赋值就使用了导致失败。源码如下:
120 if args.use_gpu:
121 places = fluid.framework.cuda_places()
122
123 compiled_program = fluid.compiler.CompiledProgram(
124 test_program).with_data_parallel(places=places)