class_docstr: This wrapper handles torch models for image classification.
  
  It can either support models from torchvision.models (resnet18, alexnet, ...) or a
  simple CNN for MNIST (simple-cnn, see SimpleCnn class).
class_docstr_tok: ["This","wrapper","handles","torch","models","for","image","classification",".","It","can","either","support","models","from","torchvision.models","(","resnet18",",","alexnet",",","...",")","or","a","simple","CNN","for","MNIST","(","simple-cnn",",","see","SimpleCnn","class",")","."]
docstr: Runs data through the model and returns output.
docstr_tok: ["Runs","data","through","the","model","and","returns","output","."]
code: def predict(self, image) -> dict:
      """Runs data through the model and returns output."""
  
      # Convert data format if required.
      image_format = preprocessing.recognize_image_format(image)
      if image_format == "files":
          image = preprocessing.load_image(
              image,
              to_numpy=False,
              resize=256,
              crop=224,
              mean=[0.485, 0.456, 0.406],
              std=[0.229, 0.224, 0.225],
          )
      elif image_format == "numpy":
          # TODO: This is almost the same code as in preprocessing.numpy_to_torch,
          #   maybe refactor it.
  
          # Rescale images to 0-255 and convert to uint8.
          # TODO: This should probably be done with the same min/max values as train
          #   set, see note in preprocessing.numpy_to_torch.
          image = (image - np.min(image)) / np.ptp(image) * 255
          image = image.astype(np.uint8)
  
          # If images are grayscale, convert to RGB by duplicating channels.
          if image.shape[0] == 1:
              image = np.stack((image[0],) * 3, axis=0)
  
          # Convert to channels last format (required for transforms.ToPILImage).
          image = image.transpose((1, 2, 0))
  
          # Set up transform to convert to PIL image, do manipulations, and convert
          # to tensor.
          # TODO: Converting to PIL and then to tensor is not super efficient, find
          #   a better method.
          transform = preprocessing.create_transform(
              from_numpy=True,
              resize=256,
              crop=224,
              mean=[0.485, 0.456, 0.406],
              std=[0.229, 0.224, 0.225],
          )
          image = transform(image)
      else:
          raise RuntimeError()
  
      # Wrap image in batch.
      image_batch = image.unsqueeze(dim=0)
  
      self.model.eval()
      with torch.no_grad():
          output = self.model(image_batch)[0]
          probabilities = torch.softmax(output, dim=0).numpy()
          predicted_class = output.argmax().item()
      return {
          "predicted_class": predicted_class,
          "probabilities": probabilities,
      }
  
imports: import comet_ml
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from torch.utils.data import DataLoader
  import torchvision
  from ignite.engine import Events, create_supervised_trainer, create_supervised_evaluator
  from ignite.metrics import Accuracy, Loss
  import numpy
  from loguru import logger
  from ..model_wrapper import ModelWrapper
  from .None import preprocessing, visualization
  from ..None import utils
label_desc: Use image node_id 6 for calling the TorchImageClassificationWrapper obj's underlying member method code with example usage: obj.predict(image) and returns: dict