Skip to content

TypeError: cost must be a scalar. #4

@noelcodella

Description

@noelcodella

Hi,

I'm getting an error: "TypeError: cost must be a scalar." in line 432 of gradient.py in theano.

I'm using Anaconda with Python 2.7, Lasagne 0.1.dev0, scikit-learn 0.15.2, Theano 0.7, "nolearn-0.6a0.dev0".

Can you specify the versions of Theano, Lasagne, and nolearn that work with your code?

Full error results are below:

python mnist_conv_autoencode.py
Using gpu device 0: Tesla K40m
/usr/local/anaconda/lib/python2.7/site-packages/Lasagne-0.1.dev0-py2.7.egg/lasagne/init.py:86: UserWarning: The uniform initializer no longer uses Glorot e.'s approach to determine the bounds, but defaults to the range (-0.01, 0.01) instead. Please use the new GlorotUniform initializer to get the old behaviororotUniform is now the default for all layers.
warnings.warn("The uniform initializer no longer uses Glorot et al.'s "
/usr/local/anaconda/lib/python2.7/site-packages/Lasagne-0.1.dev0-py2.7.egg/lasagne/layers/helper.py:69: UserWarning: get_all_layers() has been changed to rn layers in topological order. The former implementation is still available as get_all_layers_old(), but will be removed before the first release of Lasagno ignore this warning, use warnings.filterwarnings('ignore', '.*topo.*').
warnings.warn("get_all_layers() has been changed to return layers in "
/usr/local/anaconda/lib/python2.7/site-packages/nolearn/lasagne.py:376: UserWarning: layer.get_output_shape() is deprecated and will be removed for the firelease of Lasagne. Please use layer.output_shape instead.
output_shape = layer.get_output_shape()
ReshapeLayer (None, 784) produces 784 outputs
Conv2DLayer (None, 1, 28, 28) produces 784 outputs
Unpool2DLayer (None, 32, 34, 34) produces 36992 outputs
ReshapeLayer (None, 32, 17, 17) produces 9248 outputs
DenseLayer (None, 9248) produces 9248 outputs
DenseLayer (None, 40) produces 40 outputs
ReshapeLayer (None, 3872) produces 3872 outputs
MaxPool2DLayer (None, 32, 11, 11) produces 3872 outputs
Conv2DLayer (None, 32, 22, 22) produces 15488 outputs
InputLayer (None, 1, 28, 28) produces 784 outputs
/usr/local/anaconda/lib/python2.7/site-packages/nolearn/lasagne.py:283: UserWarning: layer.get_output(...) is deprecated and will be removed for the first ase of Lasagne. Please use lasagne.layers.get_output(layer, ...) instead.
output_layer.get_output(X_batch), y_batch)
/usr/local/anaconda/lib/python2.7/site-packages/nolearn/lasagne.py:285: UserWarning: layer.get_output(...) is deprecated and will be removed for the first ase of Lasagne. Please use lasagne.layers.get_output(layer, ...) instead.
output_layer.get_output(X_batch, deterministic=True), y_batch)
/usr/local/anaconda/lib/python2.7/site-packages/nolearn/lasagne.py:286: UserWarning: layer.get_output(...) is deprecated and will be removed for the first ase of Lasagne. Please use lasagne.layers.get_output(layer, ...) instead.
predict_proba = output_layer.get_output(X_batch, deterministic=True)
Traceback (most recent call last):
File "mnist_conv_autoencode.py", line 158, in
ae.fit(X_train, X_out)
File "/usr/local/anaconda/lib/python2.7/site-packages/nolearn/lasagne.py", line 145, in fit
self.y_tensor_type,
File "/usr/local/anaconda/lib/python2.7/site-packages/nolearn/lasagne.py", line 295, in _create_iter_funcs
updates = update(loss_train, all_params, **update_params)
File "/usr/local/anaconda/lib/python2.7/site-packages/Lasagne-0.1.dev0-py2.7.egg/lasagne/updates.py", line 324, in nesterov_momentum
updates = sgd(loss_or_grads, params, learning_rate)
File "/usr/local/anaconda/lib/python2.7/site-packages/Lasagne-0.1.dev0-py2.7.egg/lasagne/updates.py", line 134, in sgd
grads = get_or_compute_grads(loss_or_grads, params)
File "/usr/local/anaconda/lib/python2.7/site-packages/Lasagne-0.1.dev0-py2.7.egg/lasagne/updates.py", line 110, in get_or_compute_grads
return theano.grad(loss_or_grads, params)
File "/usr/local/anaconda/lib/python2.7/site-packages/theano/gradient.py", line 432, in grad
raise TypeError("cost must be a scalar.")
TypeError: cost must be a scalar.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions