Hey there I am new to PyTorch. I have a inference code that predicts and classify images. I can predict and classify images one by one, can anyone please help me to classify all the images of a folder in a batch.
How can I load all the image in the folder and predict one by one.
I am using the prediction code as follows:
def predict_image(image_path): print("prediciton in progress") image = Image.open(image_path) transformation = transforms.Compose([ transforms.RandomResizedCrop(224), transforms.ToTensor(), transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) ]) image_tensor = transformation(image).float() image_tensor = image_tensor.unsqueeze_(0) if cuda: image_tensor.cuda() input = Variable(image_tensor) output = model(input) index = output.data.numpy().argmax() return index
This works for single images, if called again and again the time of execution will increase. Also I am doing inference on a CPU machine.