Here is an example, in Java that explains more about inference tflite models with different batch size:
// First get the input shape of the interpreter, this will give you smth like this [1, 300, 300, 3]
int[] inputs = interpreter.getInputTensor(0).shape();
// The first element of above array represents batch size, so we change that
inputs[0] = 4 // 4 is batch size in this case
// update interpreter with new input size
interpreter.resizeInput(0, inputs);
One other important thing is how you prepare the input and output of interpreter, input data will be smth like this (extra attention to the "IMPORTANT" comment):
int numBytesPerChannel;
if (isQuantized) {
numBytesPerChannel = 1; // Quantized
} else {
numBytesPerChannel = 4; // Floating point
}
imgData = ByteBuffer.allocateDirect(batchSize * inputWidth * inputHeight * 3 * numBytesPerChannel);
imgData.order(ByteOrder.nativeOrder());
........
// Here you add the data from bitmap into the ByteBuffer (imgData)
// IMPORTANT: make sure that you write all the data into the same ByteBuffer (in our case imgData)
........
Object[] inputArray = {imgData};
Map<Integer, Object> outputMap = new HashMap<>();
// add your output here, I am adding [4][1][1][1024] as example, 4 is batch size
outputMap.put(0, new float[4][1][1][1024]);
// and then run the tflite interpreter
interpreter.runForMultipleInputsOutputs(inputArray, outputMap);