What to do if you get angry in TensorFlow v2 without attribute'app'

0. Overview

Here is a summary of the solutions when the following Error statement appears when executing the sample code of TensorFlow v2. (We will not backdate to TensorFlow v1.)

1. Background

To study TensorFlow, I downloaded the sample code (classify_image.py) from the following URL. https://github.com/atong01/Imagenet-Tensorflow/blob/master/classify_image.py

2. Environment

OS:Windows10 Enterprise 1809 64bit Python:3.7.6 TensorFlow_gpu:v2.1.0

3. Trouble

Since it is a sample code, I thought that it could be executed without any problem, but for some reason the following Error appears.

Error statement


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

Why isn't it?

So, when I looked it up "In TensorFlow v2, tf.app has already been deleted, so "Backdate to TensorFlow v1" "Rewrite code for TensorFlow v2 API" Please respond with either of them. "

I don't know. I didn't want to mess with the environment from now on because I had a lot of trouble building the environment.

4. Solution

After further investigation, I found information that the problem could be solved by writing the following import statement in the code.

Solution


import tensorflow.compat.v1 as tf

In fact, when I added it to the sample code and executed it, it worked without problems. It was good!

Reference URL https://stackoverflow.com/questions/58258003/attributeerror-module-tensorflow-has-no-attribute-app

Recommended Posts

What to do if you get angry in TensorFlow v2 without attribute'app'
What to do if you get a minus zero in Python
What to do if you get lost in file reference with FileNotFoundError
What to do if you get angry with'vertices' must be a 2D list ... in matplotlib arrow
What to do if you get a "No versions found" error in pipenv
What to do if you get angry with swapon failed: Operation not permitted
What to do if you get "Python not configured." Using PyDev in Eclipse
What to do if you get angry with "Value Error: unknown local: UTF-8" in python manage.py syncdb
What to do if you can't log in as root
What to do if you get `No kernel for language python found` in Hydrogen
What to do if you get an error when importing matplotlib in Python (Mac)
What to do if you get a UnicodeDecodeError with pip install
What to do if you can't use the trash in Lubuntu 18.04.
What to do if you get Swagger-codegen in python and Import Error: No module named
What to do if you get a Cannot retrieve metalink for repository error in yum
What to do if you get an error when running "certbot renew" in CakePHP environment
What to do if pipreqs results in UnicodeDecodeError
What to do if you can't find PDO in Laravel or CakePHP
What to do if you can't pipenv shell
What to do if you can't use scikit grid search in Python
What to do if you get stuck during Anaconda installation on Linux
What to do if you get an error saying c compiler cannot create executables in configure
If you want to get multiple statistics with groupby in pandas v1
What to do if you get a TypeError with numpy min, max
What to do if you get an error when trying to load mnist
What to do if you can't install with pip in babun environment
What to do if you get a must override `get_config` error when trying to model.save in Keras
What to do if you get Could not fetch URL 443 with pip
What to do to get google spreadsheet in python
What to do if you get angry if you don't have libxml / xmlversion.h when installing lxml on CentOS
What to do if you get an error when installing Dlib (Ubuntu)
What to do if you get angry with "Gtk * backend requires pygtke to be installed" even though pygtk is included in matplotlib
[Python] What to do if you get a ModuleNotFoundError when importing pandas using Jupyter Notebook in Anaconda
What to do if an error occurs in TensorFlow RNN related import or RNN (LSTM) Cell (v 0.11r ~)
What to do if you get an error when installing python with pyenv
What to do if pip install fails in Xcode 5.1
What to do if you can't pip install mysqlclient
ModuleNotFoundError: No module What to do if you get'tensorflow.contrib'
What to do if a UnicodeDecodeError occurs in pip
What to do if you get an error when trying to send a message in tasks.loop () immediately after startup
What to do if you get an OpenSSL error when installing Python 2 with pyenv
What to do if you get a memory error when converting from PySparkDataFrame to PandasDataFrame
What to do if Sort imports get stuck in VS Code's Python Extension (around 2020/09)
What to do if you get an Import Error when importing matplotlib with Jupyter
What to do if you get the error ʻERR_FEATURE_UNAVAILABLE_ON_PLATFORM` when using ts-node-dev on Linux
What to do if you can't hit the arrow keys in the Python interactive console
What to do if you run python in IntelliJ and end with an error
What to do if ʻarguments [0] .scrollIntoView ();` fails in python selenium
What to do if you are addicted to Windows character code
What to do if you can't sort files with subscripts
What to do if a 0xC0000005 error occurs in tf.train.start_queue_runners ()
What to do if you can't use WiFi on Linux
What to do if you lose your EC2 key pair
What to do if you get a Call with too many input arguments error at DoAndReturn in a golang test
What to do if yum breaks
What to do to get tensorflow-gpu to work
What to do if you get an Undefined error:'Module_six_moves_urllib_parse' object has no attribute'urlencode' on MacOS
What to do if you get an Undefined error when trying to use pip with pyenv
What to do if you can't install pyaudio with pip #Python
What to do if intellisense doesn't work with Anaconda + VSCode + Tensorflow2.1
What to do if "Unnamed: 0" is added in to_csv-> read_csv in pandas