code: def main():
      num_classes = 5
      im_height = im_width = 224
  
      # load image
      img_path = "../tulip.jpg"
      assert os.path.exists(
          img_path
      ), "file: '{}' dose not exist.".format(img_path)
      img = Image.open(img_path)
      # resize image
      img = img.resize((im_width, im_height))
      plt.imshow(img)
  
      # read image
      img = np.array(img).astype(np.float32)
  
      # preprocess
      img = (img / 255.0 - [0.485, 0.456, 0.406]) / [
          0.229,
          0.224,
          0.225,
      ]
  
      # Add the image to a batch where it's the only member.
      img = np.expand_dims(img, 0)
  
      # read class_indict
      json_path = "./class_indices.json"
      assert os.path.exists(
          json_path
      ), "file: '{}' dose not exist.".format(json_path)
  
      with open(json_path, "r") as f:
          class_indict = json.load(f)
  
      # create model
      model = create_model(num_classes=num_classes)
      model.build([1, im_height, im_width, 3])
  
      weights_path = "./save_weights/model.ckpt"
      assert len(
          glob.glob(weights_path + "*")
      ), "cannot find {}".format(weights_path)
      model.load_weights(weights_path)
  
      result = np.squeeze(model.predict(img, batch_size=1))
      result = tf.keras.layers.Softmax()(result)
      predict_class = np.argmax(result)
  
      print_res = "class: {}   prob: {:.3}".format(
          class_indict[str(predict_class)], result[predict_class]
      )
      plt.title(print_res)
      for i in range(len(result)):
          print(
              "class: {:10}   prob: {:.3}".format(
                  class_indict[str(i)], result[i]
              )
          )
      plt.show()
  
file_path: deep-learning-for-image-processing/tensorflow_classification/swin_transformer/predict.py
imports: import os
  import json
  import glob
  import numpy
  from PIL import Image
  import tensorflow
  import matplotlib.pyplot
  from model import swin_tiny_patch4_window7_224
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types