Hallo,
komme wieder mal nicht weiter.
Das erste Beispiel von dieser Seite:
https://github.com/opencv/opencv/…t-Detection-API
macht Fehler wie unten beschrieben.
Raspberry Pi4B 4-Giga
SD-32Giga mit Buster
Linux raspberrypi 4.19.118-v7l+ #1311 SMP Mon Apr 27 14:26:42 BST 2020 armv7l GNU/Linux
General configuration for OpenCV 4.3.0 =====================================
Platform:
Timestamp: 2020-05-21T20:01:07Z
Host: Linux 4.19.97-v7l+ armv7l
CMake: 3.13.4
TensorFlow version: 2.2.0
Fehler (erstes) Beispiel
Zeile 6:
pi@raspberrypi:~/1AA1_TF_Obj_Detc_API_Uebung $ python3 example_tf.py
Traceback (most recent call last):
File "example_tf.py", line 6, in <module>
with tf.gfile.FastGFile('frozen_inference_graph.pb','rb') as f:
AttributeError: module 'tensorflow' has no attribute 'gfile'
Habe dann noch in Zeile 6 geändert wie beschrieben, leider geht auch nicht!
Fehler Zeile 6 geändert tf.io.gfile
pi@raspberrypi:~/1AA1_TF_Obj_Detc_API_Uebung $ python3 example_tf.py
Traceback (most recent call last):
File "example_tf.py", line 6, in <module>
with tf.io.gfile.FastGFile('frozen_inference_graph.pb','rb') as f:
AttributeError: module 'tensorflow._api.v2.io.gfile' has no attribute 'FastGFile'
Vielleicht kann mir ja Jemand weiter helfen?
Gruß
RE
import numpy as np
import tensorflow as tf
import cv2 as cv
# Read the graph.
with tf.gfile.FastGFile('frozen_inference_graph.pb', 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
with tf.Session() as sess:
# Restore session
sess.graph.as_default()
tf.import_graph_def(graph_def, name='')
# Read and preprocess an image.
img = cv.imread('example.jpg')
rows = img.shape[0]
cols = img.shape[1]
inp = cv.resize(img, (300, 300))
inp = inp[:, :, [2, 1, 0]] # BGR2RGB
# Run the model
out = sess.run([sess.graph.get_tensor_by_name('num_detections:0'),
sess.graph.get_tensor_by_name('detection_scores:0'),
sess.graph.get_tensor_by_name('detection_boxes:0'),
sess.graph.get_tensor_by_name('detection_classes:0')],
feed_dict={'image_tensor:0': inp.reshape(1, inp.shape[0], inp.shape[1], 3)})
# Visualize detected bounding boxes.
num_detections = int(out[0][0])
for i in range(num_detections):
classId = int(out[3][0][i])
score = float(out[1][0][i])
bbox = [float(v) for v in out[2][0][i]]
if score > 0.3:
x = bbox[1] * cols
y = bbox[0] * rows
right = bbox[3] * cols
bottom = bbox[2] * rows
cv.rectangle(img, (int(x), int(y)), (int(right), int(bottom)), (125, 255, 51), thickness=2)
cv.imshow('TensorFlow MobileNet-SSD', img)
cv.waitKey()
Alles anzeigen