tensorflow: keras model to estimator in eager mode gives ValueError

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): no
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): OSX 10.13.4
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): 1.9.0-rc1
  • Python version: 3.6
  • Bazel version (if compiling from source): N/A
  • GCC/Compiler version (if compiling from source): N/A
  • CUDA/cuDNN version: N/A
  • GPU model and memory: N/A
  • Exact command to reproduce: N/A

Describe the problem

After enabling eager mode with tf.enable_eager_execution() if I convert my tf.keras.Model to an estimator via: tf.keras.estimator.model_to_estimator(model) I get:

INFO:tensorflow:Using the Keras model provided.
INFO:tensorflow:Using default config.
WARNING:tensorflow:Using temporary folder as model directory: /var/folders/yg/t3pf0vds6c14zlhmq1jwwvtnsz8fsr/T/tmp197t8ju4
INFO:tensorflow:Using config: {'_model_dir': '/var/folders/yg/t3pf0vds6c14zlhmq1jwwvtnsz8fsr/T/tmp197t8ju4', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': None, '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_device_fn': None, '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x1227bcdd8>, '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1}
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-6cc0c716ca8a> in <module>()
----> 1 estimator = tf.keras.estimator.model_to_estimator(model)

/usr/local/lib/python3.6/site-packages/tensorflow/python/estimator/keras.py in model_to_estimator(keras_model, keras_model_path, custom_objects, model_dir, config)
    512 
    513   # Check if we need to call get_weights:
--> 514   if _any_variable_initialized():
    515     keras_weights = keras_model.get_weights()
    516     # Warn if config passed to estimator tries to update GPUOptions. If a

/usr/local/lib/python3.6/site-packages/tensorflow/python/estimator/keras.py in _any_variable_initialized()
     77     boolean, True if at least one variable has been initialized, else False.
     78   """
---> 79   variables = variables_module.global_variables()
     80   for v in variables:
     81     if getattr(v, '_keras_initialized', False):

/usr/local/lib/python3.6/site-packages/tensorflow/python/ops/variables.py in global_variables(scope)
   1442     A list of `Variable` objects.
   1443   """
-> 1444   return ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES, scope)
   1445 
   1446 

/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py in get_collection(key, scope)
   5905   @end_compatibility
   5906   """
-> 5907   return get_default_graph().get_collection(key, scope)
   5908 
   5909 

/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py in get_collection(self, name, scope)
   3961       collected.
   3962     """  # pylint: disable=g-doc-exception
-> 3963     _assert_collection_is_ok(name)
   3964     with self._lock:
   3965       collection = self._collections.get(name, None)

/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/ops.py in _assert_collection_is_ok(collection_name)
   6146     if collection_name in GraphKeys._VARIABLE_COLLECTIONS:  # pylint: disable=protected-access
   6147       raise ValueError(
-> 6148           "variable collections are not supported when eager execution is enabled."
   6149       )
   6150 

ValueError: variable collections are not supported when eager execution is enabled.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (15 by maintainers)

Most upvoted comments

code shipped. Should be merged soon.