Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility of build_graph function with tensorflow 2.0 #37

Open
mattdornfeld opened this issue Jul 24, 2020 · 1 comment
Open

Incompatibility of build_graph function with tensorflow 2.0 #37

mattdornfeld opened this issue Jul 24, 2020 · 1 comment

Comments

@mattdornfeld
Copy link

I'm running the below example in tf 2.0 and I get an error AttributeError: module 'tensorflow_core._api.v2.train' has no attribute 'export_meta_graph'. It seems the build_graph function is incompatible with the tf 2.0 API. The example works fine with tf 1.15.

In [2]: import tensorflow as tf
   ...: from tensorflow import keras
   ...: from tensorflow.keras import layers
   ...: from sparkflow.graph_utils import build_graph
   ...:
   ...: tf.compat.v1.disable_eager_execution()
   ...:
   ...: output_dim = 64
   ...: model = keras.Sequential()
   ...: model.add(layers.Dense(output_dim, kernel_initializer='uniform', input_shape=(10,)))
   ...: model.add(layers.Activation('softmax'))
   ...:
   ...: loss_fn = keras.losses.SparseCategoricalCrossentropy()
   ...: model.compile(loss=loss_fn, optimizer='adam')
   ...:
   ...: y_true = tf.compat.v1.placeholder(dtype=tf.float32, shape=(None, output_dim))
   ...: loss = model.loss.fn(y_true, model.output)
   ...: mg = build_graph(lambda : loss)
   ...:
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-33c7a76593c9> in <module>
     16 y_true = tf.compat.v1.placeholder(dtype=tf.float32, shape=(None, output_dim))
     17 loss = model.loss.fn(y_true, model.output)
---> 18 mg = build_graph(lambda : loss)

/usr/local/lib/python3.7/site-packages/sparkflow/graph_utils.py in build_graph(func)
     12     with first_graph.as_default() as g:
     13         v = func()
---> 14         mg = json_format.MessageToJson(tf.train.export_meta_graph())
     15     return mg
     16

AttributeError: module 'tensorflow_core._api.v2.train' has no attribute 'export_meta_graph'
@M0315G
Copy link

M0315G commented Jun 16, 2021

Yes I experienced the same issue when training my CNN classifier. The reason behind it is that from TF 2.x, Tensorflow supports eager version and does not depend on the DAGs heavily to run a session. The only solution I could find is to downgrade to TF 1.x and use the API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@mattdornfeld @M0315G and others