我通过一次调用就为视频中的所有关键帧生成了imagenet标签,并具有以下代码:
# all keras/tf/mobilenet imports
model_imagenet = MobileNetV2(weights='imagenet')
frames_list = []
for frame in frame_set:
frame_img = frame.to_image()
frame_pil = frame_img.resize((224,224), Image.ANTIALIAS)
ts = int(frame.pts)
x = image.img_to_array(frame_pil)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
frames_list.append(x)
print(len(frames_list))
preds_list = model_imagenet.predict_on_batch(frames_list)
print("[*]",preds_list)
结果显示如下:
frames_list count: 125
因此,预测是一排1000维(图像网络类),难道不是125行吗?:
[[1.15425530e-04 1.83317825e-04 4.28701424e-05 2.87547664e-05
:
7.91769926e-05 1.30803732e-04 4.81895368e-05 3.06891889e-04]]
这将为批处理中的单个行生成预测。我已经尝试了predict
和predict_on_batch
的相同结果。
如何通过Keras / Tensorflow / Mobilenet一次获得200帧的批量预测?
ImageNet是一个流行的数据库,包含1000个不同的类别。
[好,这是我解决的方法,希望这对其他人有帮助: