You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 29, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Dec 29, 2022. It is now read-only.
from tensorflow.contrib.distributions.python.ops import bernoulli ImportError: cannot import name 'bernoulli' #285
@robi56 thanks. Just in case others are having a problem here are the steps to correct the problem when running unit tests:
emacs seq2seq/contrib/seq2seq/helper.py
Replace the imports line for bernoulli and categorical at the top with robi56's answer
from tensorflow.contrib.distributions import Bernoulli
from tensorflow.contrib.distributions import Categorical
Run python -m unittest seq2seq.test.pipeline_test
Thanks
Reacted by lzt2015, twoflypig, Gobinath, Bruce Chou, Kevin, vinamagrawal, Amol Thakkar, Steve Kommrusch, cauivy and 刘诤
ImportError: Failed to import test module: seq2seq
Traceback (most recent call last):
File "/opt/anaconda2/envs/keras-tf-backend-gpu/lib/python3.5/unittest/loader.py", line 153, in loadTestsFromName
module = import(module_name)
File "/root/seq2seq_src/seq2seq/init.py", line 25, in
from seq2seq import data
File "/root/seq2seq_src/seq2seq/data/init.py", line 17, in
from seq2seq.data import input_pipeline
File "/root/seq2seq_src/seq2seq/data/input_pipeline.py", line 32, in
from tensorflow.contrib.slim.python.slim.data import tfexample_decoder
File "/opt/anaconda2/envs/keras-tf-backend-gpu/lib/python3.5/site-packages/tensorflow/contrib/init.py", line 56, in
from tensorflow.contrib import seq2seq
File "/opt/anaconda2/envs/keras-tf-backend-gpu/lib/python3.5/site-packages/tensorflow/contrib/seq2seq/init.py", line 27, in
from tensorflow.contrib.seq2seq.python.ops.basic_decoder import *
File "/opt/anaconda2/envs/keras-tf-backend-gpu/lib/python3.5/site-packages/tensorflow/contrib/seq2seq/python/ops/basic_decoder.py", line 25, in
from tensorflow.contrib.seq2seq.python.ops import helper as helper_py
File "/opt/anaconda2/envs/keras-tf-backend-gpu/lib/python3.5/site-packages/tensorflow/contrib/seq2seq/python/ops/helper.py", line 36, in
from tensorflow.python.ops.distributions import Bernoulli
ImportError: cannot import name 'Bernoulli'
python -m unittest seq2seq.test.pipeline_test
WARNING:tensorflow:From /home/nil/seq2seq/seq2seq/test/pipeline_test.py:57: get_or_create_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Please switch to tf.train.get_or_create_global_step
.E
ERROR: test_train_infer (seq2seq.test.pipeline_test.PipelineTest)
Tests training and inference scripts.
Traceback (most recent call last):
File "/home/nil/seq2seq/seq2seq/test/pipeline_test.py", line 76, in test_train_infer
_clear_flags()
File "/home/nil/seq2seq/seq2seq/test/pipeline_test.py", line 44, in _clear_flags
tf.app.flags.FLAGS = tf.app.flags._FlagValues()
AttributeError: module 'tensorflow.python.platform.flags' has no attribute '_FlagValues'
Same error exists.
Traceback (most recent call last):
File "/home/nil/seq2seq/seq2seq/test/pipeline_test.py", line 76, in test_train_infer
_clear_flags()
File "/home/nil/seq2seq/seq2seq/test/pipeline_test.py", line 44, in _clear_flags
tf.app.flags.FLAGS = tf.app.flags._FlagValues()
AttributeError: module 'tensorflow.python.platform.flags' has no attribute '_FlagValues'
I got a problem after i solved the bernoulli ImportError and the AttributeError mentioned above.
Then I used the command python -m unittest seq2seq.test.pipeline_test and i got a error below.
I followed the responses and I have changed the below files:
1. /seq2seq/seq2seq/contrib/seq2seq/helper.py => (to solve bernoulli and categorical problem)
2. /seq2seq/test/pipeline_test.py => (to solve: module 'tensorflow.python.platform.flags' has no attribute '_FlagValues' )
Also, I have changed the Tensorflow version to 1.15.2
But when I try to run: ! python -m unittest seq2seq.test.pipeline_test
I face the following error after a lot of warning about deprecated files:
E
======================================================================
ERROR: test_train_infer (seq2seq.test.pipeline_test.PipelineTest)
seq2seq.test.pipeline_test.PipelineTest.test_train_infer
Tests training and inference scripts.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/content/seq2seq/seq2seq/test/pipeline_test.py", line 150, in test_train_infer
train_script.main([])
File "/content/seq2seq/bin/train.py", line 272, in main
schedule=FLAGS.schedule)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/util/deprecation.py", line 324, in new_func
return func(*args, **kwargs)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/contrib/learn/python/learn/learn_runner.py", line 225, in run
return _execute_schedule(experiment, schedule)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/contrib/learn/python/learn/learn_runner.py", line 52, in _execute_schedule
return task()
File "/content/seq2seq/seq2seq/contrib/experiment.py", line 104, in continuous_train_and_eval
monitors=self._train_monitors)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/contrib/learn/python/learn/estimators/estimator.py", line 524, in fit
loss = self._train_model(input_fn=input_fn, hooks=hooks)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/contrib/learn/python/learn/estimators/estimator.py", line 1041, in _train_model
model_fn_ops = self._get_train_ops(features, labels)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/contrib/learn/python/learn/estimators/estimator.py", line 1265, in _get_train_ops
return self._call_model_fn(features, labels, model_fn_lib.ModeKeys.TRAIN)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/contrib/learn/python/learn/estimators/estimator.py", line 1228, in _call_model_fn
model_fn_results = self._model_fn(features, labels, **kwargs)
File "/content/seq2seq/bin/train.py", line 183, in model_fn
return model(features, labels, params)
File "/content/seq2seq/seq2seq/models/model_base.py", line 146, in __call__
return self._build(features, labels, params)
File "/content/seq2seq/seq2seq/models/seq2seq_model.py", line 297, in _build
encoder_output = self.encode(features, labels)
File "/content/seq2seq/seq2seq/graph_utils.py", line 38, in func_wrapper
return templated_func(*args, **kwargs)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/ops/template.py", line 393, in __call__
return self._call_func(args, kwargs)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/ops/template.py", line 355, in _call_func
result = self._func(*args, **kwargs)
File "/content/seq2seq/seq2seq/models/basic_seq2seq.py", line 109, in encode
return encoder_fn(source_embedded, features["source_len"])
File "/content/seq2seq/seq2seq/graph_module.py", line 57, in __call__
return self._template(*args, **kwargs)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/ops/template.py", line 385, in __call__
return self._call_func(args, kwargs)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/ops/template.py", line 355, in _call_func
result = self._func(*args, **kwargs)
File "/content/seq2seq/seq2seq/encoders/encoder.py", line 49, in _build
return self.encode(inputs, *args, **kwargs)
File "/content/seq2seq/seq2seq/encoders/rnn_encoder.py", line 135, in encode
cell_fw = training_utils.get_rnn_cell(**self.params["rnn_cell"])
File "/content/seq2seq/seq2seq/training/utils.py", line 157, in get_rnn_cell
cell = cell_from_spec(cell_class, cell_params)
File "/content/seq2seq/seq2seq/training/utils.py", line 123, in cell_from_spec
are: {}""".format(key, cell_class.__name__, cell_args))
ValueError: num_units is not a valid argument for GRUCell class. Available arguments
are: set()
originally defined at:
File "/content/seq2seq/seq2seq/models/basic_seq2seq.py", line 108, in encode
encoder_fn = self.encoder_class(self.params["encoder.params"], self.mode)
File "/content/seq2seq/seq2seq/encoders/rnn_encoder.py", line 119, in __init__
super(BidirectionalRNNEncoder, self).__init__(params, mode, name)
File "/content/seq2seq/seq2seq/encoders/encoder.py", line 45, in __init__
GraphModule.__init__(self, name)
File "/content/seq2seq/seq2seq/graph_module.py", line 44, in __init__
self._template = tf.make_template(name, self._build, create_scope_now_=True)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/ops/template.py", line 161, in make_template
**kwargs)
originally defined at:
File "/content/seq2seq/seq2seq/graph_utils.py", line 37, in func_wrapper
templated_func = tf.make_template(name_, func)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/ops/template.py", line 161, in make_template
**kwargs)
----------------------------------------------------------------------
Ran 2 tests in 0.189s
FAILED (errors=1, skipped=1)
I followed the responses and I have changed the below files:
1. /seq2seq/seq2seq/contrib/seq2seq/helper.py => (to solve bernoulli and categorical problem)
2. /seq2seq/test/pipeline_test.py => (to solve: module 'tensorflow.python.platform.flags' has no attribute '_FlagValues' )
Also, I have changed the Tensorflow version to 1.15.2
But when I try to run: ! python -m unittest seq2seq.test.pipeline_test
I face the following error after a lot of warning about deprecated files:
E
======================================================================
ERROR: test_train_infer (seq2seq.test.pipeline_test.PipelineTest)
seq2seq.test.pipeline_test.PipelineTest.test_train_infer
Tests training and inference scripts.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/content/seq2seq/seq2seq/test/pipeline_test.py", line 150, in test_train_infer
train_script.main([])
File "/content/seq2seq/bin/train.py", line 272, in main
schedule=FLAGS.schedule)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/util/deprecation.py", line 324, in new_func
return func(*args, **kwargs)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/contrib/learn/python/learn/learn_runner.py", line 225, in run
return _execute_schedule(experiment, schedule)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/contrib/learn/python/learn/learn_runner.py", line 52, in _execute_schedule
return task()
File "/content/seq2seq/seq2seq/contrib/experiment.py", line 104, in continuous_train_and_eval
monitors=self._train_monitors)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/contrib/learn/python/learn/estimators/estimator.py", line 524, in fit
loss = self._train_model(input_fn=input_fn, hooks=hooks)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/contrib/learn/python/learn/estimators/estimator.py", line 1041, in _train_model
model_fn_ops = self._get_train_ops(features, labels)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/contrib/learn/python/learn/estimators/estimator.py", line 1265, in _get_train_ops
return self._call_model_fn(features, labels, model_fn_lib.ModeKeys.TRAIN)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/contrib/learn/python/learn/estimators/estimator.py", line 1228, in _call_model_fn
model_fn_results = self._model_fn(features, labels, **kwargs)
File "/content/seq2seq/bin/train.py", line 183, in model_fn
return model(features, labels, params)
File "/content/seq2seq/seq2seq/models/model_base.py", line 146, in __call__
return self._build(features, labels, params)
File "/content/seq2seq/seq2seq/models/seq2seq_model.py", line 297, in _build
encoder_output = self.encode(features, labels)
File "/content/seq2seq/seq2seq/graph_utils.py", line 38, in func_wrapper
return templated_func(*args, **kwargs)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/ops/template.py", line 393, in __call__
return self._call_func(args, kwargs)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/ops/template.py", line 355, in _call_func
result = self._func(*args, **kwargs)
File "/content/seq2seq/seq2seq/models/basic_seq2seq.py", line 109, in encode
return encoder_fn(source_embedded, features["source_len"])
File "/content/seq2seq/seq2seq/graph_module.py", line 57, in __call__
return self._template(*args, **kwargs)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/ops/template.py", line 385, in __call__
return self._call_func(args, kwargs)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/ops/template.py", line 355, in _call_func
result = self._func(*args, **kwargs)
File "/content/seq2seq/seq2seq/encoders/encoder.py", line 49, in _build
return self.encode(inputs, *args, **kwargs)
File "/content/seq2seq/seq2seq/encoders/rnn_encoder.py", line 135, in encode
cell_fw = training_utils.get_rnn_cell(**self.params["rnn_cell"])
File "/content/seq2seq/seq2seq/training/utils.py", line 157, in get_rnn_cell
cell = cell_from_spec(cell_class, cell_params)
File "/content/seq2seq/seq2seq/training/utils.py", line 123, in cell_from_spec
are: {}""".format(key, cell_class.__name__, cell_args))
ValueError: num_units is not a valid argument for GRUCell class. Available arguments
are: set()
originally defined at:
File "/content/seq2seq/seq2seq/models/basic_seq2seq.py", line 108, in encode
encoder_fn = self.encoder_class(self.params["encoder.params"], self.mode)
File "/content/seq2seq/seq2seq/encoders/rnn_encoder.py", line 119, in __init__
super(BidirectionalRNNEncoder, self).__init__(params, mode, name)
File "/content/seq2seq/seq2seq/encoders/encoder.py", line 45, in __init__
GraphModule.__init__(self, name)
File "/content/seq2seq/seq2seq/graph_module.py", line 44, in __init__
self._template = tf.make_template(name, self._build, create_scope_now_=True)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/ops/template.py", line 161, in make_template
**kwargs)
originally defined at:
File "/content/seq2seq/seq2seq/graph_utils.py", line 37, in func_wrapper
templated_func = tf.make_template(name_, func)
File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/ops/template.py", line 161, in make_template
**kwargs)
----------------------------------------------------------------------
Ran 2 tests in 0.189s
FAILED (errors=1, skipped=1)
I face the same problem and has anyone solved this error?
ERROR: test_train_infer (seq2seq.test.pipeline_test.PipelineTest)
seq2seq.test.pipeline_test.PipelineTest.test_train_infer
Tests training and inference scripts.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/parthdt2/DL_models/atlas---deep-learning-assert-statements/seq2seq/seq2seq/test/pipeline_test.py", line 159, in test_train_infer
os.path.join(BIN_FOLDER, "infer.py"))
File "/usr/lib/python3.6/imp.py", line 172, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 684, in _load
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/parthdt2/DL_models/atlas---deep-learning-assert-statements/seq2seq/bin/infer.py", line 40, in <module>
parameters for inference""")
File "/home/parthdt2/.local/lib/python3.6/site-packages/tensorflow_core/python/platform/flags.py", line 58, in wrapper
return original_function(*args, **kwargs)
File "/home/parthdt2/.local/lib/python3.6/site-packages/absl/flags/_defines.py", line 294, in DEFINE_string
**args)
File "/home/parthdt2/.local/lib/python3.6/site-packages/absl/flags/_defines.py", line 106, in DEFINE
module_name, required)
File "/home/parthdt2/.local/lib/python3.6/site-packages/absl/flags/_defines.py", line 140, in DEFINE_flag
fv[flag.name] = flag
File "/home/parthdt2/.local/lib/python3.6/site-packages/absl/flags/_flagvalues.py", line 439, in __setitem__
raise _exceptions.DuplicateFlagError.from_flag(name, self)
absl.flags._exceptions.DuplicateFlagError: The flag 'model_params' is defined twice. First from seq2seq.test.train_bin, Second from seq2seq.test.infer_bin. Description from first occurrence: YAML configuration string for the model
parameters.
Also, my fix somehow doesn't make the test pass. The test runs, but the training stops as max steps are reached. I'm not sure if that's okay or suggests a deeper bug. INFO:tensorflow:Stop training model as max steps reached.
The final output has this:
Ran 2 tests in 17.685s
FAILED (errors=1, skipped=1)
Activity
robi56 commentedon Jul 30, 2017
Update by:
This will resolve your problem
enjector commentedon Jul 31, 2017
@robi56 thanks. Just in case others are having a problem here are the steps to correct the problem when running unit tests:
from tensorflow.contrib.distributions import Bernoulli
from tensorflow.contrib.distributions import Categorical
Thanks
ptresende commentedon Sep 13, 2017
In case the solutions above do not work for you, in my env, the following did work:
My output for
python -c "import tensorflow as tf; print(tf.VERSION, tf.GIT_VERSION, tf.__file__)"is:
1.2.1 v1.2.0-5-g435cdfc /usr/local/lib/python3.5/dist-packages/tensorflow/__init__.pyalishakiba commentedon Sep 22, 2017
Hi there,
I've made the aforementioned changes, however, it did not work for me.
I am using
centos-release-6-5.el6.centos.11.1.x86_64. The output foruname -ais
Linux p3.hpc.vru.ac.ir 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linuxpython -c "import tensorflow as tf; print(tf.VERSION, tf.GIT_VERSION, tf.__file__)"is
1.2.1 b'unknown' /opt/anaconda2/envs/keras-tf-backend-gpu/lib/python3.5/site-packages/tensorflow/__init__.pyThe error is
`
python -m unittest seq2seq.test.pipeline_test E
ERROR: seq2seq (unittest.loader._FailedTest)
ImportError: Failed to import test module: seq2seq
Traceback (most recent call last):
File "/opt/anaconda2/envs/keras-tf-backend-gpu/lib/python3.5/unittest/loader.py", line 153, in loadTestsFromName
module = import(module_name)
File "/root/seq2seq_src/seq2seq/init.py", line 25, in
from seq2seq import data
File "/root/seq2seq_src/seq2seq/data/init.py", line 17, in
from seq2seq.data import input_pipeline
File "/root/seq2seq_src/seq2seq/data/input_pipeline.py", line 32, in
from tensorflow.contrib.slim.python.slim.data import tfexample_decoder
File "/opt/anaconda2/envs/keras-tf-backend-gpu/lib/python3.5/site-packages/tensorflow/contrib/init.py", line 56, in
from tensorflow.contrib import seq2seq
File "/opt/anaconda2/envs/keras-tf-backend-gpu/lib/python3.5/site-packages/tensorflow/contrib/seq2seq/init.py", line 27, in
from tensorflow.contrib.seq2seq.python.ops.basic_decoder import *
File "/opt/anaconda2/envs/keras-tf-backend-gpu/lib/python3.5/site-packages/tensorflow/contrib/seq2seq/python/ops/basic_decoder.py", line 25, in
from tensorflow.contrib.seq2seq.python.ops import helper as helper_py
File "/opt/anaconda2/envs/keras-tf-backend-gpu/lib/python3.5/site-packages/tensorflow/contrib/seq2seq/python/ops/helper.py", line 36, in
from tensorflow.python.ops.distributions import Bernoulli
ImportError: cannot import name 'Bernoulli'
Ran 1 test in 0.000s
FAILED (errors=1)
`
update for tf v1.4.0, see google#285
Sammyreus commentedon Feb 26, 2018
new error after fixing the helper.py
python -m unittest seq2seq.test.pipeline_test
WARNING:tensorflow:From /home/nil/seq2seq/seq2seq/test/pipeline_test.py:57: get_or_create_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Please switch to tf.train.get_or_create_global_step
.E
ERROR: test_train_infer (seq2seq.test.pipeline_test.PipelineTest)
Tests training and inference scripts.
Traceback (most recent call last):
File "/home/nil/seq2seq/seq2seq/test/pipeline_test.py", line 76, in test_train_infer
_clear_flags()
File "/home/nil/seq2seq/seq2seq/test/pipeline_test.py", line 44, in _clear_flags
tf.app.flags.FLAGS = tf.app.flags._FlagValues()
AttributeError: module 'tensorflow.python.platform.flags' has no attribute '_FlagValues'
Ran 2 tests in 0.134s
Jaydaar commentedon Apr 11, 2018
i have this same issue and i am not sure how to fix it.
kritinemkul commentedon Apr 28, 2018
Same error exists.
Traceback (most recent call last):
File "/home/nil/seq2seq/seq2seq/test/pipeline_test.py", line 76, in test_train_infer
_clear_flags()
File "/home/nil/seq2seq/seq2seq/test/pipeline_test.py", line 44, in _clear_flags
tf.app.flags.FLAGS = tf.app.flags._FlagValues()
AttributeError: module 'tensorflow.python.platform.flags' has no attribute '_FlagValues'
tigerneil commentedon May 3, 2018
@kritinemkul for your problem, change the following code in
/home/ubuntu/seq2seq/seq2seq/test/pipeline_test.py:kritinemkul commentedon May 3, 2018
@tigerneil Thank you for the solution.
onlyjackfrost commentedon Jun 9, 2018
I got a problem after i solved the bernoulli ImportError and the AttributeError mentioned above.
Then I used the command
python -m unittest seq2seq.test.pipeline_testand i got a error below.I've check the path"C:\Users\user\AppData\Local\Temp" and there is no such file...
Btw im using Anaconda for python3.6 and tensorflow1.8 on window8.1
neerajks commentedon Jun 19, 2018
Hi any luck resolving the above error ? I am facing the same error on tensorflow 1.8.
fix issue: google#285
mosabrezaei commentedon Apr 10, 2021
Hi,
I followed the responses and I have changed the below files:
Also, I have changed the Tensorflow version to 1.15.2
But when I try to run:
! python -m unittest seq2seq.test.pipeline_testI face the following error after a lot of warning about deprecated files:
yuchensu1 commentedon Jun 9, 2021
I face the same problem and has anyone solved this error?
thakkarparth007 commentedon Feb 19, 2022
This particular problem can be solved by replacing the following line in
seq2seq.training.utils.py:cell_args = set(inspect.getargspec(cell_class.__init__).args[1:])(found in cell_from_spec) methodwith the following line:
cell_args = set(list(inspect.signature(cell_class.__init__).parameters)[1:])But of course there's a new error now:
Also, my fix somehow doesn't make the test pass. The test runs, but the training stops as max steps are reached. I'm not sure if that's okay or suggests a deeper bug.
INFO:tensorflow:Stop training model as max steps reached.The final output has this: