0

I'm using Keras for a sliding window object detection system. This naturally requires the ability to do many, many classifications quickly. Unfortunately, Keras's model.predict() function has a significant overhead and takes longer to load? preprocess the data? who knows, than it does to do the actual network processing. I know because I've tried removing layers, etc. and it makes almost no difference to the time spent in a model.predict() call.

So basically what I'm looking for is a way to use one network and run predictions on several inputs at once. Not necessarily in separate threads, but without returning to my code. Is anyone aware of such a technique?

brendon-ai
  • 517
  • 3
  • 7
  • 20
  • 1
    model.predict can already take multiple inputs (in the first dimension), so I am not sure what is the problem. – Dr. Snoopy Oct 03 '17 at 01:06
  • @MatiasValdenegro it can indeed take multiple inputs, but as far as I know the network has to be designed to take multiple. Please correct me if this assumption is wrong. – brendon-ai Oct 03 '17 at 01:26
  • Your assumption is wrong. You can process several samples at once using batching. – Dr. Snoopy Oct 03 '17 at 01:36
  • Predicting is pretty much like training. You train with lots of samples in a batch, and you predict with lots of samples in a batch. No difference. – Daniel Möller Oct 03 '17 at 12:53
  • @DanielMöller When I pass it a list of Numpy arrays, it gives me the following error: https://hastebin.com/iliqohokom.pas Is there some configuration change I need to make to process a batch? – brendon-ai Oct 03 '17 at 13:15
  • @MatiasValdenegro see comment above – brendon-ai Oct 03 '17 at 13:15
  • 1
    You must pass a single numpy array, not a list of numpy arrays. If you've got variable lengths, there is no choice, but separating arrays for each length and predicting each of these arrays: https://stackoverflow.com/questions/46144191/keras-misinterprets-training-data-shape/46146146#46146146 – Daniel Möller Oct 03 '17 at 13:26
  • @DanielMöller thank you! I had the incorrect number of dimensions and had to squeeze it. Works now! Feel free to add it as an answer, I will accept. – brendon-ai Oct 03 '17 at 15:47

0 Answers0