paddlepaddle吧 关注:213贴子:312
  • 4回复贴,共1

dataloader 莫名报错

只看楼主收藏回复

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")
看起来很简单的一段代码,跑的时候一直报这个错误


1楼2020-01-26 17:10回复
    /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/executor.py:779: UserWarning: The following exception is not an EOF exception.
    "The following exception is not an EOF exception.")
    Traceback (most recent call last):
    File "load.py", line 36, in <module>
    pre=exe.run(train_program,feed=data ,fetch_list=[prediction])
    File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/executor.py", line 780, in run
    six.reraise(*sys.exc_info())
    File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/six.py", line 693, in reraise
    raise value
    File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/executor.py", line 775, in run
    use_program_cache=use_program_cache)
    File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/executor.py", line 834, in _run_impl
    return_numpy=return_numpy)
    File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/executor.py", line 648, in _run_parallel
    "Feed a list of tensor, the list should be the same size as places"
    ValueError: Feed a list of tensor, the list should be the same size as places


    2楼2020-01-26 17:10
    回复
      最后发现是因为CPU_NUMBER是2,分到两个cpu的时候数据维度出现了问题


      3楼2020-01-28 11:13
      收起回复
        赞一个


        4楼2020-03-02 09:27
        回复