code: def main(args):
      # Image preprocessing
      transform = transforms.Compose(
          [
              transforms.ToTensor(),
              transforms.Normalize(
                  (0.485, 0.456, 0.406), (0.229, 0.224, 0.225)
              ),
          ]
      )
  
      # Load vocabulary wrapper
      with open(args.vocab_path, "rb") as f:
          vocab = pickle.load(f)
  
      # Build models
      encoder = EncoderCNN(
          args.embed_size
      ).eval()  # eval mode (batchnorm uses moving mean/variance)
      decoder = DecoderRNN(
          args.embed_size, args.hidden_size, len(vocab), args.num_layers
      )
      encoder = encoder.to(device)
      decoder = decoder.to(device)
  
      # Load the trained model parameters
      encoder.load_state_dict(torch.load(args.encoder_path))
      decoder.load_state_dict(torch.load(args.decoder_path))
  
      # Prepare an image
      image = load_image(args.image, transform)
      image_tensor = image.to(device)
  
      # Generate an caption from the image
      feature = encoder(image_tensor)
      sampled_ids = decoder.sample(feature)
      sampled_ids = (
          sampled_ids[0].cpu().numpy()
      )  # (1, max_seq_length) -> (max_seq_length)
  
      # Convert word_ids to words
      sampled_caption = []
      for word_id in sampled_ids:
          word = vocab.idx2word[word_id]
          sampled_caption.append(word)
          if word == "<end>":
              break
      sentence = " ".join(sampled_caption)
  
      # Print out the image and the generated caption
      print(sentence)
      image = Image.open(args.image)
      plt.imshow(np.asarray(image))
  
file_path: pytorch-tutorial/tutorials/03-advanced/image_captioning/sample.py
imports: import torch
  import matplotlib.pyplot
  import numpy
  import argparse
  import pickle
  import os
  from torchvision import transforms
  from build_vocab import Vocabulary
  from model import EncoderCNN, DecoderRNN
  from PIL import Image
label_desc: Use image node_id 2 for calling a global function with example usage: main(args) without return types