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.)
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
OS:Windows10 Enterprise 1809 64bit Python:3.7.6 TensorFlow_gpu:v2.1.0
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.
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