raccoon_dataset icon indicating copy to clipboard operation
raccoon_dataset copied to clipboard

How to use tf.python_io.TFRecordWriter in Tensorflow 2.0 (generate_tfrecord.py)

Open ElHo1 opened this issue 5 years ago • 6 comments

I get this error: File "generate_tfrecord.py", line 102, in main() File "generate_tfrecord.py", line 89, in main writer = tf.python_io.TFRecordWriter(FLAGS.output_path) AttributeError: module 'tensorflow' has no attribute 'python_io'

What do i have to use instead?

ElHo1 avatar May 17 '19 06:05 ElHo1

use this :

tf.compat.v1.python_io

MAkC8 avatar Jul 01 '19 08:07 MAkC8

Or now that TF2 is out:

tf.io.TFRecordWriter

https://www.tensorflow.org/api_docs/python/tf/io/TFRecordWriter

aledalgrande avatar Oct 17 '19 04:10 aledalgrande

use tf.compat.v1.python_io.TFRecordWriter instead of tf.python_io.TFRecordWriter tf.compat.v1.app.run() instead of tf.app.run() tf.compat.v1.app.flags instead of tf.app.flags

BookPlus2020 avatar Dec 12 '19 13:12 BookPlus2020

We need to make sure the py script follows the format for tf2: Brushing up @BookPlus2020 answer:

Open the generate_tfrecord.py file and make these changes:

  1. use tf.compat.v1.python_io.TFRecordWriter instead of tf.python_io.TFRecordWriter
  2. tf.compat.v1.app.run() instead of tf.app.run()
  3. tf.compat.v1.app.flags instead of tf.app.flags
  4. tf.gfile.GFile to tf.io.gfile.GFile

chuasonglin avatar Jun 21 '20 03:06 chuasonglin

@chuasonglin I followed your revisions and keep getting this error: $ python3 generate_tfrecord.py --csv_input=data/Train_labels.csv --output_path=data/train.record --image_dir=Camera pictures/Train/ Traceback (most recent call last): File "generate_tfrecord.py", line 99, in tf.compat.v1.app.run() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/platform/app.py", line 40, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/absl/app.py", line 299, in run _run_main(main, args) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/absl/app.py", line 250, in _run_main sys.exit(main(argv)) File "generate_tfrecord.py", line 90, in main tf_example = create_tf_example(group, path) File "generate_tfrecord.py", line 45, in create_tf_example encoded_jpg = fid.read() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/lib/io/file_io.py", line 116, in read self._preread_check() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/lib/io/file_io.py", line 78, in _preread_check self._read_buf = _pywrap_file_io.BufferedInputStream( tensorflow.python.framework.errors_impl.NotFoundError: Camera/Camera-mount-and-Raspberry-Pi.png; No such file or directory

jp3spinelli avatar Jul 10 '20 18:07 jp3spinelli

tf.compat.v1.app.run() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/platform/app.py", line 40, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/absl/app.py", line 299, in run _run_main(main, args) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/absl/app.py", line 250, in _run_main sys.exit(main(argv)) File "generate_tfrecord.py", line 90, in main tf_example = create_tf_example(group, path) File "generate_tfrecord.py", line 45, in create_tf_example encoded_jpg = fid.read() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/lib/io/file_io.py", line 116, in read self._preread_check() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/lib/io/file_io.py", line 78, in _preread_check self._read_buf = _pywrap_file_io.BufferedInputStream( tensorflow.python.framework.errors_impl.NotFoundError: Camera/Camera-mount-and-Raspberry-Pi.png; No such file or directory

@chuasonglin I followed your revisions and keep getting this error: $ python3 generate_tfrecord.py --csv_input=data/Train_labels.csv --output_path=data/train.record --image_dir=Camera pictures/Train/ Traceback (most recent call last): File "generate_tfrecord.py", line 99, in tf.compat.v1.app.run() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/platform/app.py", line 40, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/absl/app.py", line 299, in run _run_main(main, args) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/absl/app.py", line 250, in _run_main sys.exit(main(argv)) File "generate_tfrecord.py", line 90, in main tf_example = create_tf_example(group, path) File "generate_tfrecord.py", line 45, in create_tf_example encoded_jpg = fid.read() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/lib/io/file_io.py", line 116, in read self._preread_check() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tensorflow/python/lib/io/file_io.py", line 78, in _preread_check self._read_buf = _pywrap_file_io.BufferedInputStream( tensorflow.python.framework.errors_impl.NotFoundError: Camera/Camera-mount-and-Raspberry-Pi.png; No such file or directory

fixed the set of errors?

amagzari avatar Oct 19 '20 00:10 amagzari