-1

I have a trained RCNN (Keras-Retinanet) model and I could predict only one image at a time.

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

Full script is here.

Is there a way to predict multiple images at a time?

Thanks

RedFox
  • 1,158
  • 2
  • 15
  • 28

1 Answers1

0

The reason you expand the dims there is to artificially add a batch dimension. Simply stack a bunch of images together and pass it into this function to get a batch of results.

Said differently, right now you are passing in: [image].

You could instead pass in: [image_1, image_2, image_3, ...] (as a numpy, not python array)

kmindspark
  • 487
  • 1
  • 7
  • 18
  • Tried but for this error: `File "detector.py", line 85, in boxes, scores, labels = model.predict_on_batch(image, image1, image2, image3) TypeError: predict_on_batch() takes 2 positional arguments but 5 were given` – RedFox Mar 03 '21 at 04:32
  • I also tried `imgs = [] imgs.append(image) imgs.append(image1)` and got this error `ValueError: Input 0 of layer conv1 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [800, 800, 3]` – RedFox Mar 03 '21 at 04:35
  • You can't pass in a python list, you have to construct a tensor or numpy array of the appropriate shape. One way to do this is to expand the dim, then use numpy's append: https://numpy.org/doc/stable/reference/generated/numpy.append.html – kmindspark Mar 03 '21 at 04:40