syntaxerrorSteve
syntaxerrorSteve

Reputation: 43

AttributeError: module 'tensorflow' has no attribute 'app': error

I am currently following this tutorial at section 4. When I run the command to generate the TF Records it returns a trace-back error for the generate_tfrecord.py file. The first error being for:

flags = tf.compat.v1.flags
flags.DEFINE_string('csv_input', '', 'Path to the CSV input')
flags.DEFINE_string('image_dir', '', 'Path to the image directory')
flags.DEFINE_string('output_path', '', 'Path to output TFRecord')
FLAGS = flags.FLAGS

I simply fixed it by adding the .compat.v1 line because I am using TF 2.0.

The next error I got was that last line with;

if __name__ == '__main__':
    tf.app.run()

It returned:

Traceback (most recent call last):
  File "generate_tfrecord.py", line 101, in <module>
    tf.app.run()
AttributeError: module 'tensorflow' has no attribute 'app'

Any help would greatly appreciated! -Cheers

Upvotes: 2

Views: 3970

Answers (2)

Alexandr  Haymin
Alexandr Haymin

Reputation: 117

Or you can simpy add import tensorflow.compat.v1 as tf tf.disable_v2_behavior() instead of import tensorflow as tf

Upvotes: 1

gogasca
gogasca

Reputation: 10058

In this TensorFlow 2 guide, https://www.tensorflow.org/guide/effective_tf2, it says tf.app is removed. To resolve, either uninstall TensorFlow 2.x and then install 1.x, or modify the code so that it uses 2.x API. You should be able to just call main method instead of tf.app.run().

Reference: https://github.com/tensorflow/tensorflow/issues/34431

Upvotes: 1

Related Questions