Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ElHo1 opened this issue May 17, 2019 · 6 comments

Comments

@ElHo1
Copy link

ElHo1 commented May 17, 2019

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?

@MAkC8
Copy link

MAkC8 commented Jul 1, 2019

use this :

tf.compat.v1.python_io

@aledalgrande
Copy link

Or now that TF2 is out:

tf.io.TFRecordWriter

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

@BookPlus2020
Copy link

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

@chuasonglin
Copy link

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

@jp3spinelli
Copy link

@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

@amagzari
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants