albermax / innvestigate

A toolbox to iNNvestigate neural networks' predictions!
Other
1.25k stars 233 forks source link

Warning in running iNNvestigate with branch feature/version2.0_rc0_branched2 #191

Closed PeishiJiang closed 2 years ago

PeishiJiang commented 4 years ago

Hello,

I'm trying to use the version with Tensorflow 2 supported (branch: feature/version2.0_rc0_branched2). After realizing that the upgrade is still in progress, I tested the introduction notebook with some quick modifications in the notebook (e.g., changing keras to tensorflow.keras). Most codes run smoothly but with the following warnings and one error (shown in the following). Will the warning affect the analyzer results? And is there any way to get around the error? Last, is there any approximate date when a full upgraded version for Tensorflow 2 will be ready? Very much appreciate it in advance!

First, the warning occurs when the analyzer is performed (e.g., analysis = gradient_analyzer.analyze(image)). For example: WARNING:tensorflow:AutoGraph could not transform <bound method GradientWRT.call of <innvestigate.layers.GradientWRT object at 0x7f9879736080>> and will run it as-is. Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, export AUTOGRAPH_VERBOSITY=10) and attach the full output. Cause: Mangled names are not yet supported by AutoGraph

The error occurs when I conduct the analyzer according to different neuron output, as shown in the following: `--------------------------------------------------------------------------- _FallbackException Traceback (most recent call last) /usr/local/anaconda3/envs/geosci/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_math_ops.py in equal(x, y, incompatible_shape_error, name) 3222 tld.op_callbacks, x, y, "incompatible_shape_error", -> 3223 incompatible_shape_error) 3224 return _result

_FallbackException: This function does not handle the case of the path where all inputs are not already EagerTensors.

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)

in 2 print("Analysis w.r.t. to neuron", neuron_index) 3 # Applying the analyzer and pass that we want ----> 4 analysis = inputXgradient_analyzer.analyze(image, neuron_index) 5 6 # Displaying the gradient ~/Codes/innvestigate/innvestigate/analyzer/base.py in analyze(self, X, neuron_selection) 402 """ 403 if not hasattr(self, "_analyzer_model"): --> 404 self.create_analyzer_model() 405 406 X = iutils.to_list(X) ~/Codes/innvestigate/innvestigate/analyzer/base.py in create_analyzer_model(self) 337 338 tmp = self._create_analysis( --> 339 model, stop_analysis_at_tensors=stop_analysis_at_tensors) 340 if isinstance(tmp, tuple): 341 if len(tmp) == 3: ~/Codes/innvestigate/innvestigate/analyzer/gradient_based.py in _create_analysis(self, model, stop_analysis_at_tensors) 134 135 def _create_analysis(self, model, stop_analysis_at_tensors=[]): --> 136 tensors_to_analyze = [x for x in iutils.to_list(model.inputs) 137 if x not in stop_analysis_at_tensors] 138 gradients = super(InputTimesGradient, self)._create_analysis( ~/Codes/innvestigate/innvestigate/analyzer/gradient_based.py in (.0) 135 def _create_analysis(self, model, stop_analysis_at_tensors=[]): 136 tensors_to_analyze = [x for x in iutils.to_list(model.inputs) --> 137 if x not in stop_analysis_at_tensors] 138 gradients = super(InputTimesGradient, self)._create_analysis( 139 model, stop_analysis_at_tensors=stop_analysis_at_tensors) /usr/local/anaconda3/envs/geosci/lib/python3.7/site-packages/tensorflow_core/python/ops/math_ops.py in tensor_equals(self, other) 1349 (g is None or g._building_function)): # pylint: disable=protected-access 1350 if fwd_compat.forward_compatible(2019, 9, 25): -> 1351 return gen_math_ops.equal(self, other, incompatible_shape_error=False) 1352 else: 1353 return gen_math_ops.equal(self, other) /usr/local/anaconda3/envs/geosci/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_math_ops.py in equal(x, y, incompatible_shape_error, name) 3227 return equal_eager_fallback( 3228 x, y, incompatible_shape_error=incompatible_shape_error, -> 3229 name=name, ctx=_ctx) 3230 except _core._SymbolicException: 3231 pass # Add nodes to the TensorFlow graph. /usr/local/anaconda3/envs/geosci/lib/python3.7/site-packages/tensorflow_core/python/ops/gen_math_ops.py in equal_eager_fallback(x, y, incompatible_shape_error, name, ctx) 3256 incompatible_shape_error = True 3257 incompatible_shape_error = _execute.make_bool(incompatible_shape_error, "incompatible_shape_error") -> 3258 _attr_T, _inputs_T = _execute.args_to_matching_eager([x, y], ctx) 3259 (x, y) = _inputs_T 3260 _inputs_flat = [x, y] /usr/local/anaconda3/envs/geosci/lib/python3.7/site-packages/tensorflow_core/python/eager/execute.py in args_to_matching_eager(l, ctx, default_dtype) 261 ret.append( 262 ops.convert_to_tensor( --> 263 t, dtype, preferred_dtype=default_dtype, ctx=ctx)) 264 if dtype is None: 265 dtype = ret[-1].dtype /usr/local/anaconda3/envs/geosci/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py in convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, dtype_hint, ctx, accepted_result_types) 1288 raise ValueError( 1289 "Tensor conversion requested dtype %s for Tensor with dtype %s: %r" % -> 1290 (dtype.name, value.dtype.name, value)) 1291 return value 1292 ValueError: Tensor conversion requested dtype float32 for Tensor with dtype int32: '
adrhill commented 2 years ago

Hi @PeishiJiang,

we just released iNNvestigate 2.0 with support for TensorFlow 2! Please try it out and let me know if this fixes your issue. :)