tensorflow-2-feature-visualization-notebooks icon indicating copy to clipboard operation
tensorflow-2-feature-visualization-notebooks copied to clipboard

0.0-Visualizing-classes cell 16 tensorflow issue

Open ariejdl opened this issue 3 years ago • 2 comments

Hello, thanks for the nice notebooks. I wonder if Tensorflow is now out-of-date here. I have this error when running cell 16 of the first notebook

0%|          | 0/50 [00:00<?, ?it/s]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-16-47964fe28d06> in <module>
     12 
     13 filters_shape = submodel.outputs[0].shape
---> 14 output_images, loss_list = optimize_filter(
     15     submodel,
     16     layer_name,

<ipython-input-14-9e5aab1202f0> in optimize_filter(submodel, layer_name, filter_index, filters_shape, steps, lr, layer_dims, n_upsample, sigma, upscaling_factor, soft_norm_std, single_receptive_field, norm_f, normalize_grads)
     39 
     40         # optimize
---> 41         img_data, loss = opt(
     42             submodel,
     43             img_data,

/opt/homebrew/Caskroom/miniforge/base/envs/conda_tf/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py in __call__(self, *args, **kwds)
    826     tracing_count = self.experimental_get_tracing_count()
    827     with trace.Trace(self._name) as tm:
--> 828       result = self._call(*args, **kwds)
    829       compiler = "xla" if self._experimental_compile else "nonXla"
    830       new_tracing_count = self.experimental_get_tracing_count()

/opt/homebrew/Caskroom/miniforge/base/envs/conda_tf/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds)
    869       # This is the first call of __call__, so we have to initialize.
    870       initializers = []
--> 871       self._initialize(args, kwds, add_initializers_to=initializers)
    872     finally:
    873       # At this point we know that the initialization is complete (or less

/opt/homebrew/Caskroom/miniforge/base/envs/conda_tf/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py in _initialize(self, args, kwds, add_initializers_to)
    723     self._graph_deleter = FunctionDeleter(self._lifted_initializer_graph)
    724     self._concrete_stateful_fn = (
--> 725         self._stateful_fn._get_concrete_function_internal_garbage_collected(  # pylint: disable=protected-access
    726             *args, **kwds))
    727 

/opt/homebrew/Caskroom/miniforge/base/envs/conda_tf/lib/python3.8/site-packages/tensorflow/python/eager/function.py in _get_concrete_function_internal_garbage_collected(self, *args, **kwargs)
   2967       args, kwargs = None, None
   2968     with self._lock:
-> 2969       graph_function, _ = self._maybe_define_function(args, kwargs)
   2970     return graph_function
   2971 

/opt/homebrew/Caskroom/miniforge/base/envs/conda_tf/lib/python3.8/site-packages/tensorflow/python/eager/function.py in _maybe_define_function(self, args, kwargs)
   3359 
   3360           self._function_cache.missed.add(call_context_key)
-> 3361           graph_function = self._create_graph_function(args, kwargs)
   3362           self._function_cache.primary[cache_key] = graph_function
   3363 

/opt/homebrew/Caskroom/miniforge/base/envs/conda_tf/lib/python3.8/site-packages/tensorflow/python/eager/function.py in _create_graph_function(self, args, kwargs, override_flat_arg_shapes)
   3194     arg_names = base_arg_names + missing_arg_names
   3195     graph_function = ConcreteFunction(
-> 3196         func_graph_module.func_graph_from_py_func(
   3197             self._name,
   3198             self._python_function,

/opt/homebrew/Caskroom/miniforge/base/envs/conda_tf/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py in func_graph_from_py_func(name, python_func, args, kwargs, signature, func_graph, autograph, autograph_options, add_control_dependencies, arg_names, op_return_value, collections, capture_by_value, override_flat_arg_shapes)
    988         _, original_func = tf_decorator.unwrap(python_func)
    989 
--> 990       func_outputs = python_func(*func_args, **func_kwargs)
    991 
    992       # invariant: `func_outputs` contains only Tensors, CompositeTensors,

/opt/homebrew/Caskroom/miniforge/base/envs/conda_tf/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py in wrapped_fn(*args, **kwds)
    632             xla_context.Exit()
    633         else:
--> 634           out = weak_wrapped_fn().__wrapped__(*args, **kwds)
    635         return out
    636 

/opt/homebrew/Caskroom/miniforge/base/envs/conda_tf/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py in wrapper(*args, **kwargs)
    975           except Exception as e:  # pylint:disable=broad-except
    976             if hasattr(e, "ag_error_metadata"):
--> 977               raise e.ag_error_metadata.to_exception(e)
    978             else:
    979               raise

ValueError: in user code:

    <ipython-input-12-412fac409d2e>:33 opt  *
        outputs = submodel(tf.nn.sigmoid(input_data))
    /opt/homebrew/Caskroom/miniforge/base/envs/conda_tf/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py:993 __call__  **
        input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
    /opt/homebrew/Caskroom/miniforge/base/envs/conda_tf/lib/python3.8/site-packages/tensorflow/python/keras/engine/input_spec.py:271 assert_input_compatibility
        raise ValueError('Input ' + str(input_index) +

    ValueError: Input 0 is incompatible with layer model: expected shape=(None, 224, 224, 3), found shape=(8, 244, 244, 3)

ariejdl avatar Jun 05 '21 09:06 ariejdl

Yes, that looks light it might be the case! let me know if you have a fix and I can update. I haven't messed with this code since I wrote it.

timsainb avatar Jun 07 '21 16:06 timsainb

Does "def gen_noise" set wrong dimension 244?

JunYiLyu avatar Dec 02 '21 08:12 JunYiLyu