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

68,518

Solution 1

try using import tensorflow.compat.v1 as tf

Solution 2

Which Tensorflow version, are you using? If it is TF2.0 then you need to replace tf.app.flags with tf.compat.v1.flags defined here since it is no longer supported.

Solution 3

use absl if you don't want to downgrade tf.

from absl import app

if __name__ == '__main__':
    
    app.run(main)
Share:
68,518
Dora89
Author by

Dora89

Updated on July 13, 2022

Comments

  • Dora89
    Dora89 almost 2 years

    I am following this tutorial and doing a project on custom object-detection using tensorflow.

    So when I tried to create TF record for the train images using the following command

    python3 generate_tfrecord.py --csv_input=data/train_labels.csv --output_path=data/train.record

    I get the following error:

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

    How can I resolve this error?

  • Dora89
    Dora89 over 4 years
    I am using TF 1.13.1
  • Dimitri
    Dimitri over 4 years
    I'm getting similar error with tf.app.run(), but changing to tf.compat.v1.run() didn't help.
  • Binx
    Binx over 3 years
    @Dimitri I had the same problem as you. Use @ThMore answer. Change import tensorflow as tf to import tensorflow.compat.v1 as tf. Don't change anything else (tf.app.flags and tf.app.run stays as is).
  • YoussefDir
    YoussefDir almost 3 years
    @Dimitri it's tf.compat.v1.app.run()