I am using PyTorch for custom image classification for 2 classes (like cats and dogs). I have the pretrained model already which classifies the passed image as either cat or dog.
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
class_names = ['dogs', 'cats']
def predict_label(image_path, model):
img = Image.open(image_path)
img_transformed = transformer(img)
with torch.no_grad():
model.eval()
output = model(img_transformed)
print(output)
index = output.data.cpu().numpy().argmax()
return class_names[index]
model = torch.load('dogs_cats')
predict_label("./husky.jpg", model)
I'm getting the following output for model(img_transformed)
.
tensor([[ 0.4717, -0.1059]], device='cuda:0')
Is it possible to draw a bounding box on parts of the image based on the class having highest probability? If so, how to get the coordinates of the bounding box?