【问题标题】:How to predict Faster RCNN model in batches?如何批量预测 Faster RCNN 模型?
【发布时间】:2021-03-03 01:48:27
【问题描述】:

我有一个训练有素的 RCNN (Keras-Retinanet) 模型,我一次只能预测一张图像。

boxes, scores, labels = model.predict_on_batch(np.expand_dims(image, axis=0))

完整的脚本是here

有没有办法一次预测多张图像?

谢谢

【问题讨论】:

    标签: tensorflow keras prediction faster-rcnn


    【解决方案1】:

    您在那里扩展 dims 的原因是为了人为地添加批处理维度。只需将一堆图像堆叠在一起,然后将其传递给此函数即可得到一批结果。

    换一种说法,现在你正在传递: [图片]。

    您可以改为传入: [image_1, image_2, image_3, ...](作为一个 numpy,而不是 python 数组)

    【讨论】:

    • 已尝试但出现此错误:File "detector.py", line 85, in <module> boxes, scores, labels = model.predict_on_batch(image, image1, image2, image3) TypeError: predict_on_batch() takes 2 positional arguments but 5 were given
    • 我也试过imgs = [] imgs.append(image) imgs.append(image1) 并得到这个错误ValueError: Input 0 of layer conv1 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [800, 800, 3]
    • 不能传入python列表,必须构造一个合适形状的张量或numpy数组。一种方法是扩展暗淡,然后使用 numpy 的追加:numpy.org/doc/stable/reference/generated/numpy.append.html
    猜你喜欢
    • 2021-03-03
    • 2020-06-01
    • 2018-01-09
    • 2020-06-17
    • 2019-12-08
    • 2020-01-20
    • 1970-01-01
    • 2020-08-22
    • 2021-09-18
    相关资源
    最近更新 更多