nvecoven / BRC

A repository containing the code for the Bistable Recurrent Cell
47 stars 6 forks source link

Min working example: ValueError: name for name_scope must be a string. #2

Open drozzy opened 4 years ago

drozzy commented 4 years ago

I just tried the min working example and it's giving me this error when I run it in jupyter. The happens for nRBC or BRC layer type (GRU training proceeds normally).

Any idea what might be the issue?

Thanks.

ValueError                                Traceback (most recent call last)
<ipython-input-8-cca6149ff0d3> in <module>
    135         model.fit(x=dataset['input'], y=dataset['output'], epochs = 60, batch_size=100,
    136                   validation_data=(test_dataset['input'], test_dataset['output']),
--> 137                   verbose = True)

~/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs)
     64   def _method_wrapper(self, *args, **kwargs):
     65     if not self._in_multi_worker_mode():  # pylint: disable=protected-access
---> 66       return method(self, *args, **kwargs)
     67 
     68     # Running inside `run_distribute_coordinator` already.

~/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)
    846                 batch_size=batch_size):
    847               callbacks.on_train_batch_begin(step)
--> 848               tmp_logs = train_function(iterator)
    849               # Catch OutOfRangeError for Datasets of unknown size.
    850               # This blocks until the batch has finished executing.

~/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in __call__(self, *args, **kwds)
    578         xla_context.Exit()
    579     else:
--> 580       result = self._call(*args, **kwds)
    581 
    582     if tracing_count == self._get_tracing_count():

~/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds)
    625       # This is the first call of __call__, so we have to initialize.
    626       initializers = []
--> 627       self._initialize(args, kwds, add_initializers_to=initializers)
    628     finally:
    629       # At this point we know that the initialization is complete (or less

~/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in _initialize(self, args, kwds, add_initializers_to)
    504     self._concrete_stateful_fn = (
    505         self._stateful_fn._get_concrete_function_internal_garbage_collected(  # pylint: disable=protected-access
--> 506             *args, **kwds))
    507 
    508     def invalid_creator_scope(*unused_args, **unused_kwds):

~/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/eager/function.py in _get_concrete_function_internal_garbage_collected(self, *args, **kwargs)
   2444       args, kwargs = None, None
   2445     with self._lock:
-> 2446       graph_function, _, _ = self._maybe_define_function(args, kwargs)
   2447     return graph_function
   2448 

~/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/eager/function.py in _maybe_define_function(self, args, kwargs)
   2775 
   2776       self._function_cache.missed.add(call_context_key)
-> 2777       graph_function = self._create_graph_function(args, kwargs)
   2778       self._function_cache.primary[cache_key] = graph_function
   2779       return graph_function, args, kwargs

~/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/eager/function.py in _create_graph_function(self, args, kwargs, override_flat_arg_shapes)
   2665             arg_names=arg_names,
   2666             override_flat_arg_shapes=override_flat_arg_shapes,
-> 2667             capture_by_value=self._capture_by_value),
   2668         self._function_attributes,
   2669         # Tell the ConcreteFunction to clean up its graph once it goes out of

~/miniconda3/envs/patchy_discs_model/lib/python3.7/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)
    979         _, original_func = tf_decorator.unwrap(python_func)
    980 
--> 981       func_outputs = python_func(*func_args, **func_kwargs)
    982 
    983       # invariant: `func_outputs` contains only Tensors, CompositeTensors,

~/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in wrapped_fn(*args, **kwds)
    439         # __wrapped__ allows AutoGraph to swap in a converted function. We give
    440         # the function a weak reference to itself to avoid a reference cycle.
--> 441         return weak_wrapped_fn().__wrapped__(*args, **kwds)
    442     weak_wrapped_fn = weakref.ref(wrapped_fn)
    443 

~/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/framework/func_graph.py in wrapper(*args, **kwargs)
    966           except Exception as e:  # pylint:disable=broad-except
    967             if hasattr(e, "ag_error_metadata"):
--> 968               raise e.ag_error_metadata.to_exception(e)
    969             else:
    970               raise

ValueError: in user code:

    /home/andriy/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py:571 train_function  *
        outputs = self.distribute_strategy.run(
    /home/andriy/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/distribute/distribute_lib.py:951 run  **
        return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
    /home/andriy/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/distribute/distribute_lib.py:2290 call_for_each_replica
        return self._call_for_each_replica(fn, args, kwargs)
    /home/andriy/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/distribute/distribute_lib.py:2649 _call_for_each_replica
        return fn(*args, **kwargs)
    /home/andriy/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py:531 train_step  **
        y_pred = self(x, training=True)
    /home/andriy/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py:927 __call__
        outputs = call_fn(cast_inputs, *args, **kwargs)
    /home/andriy/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/keras/engine/sequential.py:291 call
        outputs = layer(inputs, **kwargs)
    /home/andriy/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/keras/layers/recurrent.py:654 __call__
        return super(RNN, self).__call__(inputs, **kwargs)
    /home/andriy/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py:897 __call__
        self._maybe_build(inputs)
    /home/andriy/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py:2416 _maybe_build
        self.build(input_shapes)  # pylint:disable=not-callable
    /home/andriy/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/keras/layers/recurrent.py:573 build
        self.cell.build(step_input_shape)
    /home/andriy/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/keras/utils/tf_utils.py:316 wrapper
        output_shape = fn(instance, input_shape)
    /home/andriy/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/keras/layers/recurrent.py:169 build
        with K.name_scope(cell.name):
    /home/andriy/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/keras/backend.py:801 name_scope
        return ops.name_scope_v2(name)
    /home/andriy/miniconda3/envs/patchy_discs_model/lib/python3.7/site-packages/tensorflow/python/framework/ops.py:6415 __init__
        raise ValueError("name for name_scope must be a string.")

    ValueError: name for name_scope must be a string.
drozzy commented 4 years ago

I think I figured it out. You forgot to remove two references to model in these two places: https://github.com/nvecoven/BRC/blob/master/MinimalWorkingExample.py#L26 https://github.com/nvecoven/BRC/blob/master/MinimalWorkingExample.py#L63

drozzy commented 4 years ago

Fix: https://github.com/nvecoven/BRC/pull/3

JRunner97 commented 4 years ago

I got a similar error when the 'model' variable is not defined and passed as the tf.keras.layers.Layer 'name' parameter. Removing the references works for me as well.

nvecoven commented 4 years ago

You are absolutely right, in fact the "var_list" argument should also have been removed. I have no idea why it still ran correctly on my side despite these issues. I uploaded a new version as well as for benchmark 2 and benchmark 3. This should be fixed.