在使用官方代码训练SSD时,出现AttributeError: module 'paddle.fluid' has no attribute 'program'
Created by: newdimitri
您好,研发老师,我在macos、Python3.7、paddlepaddle 1.2下运行https://github.com/PaddlePaddle/models/tree/develop/fluid/PaddleCV/object_detection 中的代码时,出现错误:
Traceback (most recent call last):
File "train.py", line 317, in <module>
val_file_list=val_file_list)
File "train.py", line 164, in train
is_train=True)
File "train.py", line 86, in build_program
with fluid.program.devices_num_guard(main_prog, startup_prog):
AttributeError: module 'paddle.fluid' has no attribute 'program'
运行指令为:
python3 -u train.py --batch_size=64 --dataset='coco2017' --pretrained_model='pretrained/ssd_mobilenet_v1_coco/' --use_gpu=false
出错代码的前后文为:
def build_program(main_prog, startup_prog, train_params, is_train):
image_shape = train_params['image_shape']
class_num = train_params['class_num']
ap_version = train_params['ap_version']
outs = []
with fluid.program.devices_num_guard(main_prog, startup_prog):
py_reader = fluid.layers.py_reader(
capacity=64,
shapes=[[-1] + image_shape, [-1, 4], [-1, 1], [-1, 1]],
lod_levels=[0, 1, 1, 1],
dtypes=["float32", "float32", "int32", "int32"],
use_double_buffer=True)
with fluid.unique_name.guard():
image, gt_box, gt_label, difficult = fluid.layers.read_file(py_reader)
locs, confs, box, box_var = mobile_net(class_num, image, image_shape)
if is_train:
with fluid.unique_name.guard("train"):
loss = fluid.layers.ssd_loss(locs, confs, gt_box, gt_label, box,
box_var)
loss = fluid.layers.reduce_sum(loss)
optimizer = optimizer_setting(train_params)
optimizer.minimize(loss)
outs = [py_reader, loss]
else:
with fluid.unique_name.guard("inference"):
nmsed_out = fluid.layers.detection_output(
locs, confs, box, box_var, nms_threshold=0.45)
map_eval = fluid.evaluator.DetectionMAP(
nmsed_out,
gt_label,
gt_box,
difficult,
class_num,
overlap_threshold=0.5,
evaluate_difficult=False,
ap_version=ap_version)
# nmsed_out and image is used to save mode for inference
outs = [py_reader, map_eval, nmsed_out, image]
return outs