class_docstr: TorchPoints3d Trainer handles the logic between
      - BaseModel,
      - Dataset and its Tracker
      - A custom ModelCheckpoint
      - A custom Visualizer
  It supports MC dropout - multiple voting_runs for val / test datasets
class_docstr_tok: ["TorchPoints3d","Trainer","handles","the","logic","between","-","BaseModel",",","-","Dataset","and","its","Tracker","-","A","custom","ModelCheckpoint","-","A","custom","Visualizer","It","supports","MC","dropout","-","multiple","voting_runs","for","val","\/","test","datasets"]
code: def _initialize_trainer(self):
      # Enable CUDNN BACKEND
      torch.backends.cudnn.enabled = self.enable_cudnn
  
      if not self.has_training:
          self._cfg.training = self._cfg
          resume = bool(self._cfg.checkpoint_dir)
      else:
          resume = bool(self._cfg.training.checkpoint_dir)
  
      # Get device
      if self._cfg.training.cuda > -1 and torch.cuda.is_available():
          device = "cuda"
          torch.cuda.set_device(self._cfg.training.cuda)
      else:
          device = "cpu"
      self._device = torch.device(device)
      log.info("DEVICE : {}".format(self._device))
  
      # Profiling
      if self.profiling:
          # Set the num_workers as torch.utils.bottleneck doesn't work well with it
          self._cfg.training.num_workers = 0
  
      # Start Wandb if public
      if self.wandb_log:
          Wandb.launch(
              self._cfg,
              self._cfg.training.wandb.public and self.wandb_log,
          )
  
      # Checkpoint
  
      self._checkpoint: ModelCheckpoint = ModelCheckpoint(
          self._cfg.training.checkpoint_dir,
          self._cfg.model_name,
          self._cfg.training.weight_name,
          run_config=self._cfg,
          resume=resume,
      )
  
      # Create model and datasets
      if not self._checkpoint.is_empty:
          self._dataset: BaseDataset = instantiate_dataset(
              self._checkpoint.data_config
          )
          self._model: BaseModel = self._checkpoint.create_model(
              self._dataset, weight_name=self._cfg.training.weight_name
          )
      else:
          self._dataset: BaseDataset = instantiate_dataset(
              self._cfg.data
          )
          self._model: BaseModel = instantiate_model(
              copy.deepcopy(self._cfg), self._dataset
          )
          self._model.instantiate_optimizers(
              self._cfg, "cuda" in device
          )
          self._model.set_pretrained_weights()
          if not self._checkpoint.validate(
              self._dataset.used_properties
          ):
              log.warning(
                  "The model will not be able to be used from pretrained weights without the corresponding dataset. Current properties are {}".format(
                      self._dataset.used_properties
                  )
              )
      self._checkpoint.dataset_properties = (
          self._dataset.used_properties
      )
  
      log.info(self._model)
  
      self._model.log_optimizers()
      log.info(
          "Model size = %i",
          sum(
              param.numel()
              for param in self._model.parameters()
              if param.requires_grad
          ),
      )
  
      # Set dataloaders
      self._dataset.create_dataloaders(
          self._model,
          self._cfg.training.batch_size,
          self._cfg.training.shuffle,
          self._cfg.training.num_workers,
          self.precompute_multi_scale,
      )
      log.info(self._dataset)
  
      # Verify attributes in dataset
      self._model.verify_data(self._dataset.train_dataset[0])
  
      # Choose selection stage
      selection_stage = getattr(self._cfg, "selection_stage", "")
      self._checkpoint.selection_stage = (
          self._dataset.resolve_saving_stage(selection_stage)
      )
      self._tracker: BaseTracker = self._dataset.get_tracker(
          self.wandb_log, self.tensorboard_log
      )
  
      if self.wandb_log:
          Wandb.launch(
              self._cfg,
              not self._cfg.training.wandb.public and self.wandb_log,
          )
  
      # Run training / evaluation
      self._model = self._model.to(self._device)
      if self.has_visualization:
          self._visualizer = Visualizer(
              self._cfg.visualization,
              self._dataset.num_batches,
              self._dataset.batch_size,
              os.getcwd(),
              self._tracker,
          )
  
imports: import os
  import copy
  import torch
  import hydra
  import time
  import logging
  from tqdm.auto import tqdm
  import wandb
  from torch_points3d.datasets.dataset_factory import instantiate_dataset
  from torch_points3d.models.model_factory import instantiate_model
  from torch_points3d.models.base_model import BaseModel
  from torch_points3d.datasets.base_dataset import BaseDataset
  from torch_points3d.metrics.base_tracker import BaseTracker
  from torch_points3d.metrics.colored_tqdm import Coloredtqdm
  from torch_points3d.metrics.model_checkpoint import ModelCheckpoint
  from torch_points3d.utils.colors import COLORS
  from torch_points3d.utils.wandb_utils import Wandb
  from torch_points3d.visualization import Visualizer
  import torch.profiler
  import torch.autograd.profiler
  from contextlib import nullcontext
label_desc: Use image node_id 2 for calling the Trainer obj's underlying member method code with example usage: obj._initialize_trainer() without return types