optimizer.minimize(avg_cost) 无法反向传播
Created by: xubin1994
代码数据读取正常,网络框架正常,但整体拼接在一起时使用optimizer.minimize(avg_cost) 报错,似乎是说无法反向传播 训练部分代码如下:
from dataloader import *
from IresNet import IresNet
from loss import model_loss
if __name__ == '__main__':
#main_program = fluid.default_main_program()
datapath = '/data/home/xubin/dataset/dataset/GANet_dataset'
file_name = 'sceneflow_train.txt'
max_disp = 192
left_input = fluid.layers.data(name='left_input', shape=[3, 384, 768], dtype='float32')
right_input = fluid.layers.data(name='right_input', shape=[3, 384, 768], dtype='float32')
left_disp_input = fluid.layers.data(name='left_disp_input', shape=[1, 384, 768], dtype='float32')
predict_final, r_res2_predict, r_res1_predict, r_res0=IresNet(left_input,right_input)
avg_cost = model_loss(predict_final, r_res2_predict, r_res1_predict, r_res0,left_disp_input,max_disp)
optimizer = fluid.optimizer.AdamOptimizer(learning_rate=0.001)
opt = optimizer.minimize(avg_cost)
place = fluid.CPUPlace()
exe = fluid.Executor(place=place)
exe.run(program=fluid.default_startup_program())
train_reader = paddle.batch(reader=paddle.reader.shuffle(reader=train_r(datapath,file_name), buf_size=3000),
batch_size=1)
feeder = fluid.DataFeeder(place=place, feed_list=[left_input, right_input,left_disp_input])
for pass_id in range(2):
for batch_id, data in enumerate(train_reader()):
train_cost, train_acc = exe.run(program=fluid.default_main_program(),
feed=feeder.feed(data),
fetch_list=[avg_cost])
print(avg_cost)
`
报错log如下:
Traceback (most recent call last):
File "xubin_train.py", line 15, in <module>
opt = optimizer.minimize(avg_cost)
File "</usr/local/lib/python3.6/dist-packages/decorator.py:decorator-gen-20>", line 2, in minimize
File "/usr/local/lib/python3.6/dist-packages/paddle/fluid/wrapped_decorator.py", line 25, in __impl__
return wrapped_func(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/paddle/fluid/dygraph/base.py", line 87, in __impl__
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/paddle/fluid/optimizer.py", line 609, in minimize
no_grad_set=no_grad_set)
File "/usr/local/lib/python3.6/dist-packages/paddle/fluid/optimizer.py", line 494, in backward
no_grad_set, callbacks)
File "/usr/local/lib/python3.6/dist-packages/paddle/fluid/backward.py", line 706, in append_backward
_append_backward_vars_(root_block, fwd_op_num, grad_to_var, grad_info_map)
File "/usr/local/lib/python3.6/dist-packages/paddle/fluid/backward.py", line 518, in _append_backward_vars_
op_desc.infer_shape(block.desc)
IndexError: _Map_base::at
请问这种是出现了什么问题?