class_docstr: 🤗 Constructor for the image classifier trainer
class_docstr_tok: ["\ud83e\udd17","Constructor","for","the","image","classifier","trainer"]
code: def predict_image(self, img, return_str=True):
      # Change resolution to 128x128
      img.thumbnail((self.resolution, self.resolution))
  
      # Transform the image
      encoding = self.feature_extractor(images=img, return_tensors="pt")
  
      # Predict and get the corresponding label identifier
      pred = self.model(encoding["pixel_values"])
  
      # Get label index
      predicted_class_idx = pred.logits.argmax(-1).tolist()[0]
  
      if return_str:
          # Get string label from index
          return self.model.config.id2label[predicted_class_idx]
  
      else:
          labels = list(self.model.config.label2id.keys())
  
          softmax = torch.nn.Softmax(dim=0)
  
          pred_soft = softmax(pred[0][0])
          pred_soft = torch.mul(pred_soft, 100)
          probabilities = pred_soft.tolist()
  
          return dict(zip(labels, probabilities))
  
imports: import torch
  from PIL import Image
  from transformers import ViTFeatureExtractor, ViTForImageClassification, pipeline
label_desc: Use image node_id 2 for calling the VisionClassifierInference obj's underlying member method code with example usage: obj.predict_image(img, return_str) and returns: self, dict