ValueError: Feed a list of tensor, the list should be the same size as places
import paddle
from paddle import fluid
import numpy as np
def reader_creater(type="train"):
def reader():
for i in range(10):
yield np.ones(2)*i,np.ones(2)*i
return reader
train_reader=reader_creater()
train_reader=paddle.batch(train_reader,2)
# train_reader=paddle.reader.shuffle(train_reader,3)
train_program=fluid.Program()
init_program=fluid.Program()
with fluid.program_guard(train_program,init_program):
x=fluid.layers.data(name='x',shape=[2],dtype='float64')
y=fluid.layers.data(name='y',shape=[2],dtype='float64')
train_loader=fluid.io.DataLoader.from_generator(feed_list=[x,y],capacity=1,use_double_buffer=False,iterable=True)
prediction=fluid.layers.elementwise_add(x,y)
loss=fluid.layers.square_error_cost(y,prediction)
places=fluid.CPUPlace()
exe=fluid.Executor(places)
exe.run(init_program)
train_program=fluid.CompiledProgram(train_program).with_data_parallel(loss_name=loss.name)
train_loader.set_sample_list_generator(train_reader,places=places)
for data in train_loader():
print(data)
print(data[0]['x'])
pre=exe.run(train_program,feed=data ,fetch_list=[prediction])
input("pause")
看起来很简单的一段代码,跑的时候一直报这个错误
import paddle
from paddle import fluid
import numpy as np
def reader_creater(type="train"):
def reader():
for i in range(10):
yield np.ones(2)*i,np.ones(2)*i
return reader
train_reader=reader_creater()
train_reader=paddle.batch(train_reader,2)
# train_reader=paddle.reader.shuffle(train_reader,3)
train_program=fluid.Program()
init_program=fluid.Program()
with fluid.program_guard(train_program,init_program):
x=fluid.layers.data(name='x',shape=[2],dtype='float64')
y=fluid.layers.data(name='y',shape=[2],dtype='float64')
train_loader=fluid.io.DataLoader.from_generator(feed_list=[x,y],capacity=1,use_double_buffer=False,iterable=True)
prediction=fluid.layers.elementwise_add(x,y)
loss=fluid.layers.square_error_cost(y,prediction)
places=fluid.CPUPlace()
exe=fluid.Executor(places)
exe.run(init_program)
train_program=fluid.CompiledProgram(train_program).with_data_parallel(loss_name=loss.name)
train_loader.set_sample_list_generator(train_reader,places=places)
for data in train_loader():
print(data)
print(data[0]['x'])
pre=exe.run(train_program,feed=data ,fetch_list=[prediction])
input("pause")
看起来很简单的一段代码,跑的时候一直报这个错误