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

Using tensorflow 2.X fails with "module 'tensorflow' has no attribute 'Session'" #1

Open
xivarri opened this issue Jan 16, 2021 · 2 comments

Comments

@xivarri
Copy link
Contributor

xivarri commented Jan 16, 2021

Thanks for making this!
Unfortunately I can't seem to get the install down - I have to use tensorflow2.X because python3.8 doesn't support 1.X, and for some reason I cannot get a 3.6 or 3.7 virtualenv to work - and while the install seems to work, when trying to instantiate a StressRNN, I get:

<ipython-input-4-f44bb10095c3> in <module>
----> 1 stress_rnn = StressRNN()

~/gits/StressRNN/stressrnn/stressrnn.py in __init__(self, f_name_add_exception_dict)
     64         self.graph = tf.Graph()
     65         with self.graph.as_default():
---> 66             self.session = tf.Session(graph=self.graph)
     67             with self.session.as_default():
     68                 self.model = tf.keras.models.model_from_json(model_json)

AttributeError: module 'tensorflow' has no attribute 'Session'

The internet seems to suggest running

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

But doing that in an interpreter at least before importing StressRNN doesn't seem to work.
Is there any workaround?
Thanks

@xivarri
Copy link
Contributor Author

xivarri commented Jan 16, 2021

An update - I got it to work by replacing the line

import tensorflow as tf

by

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

in both stressrnn.py and model.py before installing. So if there's no better workaround, would be good to add that to the install instructions.

@dbklim
Copy link
Owner

dbklim commented Apr 5, 2021

When using TensorFlow v2.X, the speed of the project is greatly reduced, several times.

But now I have made a small update and added support for TensorFlow v2.X "out of the box". Although, at the moment it is better to use the project with ONNX Runtime, it works faster.

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

2 participants