[SOLVED] TensorFlow: AttributeError: module ‘tensorflow’ has no attribute ‘read_file’

1. The problem

The tf.read_file function has no been support longer and when you execute the code like below:

import tensorflow as tf

img_raw = tf.read_file(img_path)
print(repr(img_raw)[:100]+"…")

You get the following exception:

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

2. The solution

The function has been move into tensorflow.io module. You should change your code like it was done below:

import tensorflow as tf

img_raw = tf.io.read_file(img_path)
print(repr(img_raw)[:100]+"…")
At the end… May I ask you for something?

If I helped you solve your problem, please share this post. Thanks to this, I will have the opportunity to reach a wider group of readers. Thank You

5 2 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
oldest
newest most voted
Inline Feedbacks
View all comments
Nitish
Nitish
1 year ago

opener = urllib.request.URLopener()
opener.retrieve(DOWNLOAD_BASE + MODEL_FILE, MODEL_FILE)
tar_file = tarfile.open(MODEL_FILE)
for file in tar_file.getmembers():
file_name = os.path.basename(file.name)
if ‘frozen_inference_graph.pb’ in file_name:
tar_file.extract(file, os.getcwd())
detection_graph = tf.Graph()
with detection_graph.as_default():
od_graph_def = tf.GraphDef()
with tf.gfile.GFile(PATH_TO_CKPT, ‘rb’) as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name=”)

Got the following error:
AttributeError: module ‘tensorflow’ has no attribute ‘GraphDef’

Please help