keisen / tf-keras-vis

Neural network visualization toolkit for tf.keras
https://keisen.github.io/tf-keras-vis-docs/
MIT License
313 stars 45 forks source link

ActivationMaximization fails after tf.keras.models.load_model #32

Open omerbrandis opened 3 years ago

omerbrandis commented 3 years ago

hello,

I've manged to execute the Visualize Dense Layer example. then tried the following change :

OriginalModel = Model(weights='imagenet', include_top=True)
OriginalModel.summary()
OriginalModel.save('SavedVgg',include_optimizer=True)
model = tf.keras.models.load_model('SavedVgg')
activation_maximization = ActivationMaximization(model, model_modifier, clone=False)

(model is saved in tensorflow checkpoint format )

this fails at runtime File "DenseLayerVisualization2.py", line 60, in main() File "DenseLayerVisualization2.py", line 46, in main activation = activation_maximization(loss,callbacks=[Print(interval=50)]) File "/usr/local/lib/python3.6/dist-packages/tf_keras_vis/activation_maximization.py", line 92, in call outputs = self.model(seed_inputs, training=training) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/base_layer.py", line 891, in call outputs = self.call(cast_inputs, *args, kwargs) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/saving/saved_model/utils.py", line 57, in return_outputs_and_add_losses outputs, losses = fn(inputs, *args, *kwargs) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/saving/saved_model/utils.py", line 111, in wrap_with_training_arg lambda: replace_training_and_call(False)) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/utils/tf_utils.py", line 59, in smart_cond pred, true_fn=true_fn, false_fn=false_fn, name=name) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/smart_cond.py", line 56, in smart_cond return false_fn() File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/saving/saved_model/utils.py", line 111, in lambda: replace_training_and_call(False)) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/saving/saved_model/utils.py", line 106, in replace_training_and_call return wrapped_call(args, kwargs) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/def_function.py", line 457, in call result = self._call(*args, kwds) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/def_function.py", line 494, in _call results = self._stateful_fn(*args, *kwds) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/function.py", line 1822, in call graph_function, args, kwargs = self._maybe_define_function(args, kwargs) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/function.py", line 2150, in _maybe_define_function graph_function = self._create_graph_function(args, kwargs) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/function.py", line 2041, in _create_graph_function capture_by_value=self._capture_by_value), File "/usr/local/lib/python3.6/dist-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 "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/def_function.py", line 358, in wrapped_fn return weak_wrapped_fn().wrapped(*args, **kwds) File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/saved_model/function_deserialization.py", line 262, in restored_function_body "\n\n".join(signature_descriptions))) ValueError: Could not find matching function to call loaded from the SavedModel. Got: Positional arguments (3 total):

Expected these arguments to match one of the following 4 option(s):.....

Can anyone help ?

thanks, Omer.

keisen commented 3 years ago

Hi, @omerbrandis .

It seems the cause of the error is OriginalModel. Just in case, I will examine the cause of the problem. Could you please submit the code snippet that reproduce the problem?

Thanks!