Reputation: 591
When I am using nolearn to implement multi-label classification, I got this error:
'Bad input argument to theano function with name "/Users/lm/Documents/anaconda/lib/python2.7/site-packages/nolearn/lasagne/base.py:391" at index 1(0-based)', 'TensorType(float32, matrix) cannot store a value of dtype int64 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([[0, 0, 0, ..., 0, 0, 1],
Upvotes: 2
Views: 1724
Reputation: 7869
In my case all I did was change the floatX
flag (under [global]
) to on the .theanorc file from :
[global]
floatX = float64
to:
[global]
floatX = float32
Notice that the 64 at the end was replaced by the 32.
Upvotes: 0
Reputation: 13218
As told in the error message, you need to convert your input and output to the appropriate type (if you do not fear losing precision).
input = input.astype(np.float32)
output = output.astype(np.float32)
should work
Note: even if you do this, the error might remain if you have a BatchIterator
which transforms your data (and by inadvertance uses float64
again). The solution is the same: inside the BatchIterator
, cast the data to float32
right before returning it.
Upvotes: 6