【发布时间】:2020-03-13 09:38:49
【问题描述】:
我是对象检测的新手,我很难弄清楚如何从 MobileNetV2 上的 Keras 应用程序中获取边界框:https://keras.io/applications/#mobilenetv2
该模型在预测图像内容方面效果很好,但是该模型的预测不包括边界框。我正在使用 ResNet50 提供的 Keras 示例,但由于我需要轻量级 SSD 架构,因此将其更改为 MobileNetV2。
from keras.applications.mobilenet_v2 import MobileNetV2
from keras.preprocessing import image
from keras.applications.mobilenet_v2 import preprocess_input, decode_predictions
import numpy as np
model = MobileNetV2(weights='imagenet')
img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = model.predict(x)
# decode the results into a list of tuples (class, description, probability)
# (one such list for each sample in the batch)
print('Predicted:', decode_predictions(preds, top=3)[0])
# Predicted: [(u'n02504013', u'Indian_elephant', 0.82658225), (u'n01871265', u'tusker', 0.1122357), (u'n02504458', u'African_elephant', 0.061040461)]
我使用了 MobileNetV2 的低级张量流实现
# Load the Tensorflow model into memory.
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='')
sess = tf.Session(graph=detection_graph)
(boxes, scores, classes, num) = sess.run(
[detection_boxes, detection_scores, detection_classes, num_detections],
feed_dict={image_tensor: frame_expanded})
返回边界框。 Keras 是错过了这个还是我要疯了? 非常感谢您的宝贵时间!
【问题讨论】:
标签: tensorflow object keras detection tensorflow-ssd