josedolz / LiviaNET

This repository contains the code of LiviaNET, a 3D fully convolutional neural network that was employed in our work: "3D fully convolutional networks for subcortical segmentation in MRI: A large-scale study"
MIT License
161 stars 52 forks source link

TypeError with theano #16

Closed iZsh closed 6 years ago

iZsh commented 6 years ago

Hello,

I'm trying to run your training code with python ./networkTraining.py ./LiviaNET_Config.ini 0

and I'm getting TypeError with theano 1.0.1 and python 2.7 and numpy 1.14.3

TypeError: ('TensorType(float32, scalar) cannot store accurately value 0.001, it would be represented as 0.001. If you do not mind this precision loss, you can: 1) explicitly convert your data to a numpy array of dtype float32, or 2) set "allow_input_downcast=True" when calling "function".', 0.001, 'Container name "None"')

that one was coming when callingmyLiviaNet3D.initTrainingParameters with myParserConfigIni.learning_rate

which I fixed with np.cast["float32"](myParserConfigIni.learning_rate)

the same occurred with myParserConfigIni.momentumValue. Fixed likewise.

Unfortunately I'm now hitting the following error:

File "/usr/local/lib/python2.7/dist-packages/theano/gradient.py", line 1326, in access_grad_cache term = access_term_cache(node)[idx] File "/usr/local/lib/python2.7/dist-packages/theano/gradient.py", line 1162, in access_term_cache new_output_grads) File "/usr/local/lib/python2.7/dist-packages/theano/gof/op.py", line 711, in L_op return self.grad(inputs, output_grads) File "/usr/local/lib/python2.7/dist-packages/theano/tensor/nnet/abstract_conv.py", line 2495, in grad d_bottom = bottom.type.filter_variable(d_bottom) File "/usr/local/lib/python2.7/dist-packages/theano/tensor/type.py", line 234, in filter_variable self=self)) TypeError: Cannot convert Type TensorType(float32, 4D) (of Variable AbstractConv2d_gradInputs{convdim=2, border_mode='valid', subsample=(1, 1), filter_flip=True, imshp=(190, 100, 19, 19), kshp=(9, 100, 1, 1), filter_dilation=(1, 1), num_groups=1, unshared=False}.0) into Type TensorType(float64, 4D). You can try to manually convert AbstractConv2d_gradInputs{convdim=2, border_mode='valid', subsample=(1, 1), filter_flip=True, imshp=(190, 100, 19, 19), kshp=(9, 100, 1, 1), filter_dilation=(1, 1), num_groups=1, unshared=False}.0 into a TensorType(float64, 4D).

which is getting more complex and it seems to point at a general casting issue, maybe due to the newer version of theano i'm using?

Could you take a look and help me run your code?

Regards,

iZsh commented 6 years ago

it seems running the code with the following env variable solves the issue:

THEANO_FLAGS='floatX=float32' python ./networkTraining.py ./LiviaNET_Config.ini 0

You might want to document that in your README :-)

josedolz commented 6 years ago

Hi @iZsh,

Thank you for your comments. I am glad you found out the source of your error.

Have a look to the Readme file, on the 'known problems' section. This issue is reported there...:)

Best

iZsh commented 6 years ago

oh gosh. I'm stupid facepalm sorry ;-)