Chapter2 - visualization.py fails on line 126
elviejokike opened this issue · 4 comments
After using the instructions mentioned in https://github.com/PracticalDL/Practical-Deep-Learning-Book/tree/master/code/chapter-2 (updating the .json file) and running the script on my own environment. I get the following error:
2019-12-29 21:33:16.538110: I tensorflow/core/common_runtime/process_util.cc:115] Creating new thread pool with default inter op setting: 2. Tune using inter_op_parallelism_threads for best performance.
Traceback (most recent call last):
File "visualization.py", line 162, in
process_image(image_path, output_prefix + "_output.jpg")
File "visualization.py", line 126, in process_image heatmap = explainer.explain(data, model, "block5_conv3", class_index)
File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tf_explain/core/grad_cam.py", line 50, inexplain model, images, layer_name, class_index
File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow_core/python/eager/def_function.py", line 457, in call result = self._call(*args, **kwds)
File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow_core/python/eager/def_function.py", line 503, in _call
self._initialize(args, kwds, add_initializers_to=initializer_map)
File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow_core/python/eager/def_function.py", line 408, in _initialize
*args, **kwds))
File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 1848, in _get_concrete_function_internal_garbage_collected
graph_function, _, _ = self._maybe_define_function(args, kwargs)
File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 2150, in _maybe_define_function
graph_function = self._create_graph_function(args, kwargs)
File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 2041, in _create_graph_function
capture_by_value=self._capture_by_value),
File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow_core/python/framework/func_graph.py", line 915, in func_graph_from_py_func
func_outputs = python_func(*func_args, **func_kwargs)
File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow_core/python/eager/def_function.py", line 358, in wrapped_fn
return weak_wrapped_fn().wrapped(*args, **kwds)
File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow_core/python/framework/func_graph.py", line 905, in wrapper
raise e.ag_error_metadata.to_exception(e)
TypeError: in converted code:
relative to /home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages:
tf_explain/core/grad_cam.py:102 get_gradients_and_filters *
grad_model = tf.keras.models.Model(
tensorflow_core/python/keras/engine/network.py:539 get_layer
raise ValueError('No such layer: ' + name)
TypeError: must be str, not numpy.int64
The same error is reported on my notebook when using the code copied from https://github.com/practicaldl/Practical-Deep-Learning-Book/blob/master/code/chapter-2/2-colab-what-does-my-neural-network-think.ipynb
Thanks for reporting this. It appears to be a regression in tf-explain 0.2.0
, which was released 3 days ago. Try changing the pip install tf-explain
line to pip install tf-explain==0.1.0
. That appears to fix the problem for me.
I've fixed this in PR #57.
Thanks. Perhaps, it will be nicer to have a requirements.txt file per chapter / module.