Models: lm_1b AttributeError: 'str' object has no attribute 'decode'

Created on 16 Apr 2018  路  3Comments  路  Source: tensorflow/models

Hi!

Tensorflow Version = 1.4.0
Using Anaconda Python 3.6.3

Describe the problem

Trying to run sample mode using Tensorflow lm_1b, when I type

bazel-bin/lm_1b/lm_1b_eval --mode sample --prefix "I love that I" --pbtxt .\data\vocab -2016-09-10.txt --vocab_file .\data\vocab-2016-09-10.txt --ckpt 'data/ckpt-*'

The following comes out:

Recovering graph. Traceback (most recent call last): File "\\?\C:\Users\snmsa\AppData\Local\Temp\Bazel.runfiles_89njezvs\runfiles\__main__\lm_1b\lm_1b_eval.py", line 308, in <module> tf.app.run() File "C:\Users\snmsa\Anaconda3\lib\site-packages\tensorflow\python\platform\app.py", line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "\\?\C:\Users\snmsa\AppData\Local\Temp\Bazel.runfiles_89njezvs\runfiles\__main__\lm_1b\lm_1b_eval.py", line 298, in main _SampleModel(FLAGS.prefix, vocab) File "\\?\C:\Users\snmsa\AppData\Local\Temp\Bazel.runfiles_89njezvs\runfiles\__main__\lm_1b\lm_1b_eval.py", line 174, in _SampleModel sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt) File "\\?\C:\Users\snmsa\AppData\Local\Temp\Bazel.runfiles_89njezvs\runfiles\__main__\lm_1b\lm_1b_eval.py", line 87, in _LoadModel s = f.read().decode() AttributeError: 'str' object has no attribute 'decode'

Any help figuring out how to fix this error would be really appreciated

help wanted

All 3 comments

Seems likely to be a Python 2/3 compatibility error. Assigning to @OriolVinyals , but this would also be a good starter PR if you would like to contribute. See http://python-future.org/compatible_idioms.html for some possible solutions you could try.

@OriolVinyals
Completely right, I will close the issue now. Thank you!

Modify lm_1b_eval.py line 84:
with tf.gfile.FastGFile(gd_file, 'r') as f: to with tf.gfile.FastGFile(gd_file, 'rb') as f: (r to rb)
and then use bazel build again. It works for me. (I use python 3.x)

Was this page helpful?
0 / 5 - 0 ratings