models icon indicating copy to clipboard operation
models copied to clipboard

Object_detection example error

Open bryancresswell opened this issue 9 years ago • 12 comments

I am in the midst of doing the example on object_detection at https://github.com/tensorflow/models/blob/master/object_detection/g3doc/running_pets.md, and when i run the script for create_pet_tf_record.py, i get this error.

python3 create_pet_tf_record.py     --label_map_path=data/pet_label_map.pbtxt     --data_dir=`pwd`     --output_dir=`pwd`
/home/cressy/Desktop/Code/models/object_detection/utils/dataset_util.py:75: FutureWarning: The behavior of this method will change in future versions. Use specific 'len(elem)' or 'elem is not None' test instead.
  if not xml:
Traceback (most recent call last):
  File "create_pet_tf_record.py", line 211, in <module>
    tf.app.run()
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "create_pet_tf_record.py", line 206, in main
    image_dir, train_examples)
  File "create_pet_tf_record.py", line 175, in create_tf_record
    tf_example = dict_to_tf_example(data, label_map_dict, image_dir)
  File "create_pet_tf_record.py", line 90, in dict_to_tf_example
    encoded_jpg = fid.read()
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/lib/io/file_io.py", line 125, in read
    pywrap_tensorflow.ReadFromStream(self._read_buf, length, status))
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/lib/io/file_io.py", line 93, in _prepare_value
    return compat.as_str_any(val)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/util/compat.py", line 106, in as_str_any
    return as_str(value)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/util/compat.py", line 84, in as_text
    return bytes_or_text.decode(encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

bryancresswell avatar Jun 17 '17 21:06 bryancresswell

I ran into this same problem. It appears the object detection library was written in python 2.7, and there are several compatibility issues if you try to run it with python 3. Looks like the last commit fixed a compatibility issues, so this may be something they address soon. for you specific problem .encode() the string will fix it.

danzelmo avatar Jun 19 '17 02:06 danzelmo

I have the same problem. How can i fix it?

peciato avatar Jun 19 '17 10:06 peciato

You can either install tensorflow in a 2.7 environment, or wait for an compatibility update. It looks like there are pull requests already being submitted addressing the issues.

danzelmo avatar Jun 19 '17 15:06 danzelmo

Does this PR address the python3 issues in running the pets script? https://github.com/tensorflow/models/pull/1614

derekjchow avatar Jun 19 '17 18:06 derekjchow

Yes, I had this problem as well. Python string encoding is different in Python 2.7 vs 3.6 and it break Tensorflow.

c0nn3r avatar Jun 19 '17 18:06 c0nn3r

@bryancresswell @danzelmo @peciato @c0nn3r Can one of you try PR #1614 that @derekjchow mentioned, to see whether it fixes the issue for you? Thanks!

tatatodd avatar Jun 20 '17 02:06 tatatodd

@tatatodd PR #1614 generates the two pet training files for in both python 3.5 and 2.7. I have not run the full example with files from both versions of python. the file sizes for are slightly different(a few kb) for 3.5 and 2.7 this may not be important though.

danzelmo avatar Jun 20 '17 02:06 danzelmo

Has this issue been addressed?

CarltonSemple avatar Sep 18 '17 20:09 CarltonSemple

i am having this same problem any advances?

hcloud00 avatar Oct 10 '17 20:10 hcloud00

Same problem here. Did anyone find a solution?

Smokrow avatar Nov 23 '17 08:11 Smokrow

.encode()

I ran into this same problem. It appears the object detection library was written in python 2.7, and there are several compatibility issues if you try to run it with python 3. Looks like the last commit fixed a compatibility issues, so this may be something they address soon. for you specific problem .encode() the string will fix it.

Hi, where i use encode() ?

LyonOconner avatar Nov 01 '18 15:11 LyonOconner

Hi There, We are checking to see if you still need help on this, as this seems to be considerably old issue. Please update this issue with the latest information, code snippet to reproduce your issue and error you are seeing. If we don't hear from you in the next 7 days, this issue will be closed automatically. If you don't need help on this issue any more, please consider closing this.

tensorflowbutler avatar Jan 29 '20 23:01 tensorflowbutler