I have a pytorch model and I can test a sample image by following scripts. I want to know how can I send a batch of images to this model. I am pretty noob at pytorch and tensorflow.
You could load a few images and create a batch of these tensors using e.g. torch.stack.
E.g. assuming each image has a shape of [3, 224, 224] and you are loading 5 images, the code would look similar to this:
x = []
# load 5 images
for _ in range(5):
img = torch.randn(3, 224, 224) # load your actual image here and transform it to a tensor
x.append(img)
x = torch.stack(x)
print(x.shape)
# > torch.Size([5, 3, 224, 224])
out = model(x)
Of course you could also use a Dataset etc. so I would generally recommend to take a look at the tutorials.
Also, remove the Variable usage, as it’s deprecated since PyTorch 0.4.