-
-
Save gauravbansal98/f4675b67ca08db685ee75bd462943fb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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