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],
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.