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",")","."]
code: def _preprocess_for_training(self, name, data, use_cuda=False):
      if data is None:  # val/test can be empty´
          logger.info(f"{name}: Not given")
          return None
      else:
          logger.info(f"{name}:")
  
          # Get number of classes from config or infer from train_data (needs to be
          # done before the conversion!).
          if "num_classes" in self.config:
              self.num_classes = self.config["num_classes"]
          elif name == "train":
              self.num_classes = preprocessing.get_num_classes(data)
  
          # Convert format.
          logger.info(
              f"    data format: {preprocessing.recognize_data_format(data)}"
          )
          # TODO: Properly do mean/std normalization.
          # TODO: Give error if resize/crop are in config (we always need these values
          #   here!).
          data = preprocessing.to_torch(
              data,
              resize=256,
              crop=224,
              mean=[0.485, 0.456, 0.406],
              std=[0.229, 0.224, 0.225],
          )
          logger.info(f"    resized to 256 x 256")
          logger.info(f"    center-cropped to 224 x 224")
          logger.info(f"    samples: {len(data)}")
          logger.info(f"    image shape: {tuple(data[0][0].shape)}")
  
          # TODO: Either write num classes for each dataset here or
          # TODO: Raise error if num_classes diverges between datasets.
          logger.info(f"    classes: {self.num_classes}")
  
          # Wrap in data loader.
          batch_size = self.config.get("batch_size", 128)
          kwargs = {"batch_size": batch_size}
          logger.info(f"    batch size: {batch_size}")
          if use_cuda:
              kwargs["pin_memory"] = True
              kwargs["num_workers"] = 1
          if name == "train":
              kwargs["shuffle"] = True
              logger.info(f"    shuffled")
          loader = DataLoader(data, **kwargs)
          return loader
  
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 3 for calling the TorchImageClassificationWrapper obj's underlying member method code with example usage: obj._preprocess_for_training(name, data, use_cuda) and returns: None, loader