Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

运行示例中的代码,得到错误:reduce() of empty sequence with no initial value #2564

Closed
SniperZhao opened this issue Jun 22, 2017 · 6 comments · Fixed by #2636
Closed
Assignees

Comments

@SniperZhao
Copy link

SniperZhao commented Jun 22, 2017

新建了一个python文件,照抄了新手入门的线性回归代码。
运行该python的时候得到错误:

I0622 17:05:55.289027  8472 Util.cpp:166] commandline:  --use_gpu=False 
I0622 17:05:55.294421  8472 GradientMachine.cpp:85] Initing parameters..
I0622 17:05:55.294454  8472 GradientMachine.cpp:92] Init parameters done.
Traceback (most recent call last):
  File "lienerRegression.py", line 61, in <module>
    num_passes=100)
  File "/home/zhaoyuan/002.tools/paddleV2/python27/lib/python2.7/site-packages/paddle/v2/trainer.py", line 153, in train
    in_args = feeder(data_batch)
  File "/home/zhaoyuan/002.tools/paddleV2/python27/lib/python2.7/site-packages/py_paddle/dataprovider_converter.py", line 278, in __call__
    return self.convert(dat, argument)
  File "/home/zhaoyuan/002.tools/paddleV2/python27/lib/python2.7/site-packages/paddle/v2/data_feeder.py", line 134, in convert
    return DataProviderConverter.convert(self, reorder_data(dat), argument)
  File "/home/zhaoyuan/002.tools/paddleV2/python27/lib/python2.7/site-packages/py_paddle/dataprovider_converter.py", line 263, in convert
    scanner.pre_scan(each_step)
  File "/home/zhaoyuan/002.tools/paddleV2/python27/lib/python2.7/site-packages/py_paddle/dataprovider_converter.py", line 112, in pre_scan
    self.__dim__ = reduce(lambda x, y: x * y, self.__shape__)
TypeError: reduce() of empty sequence with no initial value
@chrisxu2016
Copy link
Contributor

Can you paste the code? I'm not sure about this error now? Please make sure that data_reader has no problem

@SniperZhao
Copy link
Author

具体代码请见:http://www.paddlepaddle.org/doc_cn/getstarted/concepts/use_concepts_cn.html
拉到最下面的线性回归完整示例部分。

我安装好paddle之后,编辑该代码到【linear.py】文件,然后键入命令【python linear.py】
得到上述报错。

@SniperZhao
Copy link
Author

@chrisxu2016 any update?

@juliecbd
Copy link

To confirm, I did not have this problem before. I was able to input numpy nd array with multiple samples without problem with the paddle build 1 month ago. I rebuilt it yesterday, and I now have this problem. So I think there have been some commits which break the infer function

@jacquesqiao
Copy link
Member

jacquesqiao commented Jun 28, 2017

The demo code have some error, the input value is configured as dense_vector

y = paddle.layer.data(name='y', type=paddle.data_type.dense_vector(1))

but the reader yeild a scalar:

def train_reader():
    train_x = np.array([[1, 1], [1, 2], [3, 4], [5, 2]])
    train_y = np.array([-2, -3, -7, -7])

    def reader():
        for i in xrange(train_y.shape[0]):
            yield train_x[i], train_y[i]

    return reader

the reader should be changed to:

def train_reader():
    train_x = np.array([[1, 1], [1, 2], [3, 4], [5, 2]])
    train_y = np.array([[-2], [-3], [-7], [-7]])

    def reader():
        for i in xrange(train_y.shape[0]):
            yield train_x[i], train_y[i]

    return reader

@SniperZhao
Copy link
Author

SniperZhao commented Jun 28, 2017

Thank you @jacquesqiao, it works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants