models icon indicating copy to clipboard operation
models copied to clipboard

Error running lm_1b model on python3.

Open napsternxg opened this issue 9 years ago • 15 comments

Please let us know which model this issue is about (specify the top-level directory)

Using model lm_1b

When I run with python3 I get the following errors:

$ python lm_1b/lm_1b_eval.py --mode sample --prefix "I love that I" --pbtxt data/graph-2016-09-10.pbtxt --vocab_file data/vocab-2016-09-10.txt  --ckpt 'data/ckpt-*'
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so locally
Recovering graph.
Traceback (most recent call last):
  File "/home/napsternxg/Codes/tensorflow_models/bazel-bin/lm_1b/lm_1b_eval.runfiles/__main__/lm_1b/lm_1b_eval.py", line 307, in <module>
    tf.app.run()
  File "/home/napsternxg/anaconda3/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 43, in run
    sys.exit(main(sys.argv[:1] + flags_passthrough))
  File "/home/napsternxg/Codes/tensorflow_models/bazel-bin/lm_1b/lm_1b_eval.runfiles/__main__/lm_1b/lm_1b_eval.py", line 297, in main
    _SampleModel(FLAGS.prefix, vocab)
  File "/home/napsternxg/Codes/tensorflow_models/bazel-bin/lm_1b/lm_1b_eval.runfiles/__main__/lm_1b/lm_1b_eval.py", line 173, in _SampleModel
    sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt)
  File "/home/napsternxg/Codes/tensorflow_models/bazel-bin/lm_1b/lm_1b_eval.runfiles/__main__/lm_1b/lm_1b_eval.py", line 88, in _LoadModel
    text_format.Merge(s, gd)
  File "/home/napsternxg/anaconda3/lib/python3.5/site-packages/google/protobuf/text_format.py", line 472, in Merge
    text.split('\n'),
TypeError: a bytes-like object is required, not 'str'

I have also tried running the same using the bazel commands as mentioned in the model README, and I get the same error. Then after referring to #583 I tried using python3 but am still getting the same error.

Here are some additional details:

Python version: 3.5.2 |Anaconda custom (64-bit)| (default, Jul  2 2016, 17:53:06) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
Tensorflow version: 0.12.1

napsternxg avatar Feb 05 '17 16:02 napsternxg

Can you try this will more recent TensorFlow? I'm curious if it's fixed at 1.0 or HEAD.

girving avatar Feb 06 '17 22:02 girving

Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks!

aselle avatar Mar 03 '17 23:03 aselle

I'm using tensorflow 1.0 on python 3.5 and I have the same issues.

$ bazel-bin/lm_1b/lm_1b_eval --mode sample
--prefix "I love that I"
--pbtxt data/graph-2016-09-10.pbtxt
--vocab_file data/vocab-2016-09-10.txt
--ckpt 'data/ckpt-*' I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.7.5 locally I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.4 locally I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.7.5 locally I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.7.5 locally Recovering graph. Traceback (most recent call last): File "/home/hqy/Code/models/bazel-bin/lm_1b/lm_1b_eval.runfiles/main/lm_1b/lm_1b_eval.py", line 307, in tf.app.run() File "/home/hqy/.local/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 44, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "/home/hqy/Code/models/bazel-bin/lm_1b/lm_1b_eval.runfiles/main/lm_1b/lm_1b_eval.py", line 297, in main _SampleModel(FLAGS.prefix, vocab) File "/home/hqy/Code/models/bazel-bin/lm_1b/lm_1b_eval.runfiles/main/lm_1b/lm_1b_eval.py", line 173, in _SampleModel sess, t = _LoadModel(FLAGS.pbtxt, FLAGS.ckpt) File "/home/hqy/Code/models/bazel-bin/lm_1b/lm_1b_eval.runfiles/main/lm_1b/lm_1b_eval.py", line 88, in _LoadModel text_format.Merge(s, gd) File "/home/hqy/.local/lib/python3.5/site-packages/google/protobuf/text_format.py", line 472, in Merge text.split('\n'), TypeError: a bytes-like object is required, not 'str'

please consider reopen this issue @aselle

qinyao-he avatar Mar 07 '17 07:03 qinyao-he

I ran into the exact same error. I patched it up adding a simple type check in text_format.py, then ran into some python2to3 issues: lm_1b_eval.py uses xrange, should be range for python3

maartensap avatar Apr 04 '17 19:04 maartensap

I had the same error. I am working with Python 3.5 and Tensorflow '0.12.1' I replaced s = f.read() at line 86 in lm_1b_eval.py by s = f.read().decode() Then I replaced the xrange occurences at line 180 and 272 in lm_1b_eval.py by range Now it works like a charm !

edouardfouche avatar Apr 28 '17 06:04 edouardfouche

Would you be up for submitting a pull request?

girving avatar Apr 28 '17 14:04 girving

Sure, this is done :)

edouardfouche avatar Apr 28 '17 17:04 edouardfouche

Ihad the same error, I run the example of object detection example with Python 3.5 and Tensorflow '1.1'

python create_pascal_tf_record.py --data_dir=/home/user/object_detection_test/VOCdevkit --year=VOC2012 --set=train --output_path=pascal_train.record I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally Traceback (most recent call last): File "create_pascal_tf_record.py", line 183, in tf.app.run() File "/root/anaconda3/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 44, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File "create_pascal_tf_record.py", line 158, in main label_map_dict = label_map_util.get_label_map_dict(FLAGS.label_map_path) File "/home/user/models/object_detection/utils/label_map_util.py", line 122, in get_label_map_dict label_map = load_labelmap(label_map_path) File "/home/user/models/object_detection/utils/label_map_util.py", line 107, in load_labelmap text_format.Merge(label_map_string, label_map) File "/root/anaconda3/lib/python3.5/site-packages/google/protobuf/text_format.py", line 472, in Merge text.split('\n'), TypeError: a bytes-like object is required, not 'str'

chencjiajy avatar Jun 28 '17 03:06 chencjiajy

Does it work if you change label_map_string = fid.read() at line 104 in label_map_util.py to label_map_string = fid.read().decode() ?

edouardfouche avatar Jun 28 '17 04:06 edouardfouche

It works! thank you!

chencjiajy avatar Jun 28 '17 07:06 chencjiajy

adding .decode() is the trick. Thanks @edouardfouche

hangzh-msft avatar Jul 07 '17 00:07 hangzh-msft

Adding .decode() works if you are using TF 1.0. No need for this if you are running TF 1.2.x.

hangzh-msft avatar Jul 07 '17 00:07 hangzh-msft

I tried to run the object model detection and I run into the same issue. tried changing label_map_string = fid.read().decode(), but still no luck. Note: The line number is not 104 for me, but I made the change in "load_labelmap(path)" method in label_map_util.py

Am using python 3.6, Tensor flow - version 1.0.0, and running on OSX. am running via Anaconda 1.6.3.

mageshr2016 avatar Sep 19 '17 20:09 mageshr2016

so anyone could salve the problem?

Roc-J avatar Jul 25 '18 03:07 Roc-J

i solve with label_map_string = bytearray(fid.read(), 'utf-8') on line 132

Daxel90 avatar Sep 17 '18 16:09 Daxel90