How to process each item in batch at the same time?

Hi, I’m trying to process each item in batch at the same time.

Ex)
I have a batch (8 x 3 x 224 x 224) where its batch size is 8 and l also have a function whose input is one image (3 x 224 x 224).

Then, I want to repeat the same function on each image. I can do this by iterating all items like:
for i in range(data.shape[0]):
input[i] = function(inputs[i])

But I think this loop is too time-consuming. Is there a more efficient way to process a batch of data at the same time?

It depends on the implementation of your function.
PyTorch methods usually accept batched data, so if you are using internally in function PyTorch methods, it could directly work.