lmjohns3 / theanets

Neural network toolkit for Python
http://theanets.rtfd.org
MIT License
328 stars 73 forks source link

Type Error in XOR example #15

Closed sutr90 closed 10 years ago

sutr90 commented 10 years ago

Hi, I was testing my setup with your examples just to be sure everything works before I start doing any serious work.

When I run the example I get some log output and then following error:

  File "xor-classfier.py", line 27, in <module>
    e.run(train, train)
  File "/home/theano/dp/python/theano-nets/theanets/main.py", line 210, in run
    for _ in self.train(train=train, valid=valid):
  File "/home/theano/dp/python/theano-nets/theanets/main.py", line 238, in train
    cg_set=self.datasets['cg']):
  File "/home/theano/dp/python/theano-nets/theanets/trainer.py", line 135, in train
    self.evaluate(i, valid_set)
  File "/home/theano/dp/python/theano-nets/theanets/trainer.py", line 93, in evaluate
    costs = np.mean([self.f_eval(*x) for x in valid_set], axis=0)
  File "/usr/lib/python2.7/site-packages/theano/compile/function_module.py", line 497, in __call__
    allow_downcast=s.allow_downcast)
  File "/usr/lib/python2.7/site-packages/theano/tensor/type.py", line 119, in filter
    raise TypeError(err_msg, data)
TypeError: ('Bad input argument to theano function at index 0(0-based)', 'TensorType(float32, matrix) cannot store a value of dtype float64 without risking loss of precision. If you do not mind this loss, you can: 1) explicitly cast your data to float32, or 2) set "allow_input_downcast=True" when calling "function".', array([[ ... ]]))

I understand what's going on, I'm just not sure how to fix it.

I see two option here: either I have incorrect setup in my theano installation or there is some flaw in your code.

My setup taken from .theanorc

[global]
floatX = float32
device = gpu0
mode=FAST_RUN

[nvcc]
fastmath = True

[blas]
ldflags = -latlas -lgfortran -lf77blas

I think there is a conflict with your code and my settings, as my theano is trying to run on GPU, while yours isn't aware of it.

Thanks for help.

lmjohns3 commented 10 years ago

Thanks for the feedback! The example needed to be told explicitly which floating-point format to use. I think Theano also lets you avoid this error by setting the allow_input_downcast keyword arg when calling functions, but I've avoided doing that in favor of making sure the data is in the format I expect.

sutr90 commented 10 years ago

Thanks for clearing this out. I was afraind, it would affect some other parts of library too.