Skip to content

Instantly share code, notes, and snippets.

@gauravbansal98
Created May 14, 2020 11:51
Show Gist options
  • Save gauravbansal98/f4675b67ca08db685ee75bd462943fb1 to your computer and use it in GitHub Desktop.
Save gauravbansal98/f4675b67ca08db685ee75bd462943fb1 to your computer and use it in GitHub Desktop.
encoder_model = Encoder()
decoder_model = CaptionModel(vocab_size).to(device)
decoder_model.load_state_dict(torch.load(args.checkpoint))
for image_name in os.listdir("evaluate/images"):
image = load_image(image_name, size=224)
# convert the image pixels to a numpy array
image = transforms.ToTensor()(image)
# reshape data for the model
image = image.unsqueeze(0)
# prepare the image for the VGG model
image = normalize_batch(image)
features = encoder_model(image)
predicted_sentence = generate_desc(decoder_model, tokenizer, features, max_length)
print(predicted_sentence)
plt.axis('off')
plt.title(predicted_sentence)
plt.savefig(os.path.join("evaluate/results/",
image_name+'_result.jpg'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment