kohheinomura / keras_classification_tools

5 stars 1 forks source link

error: gradcam_resnet50.py: None values not supported #1

Open HIN0209 opened 6 years ago

HIN0209 commented 6 years ago

Hello, this is an interesting project, but I encountered an error.

My setting: Ubuntu16.04, anaconda3, python3.5.4, tensorflow-gpu 1.6.0, Keras 2.1.5, GPU GTX 1080Ti

I used a dog/cat dataset from Kaggle (2 classes, 22500 training images and 2500 val images). Both train.py and predict.py worked completely. The problem was in gradcam_resnet50.py as follows, essentially 'None values not supported' after prediction was made. Your help is appreciated!!

gradcam_resnet50.py:146: UserWarning: Update your Model call to the Keras 2 API: Model(inputs=Tensor("in..., outputs=Tensor("se...) model = Model(input=resnet50.input, output=top_model(resnet50.output)) Target Image:./data/catdog/val/cat/cat.11760.jpg prediction_time:1.3155994415283203[sec] Predicted class:cat ('cat', 0.9883754) ('dog', 0.011624636) Traceback (most recent call last): File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 510, in _apply_op_helper preferred_dtype=default_dtype) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1036, in internal_convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/constant_op.py", line 235, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/constant_op.py", line 214, in constant value, dtype=dtype, shape=shape, verify_shape=verify_shape)) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/tensor_util.py", line 421, 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 "/home/XXXXX/anaconda3/envs/tensorflow/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 "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1036, in internal_convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/constant_op.py", line 235, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/constant_op.py", line 214, in constant value, dtype=dtype, shape=shape, verify_shape=verify_shape)) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/tensor_util.py", line 421, 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 "gradcam_resnet50.py", line 157, in main() File "gradcam_resnet50.py", line 154, in main createHeatmapGrid(args, cls, model, 'activation_49') File "gradcam_resnet50.py", line 115, in createHeatmapGrid cam, heatmap = grad_cam(model, preprocessed_input, predicted_class, out_layer) File "gradcam_resnet50.py", line 49, in grad_cam grads = normalize(K.gradients(loss, conv_output)[0]) File "gradcam_resnet50.py", line 36, in normalize return x / (K.sqrt(K.mean(K.square(x))) + 1e-5) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 1435, in square return tf.square(x) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/ops/math_ops.py", line 467, in square return gen_math_ops.square(x, name=name) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/ops/gen_math_ops.py", line 4751, in square "Square", x=x, name=name) File "/home/XXXXX/anaconda3/envs/tensorflow/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.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/XXXXX/anaconda3/envs/tensorflow/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 "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1036, in internal_convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/constant_op.py", line 235, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/constant_op.py", line 214, in constant value, dtype=dtype, shape=shape, verify_shape=verify_shape)) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/framework/tensor_util.py", line 421, 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 "gradcam_resnet50.py", line 157, in main() File "gradcam_resnet50.py", line 154, in main createHeatmapGrid(args, cls, model, 'activation_49') File "gradcam_resnet50.py", line 115, in createHeatmapGrid cam, heatmap = grad_cam(model, preprocessed_input, predicted_class, out_layer) File "gradcam_resnet50.py", line 49, in grad_cam grads = normalize(K.gradients(loss, conv_output)[0]) File "gradcam_resnet50.py", line 36, in normalize return x / (K.sqrt(K.mean(K.square(x))) + 1e-5) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 1435, in square return tf.square(x) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/ops/math_ops.py", line 467, in square return gen_math_ops.square(x, name=name) File "/home/XXXXX/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/python/ops/gen_math_ops.py", line 4751, in square "Square", x=x, name=name) File "/home/XXXXX/anaconda3/envs/tensorflow/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.

Hadess24 commented 6 years ago

do you solve it?