CuriousAI / ladder

Ladder network is a deep learning algorithm that combines supervised and unsupervised learning
MIT License
516 stars 142 forks source link

The image and the kernel must have the same type.inputs(float64), kerns(float32) #13

Closed petteriTeikari closed 8 years ago

petteriTeikari commented 8 years ago

I got the following error when trying to run the cifar10 example:

Traceback (most recent call last):
  File "./run.py", line 652, in <module>
    if train(d) is None:
  File "./run.py", line 410, in train
    ladder = setup_model(p)
  File "./run.py", line 181, in setup_model
    ladder.apply(x, y, x_only)
  File "/home/petteri/ladder/ladder.py", line 195, in apply
    clean = self.act.clean = encoder(input_concat, 'clean')
  File "/home/petteri/ladder/ladder.py", line 183, in encoder
    noise_std=noise)
  File "/home/petteri/ladder/ladder.py", line 349, in f
    z, output_size = self.f_conv(h, spec, in_dim, gen_id('W'))
  File "/home/petteri/ladder/ladder.py", line 450, in f_conv
    filter_size), border_mode=bm)
  File "/home/petteri/anaconda2/lib/python2.7/site-packages/theano/tensor/nnet/conv.py", line 153, in conv2d
    return op(input, filters)
  File "/home/petteri/anaconda2/lib/python2.7/site-packages/theano/gof/op.py", line 602, in __call__
    node = self.make_node(*inputs, **kwargs)
  File "/home/petteri/anaconda2/lib/python2.7/site-packages/theano/tensor/nnet/conv.py", line 655, in make_node
    "inputs(%s), kerns(%s)" % (_inputs.dtype, _kerns.dtype))
NotImplementedError: The image and the kernel must have the same type.inputs(float64), kerns(float32)

Which got fixed by casting manually at line 180 of ladder.py:

h = T.cast(h, 'float32')

But this again later leads to TypeError:

INFO:blocks.algorithms:Initializing the training algorithm
ERROR:blocks.main_loop:Error occured during training.

Blocks will attempt to run `on_error` extensions, potentially saving data, before exiting and reraising the error. Note that the usual `after_training` extensions will *not* be run. The original error will be re-raised and also stored in the training log. Press CTRL + C to halt Blocks immediately.
Traceback (most recent call last):
  File "./run.py", line 652, in <module>
    if train(d) is None:
  File "./run.py", line 500, in train
    main_loop.run()
  File "/home/petteri/anaconda2/lib/python2.7/site-packages/blocks/main_loop.py", line 188, in run
    reraise_as(e)
  File "/home/petteri/anaconda2/lib/python2.7/site-packages/blocks/utils/__init__.py", line 225, in reraise_as
    six.reraise(type(new_exc), new_exc, orig_exc_traceback)
  File "/home/petteri/anaconda2/lib/python2.7/site-packages/blocks/main_loop.py", line 164, in run
    self.algorithm.initialize()
  File "/home/petteri/anaconda2/lib/python2.7/site-packages/blocks/algorithms/__init__.py", line 224, in initialize
    self._function = theano.function(self.inputs, [], updates=all_updates)
  File "/home/petteri/anaconda2/lib/python2.7/site-packages/theano/compile/function.py", line 322, in function
    output_keys=output_keys)
  File "/home/petteri/anaconda2/lib/python2.7/site-packages/theano/compile/pfunc.py", line 443, in pfunc
    no_default_updates=no_default_updates)
  File "/home/petteri/anaconda2/lib/python2.7/site-packages/theano/compile/pfunc.py", line 208, in rebuild_collect_shared
    raise TypeError(err_msg, err_sug)
TypeError: ('An update must have the same type as the original shared variable (shared_var=f_11_b, shared_var.type=TensorType(float32, vector), update_val=Elemwise{sub,no_inplace}.0, update_val.type=TensorType(float64, vector))., If the difference is related to the broadcast pattern, you can call the tensor.unbroadcast(var, axis_to_unbroadcast[, ...]) function to remove broadcastable dimensions.\n\nOriginal exception:\n\tTypeError: An update must have the same type as the original shared variable (shared_var=f_11_b, shared_var.type=TensorType(float32, vector), update_val=Elemwise{sub,no_inplace}.0, update_val.type=TensorType(float64, vector))., If the difference is related to the broadcast pattern, you can call the tensor.unbroadcast(var, axis_to_unbroadcast[, ...]) function to remove broadcastable dimensions.', 'If the difference is related to the broadcast pattern, you can call the tensor.unbroadcast(var, axis_to_unbroadcast[, ...]) function to remove broadcastable dimensions.')

Any thoughts on where it goes wrong?

hotloo commented 8 years ago

Can you try this out with the updated master? Also, could you please post your theanorc here?

Also, would it possible if you can try out the code with the environment that is built from environment.yml?

lfpolani commented 8 years ago

I run into the same problem when using the CIFAR dataset: File "/Users/lfc009/anaconda2/envs/ladder/lib/python2.7/site-packages/theano/gof/op.py", line 611, in call node = self.make_node(_inputs, *_kwargs) File "/Users/lfc009/anaconda2/envs/ladder/lib/python2.7/site-packages/theano/tensor/nnet/conv.py", line 655, in make_node "inputs(%s), kerns(%s)" % (_inputs.dtype, _kerns.dtype)) NotImplementedError: The image and the kernel must have the same type.inputs(float64), kerns(float32)

When running the Mnist dataset, I get the following error: INFO:main:== PARAMETERS == INFO:main: zestbn : bugfix
INFO:main: dseed : 1
INFO:main: top_c : 1
INFO:main: super_noise_std : 0.3
INFO:main: batch_size : 100
INFO:main: dataset : mnist
INFO:main: valid_set_size : 10000
INFO:main: num_epochs : 150
INFO:main: whiten_zca : 0
INFO:main: unlabeled_samples : 60000
INFO:main: decoder_spec : ('gauss',)
INFO:main: valid_batch_size : 100
INFO:main: denoising_cost_x : (1000.0, 1.0, 0.01, 0.01, 0.01, 0.01, 0.01) INFO:main: f_local_noise_std : 0.3
INFO:main: cmd : train
INFO:main: act : relu
INFO:main: lrate_decay : 0.67
INFO:main: seed : 1
INFO:main: lr : 0.002
INFO:main: save_to : mnist_all_full
INFO:main: save_dir : results/mnist_all_full15 INFO:main: commit :
INFO:main: contrast_norm : 0
INFO:main: encoder_layers : ('1000', '500', '250', '250', '250', '10') INFO:main: labeled_samples : 60000
Traceback (most recent call last): File "run.py", line 655, in if train(d) is None: File "run.py", line 409, in train in_dim, data, whiten, cnorm = setup_data(p, test_set=False) File "run.py", line 250, in setup_data 'Make sure data is in float format and in range 0 to 1' AssertionError: Make sure data is in float format and in range 0 to 1

Any idea on how to solve it?

hotloo commented 8 years ago

@lfpolani Sorry for the slow response. Could you please show us your environment setup? I did remember that Fuel has some breaking changes in their dataset between different versions.

Also, could you cross check the environment.yml file that I provided work if you install that exactly?

lfpolani commented 8 years ago

Thanks, I already solved my problem. I will close this issue.

tongmuyuan commented 8 years ago

Hi @ifpolani, I just meet a same error you did, and got this error report:

TypeError: ('An update must have the same type as the original shared variable (shared_var=f_5_b, shared_var.type=TensorType(float32, vector), update_val=Elemwise{sub,no_inplace}.0, update_val.type=TensorType(float64, vector))., If the difference is related to the broadcast pattern, you can call the tensor.unbroadcast(var, axis_to_unbroadcast[, ...]) function to remove broadcastable dimensions.\n\nOriginal exception:\n\tTypeError: An update must have the same type as the original shared variable (shared_var=f_5_b, shared_var.type=TensorType(float32, vector), update_val=Elemwise{sub,no_inplace}.0, update_val.type=TensorType(float64, vector))., If the difference is related to the broadcast pattern, you can call the tensor.unbroadcast(var, axis_to_unbroadcast[, ...]) function to remove broadcastable dimensions.', 'If the difference is related to the broadcast pattern, you can call the tensor.unbroadcast(var, axis_to_unbroadcast[, ...]) function to remove broadcastable dimensions.')

could you please tell me how to solve it on your way. Thank you!