Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code crashes for new version of TF and Keras #12

Open
vianamp opened this issue Nov 14, 2017 · 6 comments
Open

Code crashes for new version of TF and Keras #12

vianamp opened this issue Nov 14, 2017 · 6 comments

Comments

@vianamp
Copy link

vianamp commented Nov 14, 2017

Hi. I just updated Keras (2.1.0) and TF (1.4.0) and the your code is no longer working. It seems that the function K.gradients(...) is now returning [None]. Any idea how to fix it without downgrading to older versions?

Full error report:

Traceback (most recent call last):
  File "/Users/mviana/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 510, in _apply_op_helper
    preferred_dtype=default_dtype)
  File "/Users/mviana/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 926, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/Users/mviana/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/constant_op.py", line 229, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/Users/mviana/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/constant_op.py", line 208, in constant
    value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "/Users/mviana/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/tensor_util.py", line 371, in make_tensor_proto
    raise ValueError("None values not supported.")
ValueError: None values not supported.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/mviana/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 524, in _apply_op_helper
    values, as_ref=input_arg.is_ref).dtype.name
  File "/Users/mviana/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 926, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/Users/mviana/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/constant_op.py", line 229, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/Users/mviana/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/constant_op.py", line 208, in constant
    value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "/Users/mviana/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/tensor_util.py", line 371, in make_tensor_proto
    raise ValueError("None values not supported.")
ValueError: None values not supported.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "grad-cam-or.py", line 138, in <module>
    cam, heatmap = grad_cam(model, preprocessed_input, predicted_class, "block5_conv3")
  File "grad-cam-or.py", line 100, in grad_cam
    grads = normalize(K.gradients(loss, conv_output)[0])
  File "grad-cam-or.py", line 22, in normalize
    return x / (K.sqrt(K.mean(K.square(x))) + 1e-5)
  File "/Users/mviana/anaconda3/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 1412, in square
    return tf.square(x)
  File "/Users/mviana/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/math_ops.py", line 449, in square
    return gen_math_ops.square(x, name=name)
  File "/Users/mviana/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/gen_math_ops.py", line 4567, in square
    "Square", x=x, name=name)
  File "/Users/mviana/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 528, in _apply_op_helper
    (input_name, err))
ValueError: Tried to convert 'x' to a tensor and failed. Error: None values not supported.
@xieenze
Copy link

xieenze commented Dec 5, 2017

i have the same problem

@vianamp
Copy link
Author

vianamp commented Dec 5, 2017

Hi @xieenze. Apparently it has not been fixed. Please check: #8478.

@back-kh
Copy link

back-kh commented Dec 13, 2017

Hello! any solution of this problem ?

@chavdim
Copy link

chavdim commented Jan 8, 2018

downgrading keras worked for me.
pip3 install 'keras==2.0.9' --force-reinstall
can make it work again

@vense
Copy link

vense commented Jan 24, 2018

@chavdim Thanks for your comment. But it is not a perfect solution.
So, I modified code little. https://github.com/vense/keras-grad-cam/blob/master/grad-cam.py
This code is tested by keras version 2.1.3.

@Mateus224
Copy link

@vense i tried your code too but i get:

np.float32(cam) + np.float32(image)
ValueError: operands could not be broadcast together with shapes (224,224,3) (3,224,224) 

why they have different shapes? I this because of Tenorflow? My version is 1.13.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants