using SHAP with Inception V3

95 views Asked by At

I am trying to run GradientExplainer method of SHAP on a trained Inception V3 model. I could do it without a problem on a VGG16 and MobileNet. The difference between Inception and those two models is the input dimension shape being 299 instead of 224.

But when I try SHAP on Inception I receive a long, confusing error that I cannot figure out and wasn't able to find an answer for here or elsewhere. Here is the error. Has someone here been able to visualize Inception V3 results using SHAP's GradientExplainer?

'''
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
   1376     try:
-> 1377       return fn(*args)
   1378     except errors.OpError as e:

9 frames
InvalidArgumentError: 2 root error(s) found.
  (0) INVALID_ARGUMENT: You must feed a value for placeholder tensor 'input_1' with dtype float and shape [?,299,299,3]
     [[{{node input_1}}]]
     [[dense_2/Softmax/_34069]]
  (1) INVALID_ARGUMENT: You must feed a value for placeholder tensor 'input_1' with dtype float and shape [?,299,299,3]
     [[{{node input_1}}]]
0 successful operations.
0 derived errors ignored.

During handling of the above exception, another exception occurred:

InvalidArgumentError                      Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)
   1394                     '\nsession_config.graph_options.rewrite_options.'
   1395                     'disable_meta_optimizer = True')
-> 1396       raise type(e)(node_def, op, message)  # pylint: disable=no-value-for-parameter
   1397 
   1398   def _extend_graph(self):

InvalidArgumentError: Graph execution error:

Detected at node 'input_1' defined at (most recent call last):
    File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
      return _run_code(code, main_globals, None,
    File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
      exec(code, run_globals)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel_launcher.py", line 16, in <module>
      app.launch_new_instance()
    File "/usr/local/lib/python3.8/dist-packages/traitlets/config/application.py", line 992, in launch_instance
      app.start()
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelapp.py", line 612, in start
      self.io_loop.start()
    File "/usr/local/lib/python3.8/dist-packages/tornado/platform/asyncio.py", line 149, in start
      self.asyncio_loop.run_forever()
    File "/usr/lib/python3.8/asyncio/base_events.py", line 570, in run_forever
      self._run_once()
    File "/usr/lib/python3.8/asyncio/base_events.py", line 1859, in _run_once
      handle._run()
    File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
      self._context.run(self._callback, *self._args)
    File "/usr/local/lib/python3.8/dist-packages/tornado/ioloop.py", line 690, in <lambda>
      lambda f: self._run_callback(functools.partial(callback, future))
    File "/usr/local/lib/python3.8/dist-packages/tornado/ioloop.py", line 743, in _run_callback
      ret = callback()
    File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 787, in inner
      self.run()
    File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 748, in run
      yielded = self.gen.send(value)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py", line 365, in process_one
      yield gen.maybe_future(dispatch(*args))
    File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 209, in wrapper
      yielded = next(result)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py", line 268, in dispatch_shell
      yield gen.maybe_future(handler(stream, idents, msg))
    File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 209, in wrapper
      yielded = next(result)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py", line 543, in execute_request
      self.do_execute(
    File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 209, in wrapper
      yielded = next(result)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/ipkernel.py", line 306, in do_execute
      res = shell.run_cell(code, store_history=store_history, silent=silent)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/zmqshell.py", line 536, in run_cell
      return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 2854, in run_cell
      result = self._run_cell(
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 2881, in _run_cell
      return runner(coro)
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/async_helpers.py", line 68, in _pseudo_sync_runner
      coro.send(None)
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3057, in run_cell_async
      has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3249, in run_ast_nodes
      if (await self.run_code(code, result,  async_=asy)):
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3326, in run_code
      exec(code_obj, self.user_global_ns, self.user_ns)
    File "<ipython-input-28-2966d0b0f166>", line 2, in <module>
      model = tf.keras.models.load_model(f'/content/drive/MyDrive/Colab Notebooks/models/{model_name}')
    File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/keras/saving/save.py", line 209, in load_model
      return saved_model_load.load(filepath_str, compile, options)
    File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 135, in load
      keras_loader.load_layers(compile=compile)
    File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 399, in load_layers
      self.loaded_nodes[node_metadata.node_id] = self._load_layer(
    File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 441, in _load_layer
      obj, setter = self._revive_from_config(identifier, metadata, node_id)
    File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 459, in _revive_from_config
      self._revive_layer_or_model_from_config(metadata, node_id))
    File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 523, in _revive_layer_or_model_from_config
      obj = layers_module.deserialize(
    File "/usr/local/lib/python3.8/dist-packages/keras/layers/serialization.py", line 205, in deserialize
      return generic_utils.deserialize_keras_object(
    File "/usr/local/lib/python3.8/dist-packages/keras/utils/generic_utils.py", line 686, in deserialize_keras_object
      deserialized_obj = cls.from_config(cls_config)
    File "/usr/local/lib/python3.8/dist-packages/keras/engine/base_layer_v1.py", line 515, in from_config
      return cls(**config)
    File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/keras/engine/input_layer.py", line 200, in __init__
      input_tensor = backend.placeholder(
    File "/usr/local/lib/python3.8/dist-packages/keras/backend.py", line 1386, in placeholder
      x = tf.compat.v1.placeholder(dtype, shape=shape, name=name)
Node: 'input_1'
Detected at node 'input_1' defined at (most recent call last):
    File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
      return _run_code(code, main_globals, None,
    File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
      exec(code, run_globals)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel_launcher.py", line 16, in <module>
      app.launch_new_instance()
    File "/usr/local/lib/python3.8/dist-packages/traitlets/config/application.py", line 992, in launch_instance
      app.start()
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelapp.py", line 612, in start
      self.io_loop.start()
    File "/usr/local/lib/python3.8/dist-packages/tornado/platform/asyncio.py", line 149, in start
      self.asyncio_loop.run_forever()
    File "/usr/lib/python3.8/asyncio/base_events.py", line 570, in run_forever
      self._run_once()
    File "/usr/lib/python3.8/asyncio/base_events.py", line 1859, in _run_once
      handle._run()
    File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
      self._context.run(self._callback, *self._args)
    File "/usr/local/lib/python3.8/dist-packages/tornado/ioloop.py", line 690, in <lambda>
      lambda f: self._run_callback(functools.partial(callback, future))
    File "/usr/local/lib/python3.8/dist-packages/tornado/ioloop.py", line 743, in _run_callback
      ret = callback()
    File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 787, in inner
      self.run()
    File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 748, in run
      yielded = self.gen.send(value)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py", line 365, in process_one
      yield gen.maybe_future(dispatch(*args))
    File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 209, in wrapper
      yielded = next(result)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py", line 268, in dispatch_shell
      yield gen.maybe_future(handler(stream, idents, msg))
    File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 209, in wrapper
      yielded = next(result)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py", line 543, in execute_request
      self.do_execute(
    File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 209, in wrapper
      yielded = next(result)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/ipkernel.py", line 306, in do_execute
      res = shell.run_cell(code, store_history=store_history, silent=silent)
    File "/usr/local/lib/python3.8/dist-packages/ipykernel/zmqshell.py", line 536, in run_cell
      return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 2854, in run_cell
      result = self._run_cell(
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 2881, in _run_cell
      return runner(coro)
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/async_helpers.py", line 68, in _pseudo_sync_runner
      coro.send(None)
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3057, in run_cell_async
      has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3249, in run_ast_nodes
      if (await self.run_code(code, result,  async_=asy)):
    File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3326, in run_code
      exec(code_obj, self.user_global_ns, self.user_ns)
    File "<ipython-input-28-2966d0b0f166>", line 2, in <module>
      model = tf.keras.models.load_model(f'/content/drive/MyDrive/Colab Notebooks/models/{model_name}')
    File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/keras/saving/save.py", line 209, in load_model
      return saved_model_load.load(filepath_str, compile, options)
    File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 135, in load
      keras_loader.load_layers(compile=compile)
    File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 399, in load_layers
      self.loaded_nodes[node_metadata.node_id] = self._load_layer(
    File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 441, in _load_layer
      obj, setter = self._revive_from_config(identifier, metadata, node_id)
    File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 459, in _revive_from_config
      self._revive_layer_or_model_from_config(metadata, node_id))
    File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 523, in _revive_layer_or_model_from_config
      obj = layers_module.deserialize(
    File "/usr/local/lib/python3.8/dist-packages/keras/layers/serialization.py", line 205, in deserialize
      return generic_utils.deserialize_keras_object(
    File "/usr/local/lib/python3.8/dist-packages/keras/utils/generic_utils.py", line 686, in deserialize_keras_object
      deserialized_obj = cls.from_config(cls_config)
    File "/usr/local/lib/python3.8/dist-packages/keras/engine/base_layer_v1.py", line 515, in from_config
      return cls(**config)
    File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/usr/local/lib/python3.8/dist-packages/keras/engine/input_layer.py", line 200, in __init__
      input_tensor = backend.placeholder(
    File "/usr/local/lib/python3.8/dist-packages/keras/backend.py", line 1386, in placeholder
      x = tf.compat.v1.placeholder(dtype, shape=shape, name=name)
Node: 'input_1'
2 root error(s) found.
  (0) INVALID_ARGUMENT: You must feed a value for placeholder tensor 'input_1' with dtype float and shape [?,299,299,3]
     [[{{node input_1}}]]
     [[dense_2/Softmax/_34069]]
  (1) INVALID_ARGUMENT: You must feed a value for placeholder tensor 'input_1' with dtype float and shape [?,299,299,3]
     [[{{node input_1}}]]
0 successful operations.
0 derived errors ignored.

Original stack trace for 'input_1':
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.8/dist-packages/ipykernel_launcher.py", line 16, in <module>
    app.launch_new_instance()
  File "/usr/local/lib/python3.8/dist-packages/traitlets/config/application.py", line 992, in launch_instance
    app.start()
  File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelapp.py", line 612, in start
    self.io_loop.start()
  File "/usr/local/lib/python3.8/dist-packages/tornado/platform/asyncio.py", line 149, in start
    self.asyncio_loop.run_forever()
  File "/usr/lib/python3.8/asyncio/base_events.py", line 570, in run_forever
    self._run_once()
  File "/usr/lib/python3.8/asyncio/base_events.py", line 1859, in _run_once
    handle._run()
  File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.8/dist-packages/tornado/ioloop.py", line 690, in <lambda>
    lambda f: self._run_callback(functools.partial(callback, future))
  File "/usr/local/lib/python3.8/dist-packages/tornado/ioloop.py", line 743, in _run_callback
    ret = callback()
  File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 787, in inner
    self.run()
  File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 748, in run
    yielded = self.gen.send(value)
  File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py", line 365, in process_one
    yield gen.maybe_future(dispatch(*args))
  File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 209, in wrapper
    yielded = next(result)
  File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py", line 268, in dispatch_shell
    yield gen.maybe_future(handler(stream, idents, msg))
  File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 209, in wrapper
    yielded = next(result)
  File "/usr/local/lib/python3.8/dist-packages/ipykernel/kernelbase.py", line 543, in execute_request
    self.do_execute(
  File "/usr/local/lib/python3.8/dist-packages/tornado/gen.py", line 209, in wrapper
    yielded = next(result)
  File "/usr/local/lib/python3.8/dist-packages/ipykernel/ipkernel.py", line 306, in do_execute
    res = shell.run_cell(code, store_history=store_history, silent=silent)
  File "/usr/local/lib/python3.8/dist-packages/ipykernel/zmqshell.py", line 536, in run_cell
    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 2854, in run_cell
    result = self._run_cell(
  File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 2881, in _run_cell
    return runner(coro)
  File "/usr/local/lib/python3.8/dist-packages/IPython/core/async_helpers.py", line 68, in _pseudo_sync_runner
    coro.send(None)
  File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3057, in run_cell_async
    has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
  File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3249, in run_ast_nodes
    if (await self.run_code(code, result,  async_=asy)):
  File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-28-2966d0b0f166>", line 2, in <module>
    model = tf.keras.models.load_model(f'/content/drive/MyDrive/Colab Notebooks/models/{model_name}')
  File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 64, in error_handler
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/keras/saving/save.py", line 209, in load_model
    return saved_model_load.load(filepath_str, compile, options)
  File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 135, in load
    keras_loader.load_layers(compile=compile)
  File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 399, in load_layers
    self.loaded_nodes[node_metadata.node_id] = self._load_layer(
  File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 441, in _load_layer
    obj, setter = self._revive_from_config(identifier, metadata, node_id)
  File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 459, in _revive_from_config
    self._revive_layer_or_model_from_config(metadata, node_id))
  File "/usr/local/lib/python3.8/dist-packages/keras/saving/saved_model/load.py", line 523, in _revive_layer_or_model_from_config
    obj = layers_module.deserialize(
  File "/usr/local/lib/python3.8/dist-packages/keras/layers/serialization.py", line 205, in deserialize
    return generic_utils.deserialize_keras_object(
  File "/usr/local/lib/python3.8/dist-packages/keras/utils/generic_utils.py", line 686, in deserialize_keras_object
    deserialized_obj = cls.from_config(cls_config)
  File "/usr/local/lib/python3.8/dist-packages/keras/engine/base_layer_v1.py", line 515, in from_config
    return cls(**config)
  File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 64, in error_handler
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/keras/engine/input_layer.py", line 200, in __init__
    input_tensor = backend.placeholder(
  File "/usr/local/lib/python3.8/dist-packages/keras/backend.py", line 1386, in placeholder
    x = tf.compat.v1.placeholder(dtype, shape=shape, name=name)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/ops/array_ops.py", line 3346, in placeholder
    return gen_array_ops.placeholder(dtype=dtype, shape=shape, name=name)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 6893, in placeholder
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/op_def_library.py", line 797, in _apply_op_helper
    op = g._create_op_internal(op_type_name, inputs, dtypes=None,
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/ops.py", line 3754, in _create_op_internal
    ret = Operation(
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/ops.py", line 2133, in __init__
    self._traceback = tf_stack.extract_stack_for_node(self._c_op)
'''
0

There are 0 answers