kyle-dorman / bayesian-neural-network-blogpost

Building a Bayesian deep learning classifier
https://medium.com/towards-data-science/building-a-bayesian-deep-learning-classifier-ece1845bc09
481 stars 105 forks source link

Error in bayesian_categorical_crossentropy_internal in bnn/loss_equations.py #1

Closed olenash closed 6 years ago

olenash commented 6 years ago

I ran bin/create_batch_data.py successfully. But when I run bin/train.py an error TypeError: Failed to convert object of type <class 'theano.tensor.var.TensorVariable'> to Tensor. Contents: Elemwise{second,no_inplace}.0. Consider casting elements to a supported type. occurs in bnn/loss_equations.py in bayesian_categorical_crossentropy_internal function in dist = distributions.Normal(loc=K.zeros_like(std), scale=std). I run project under Python2.7, TensorFlow version 1.3.0.

Here is an error:
Using Theano backend.
('encoder:', 'resnet50')
('batch_size:', 32)
('epochs:', 1)
('dataset:', 'cifar10')
('monte_carlo_simulations:', 100)
Unpickling file batch_data/resnet50_cifar10/train.p
Unpickling file batch_data/resnet50_cifar10/test.p
Compiling model.
Traceback (most recent call last):
  File "bin/train.py", line 88, in <module>
    tf.app.run()
  File "/home/oshevech/anaconda2/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "bin/train.py", line 66, in main
    loss_weights={'logits_variance': .2, 'softmax_output': 1.})
  File "/home/oshevech/anaconda2/lib/python2.7/site-packages/keras/engine/training.py", line 899, in compile
    sample_weight, mask)
  File "/home/oshevech/anaconda2/lib/python2.7/site-packages/keras/engine/training.py", line 430, in weighted
    score_array = fn(y_true, y_pred)
  File "/home/oshevech/Documents/Work/bayesian-neural-network-blogpost/bnn/loss_equations.py", line 72, in bayesian_categorical_crossentropy_internal
    dist = distributions.Normal(loc=K.zeros_like(std), scale=std)
  File "/home/oshevech/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/distributions/normal.py", line 136, in init
    self._loc = array_ops.identity(loc, name="loc")
  File "/home/oshevech/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1400, in identity
    result = _op_def_lib.apply_op("Identity", input=input, name=name)
  File "/home/oshevech/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 493, in apply_op
    raise err
TypeError: Failed to convert object of type <class 'theano.tensor.var.TensorVariable'> to Tensor. Contents: Elemwise{second,no_inplace}.0. Consider casting elements to a supported type.
olenash commented 6 years ago

I found the source of an issue - my keras used theano backend, not tensorflow.