map_location=device)) # Move models to GPU if CUDA is available. encoder.to(device) decoder.to(device) # Move image Pytorch Tensor to GPU if CUDA is available. image = image.to(device) # Obtain the embedded image features. features = encoder(image).unsqueeze(1) # Pass the embedded image features through the model to get a predicted caption. output = decoder.sample(features) sentence = vocab.convert_sentence(output) # display final result ax = plt.axes() # remove spines ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.spines['bottom'].set_visible(False) ax.spines['left'].set_visible(False) # Hide ticks ax.xaxis.set_major_locator(plt.NullLocator()) ax.yaxis.set_major_locator(plt.NullLocator()) plt.imshow(np.squeeze(orig_image))