docstr: Add class weights to a given dataset that are then accessible using the `class_weights` attribute
          
docstr_tok: ["Add","class","weights","to","a","given","dataset","that","are","then","accessible","using","the","`","class_weights","`","attribute"]
code: def add_weights(
      self, dataset_name="train", class_weight_method="sqrt"
  ):
      """Add class weights to a given dataset that are then accessible using the `class_weights` attribute"""
      L = self.num_classes
      weights = torch.ones(L)
      dataset = self.get_dataset(dataset_name)
      idx_classes, counts = torch.unique(
          dataset.data.y, return_counts=True
      )
  
      dataset.idx_classes = torch.arange(L).long()
      weights[idx_classes] = counts.float()
      weights = weights.float()
      weights = weights.mean() / weights
      if class_weight_method == "sqrt":
          weights = torch.sqrt(weights)
      elif str(class_weight_method).startswith("log"):
          weights = torch.log(1.1 + weights / weights.sum())
      else:
          raise ValueError(
              "Method %s not supported" % class_weight_method
          )
  
      weights /= torch.sum(weights)
      log.info(
          "CLASS WEIGHT : {}".format(
              [np.round(weight.item(), 4) for weight in weights]
          )
      )
      setattr(dataset, "weight_classes", weights)
  
      return dataset
  
imports: import os
  from abc import ABC, abstractmethod
  import logging
  import functools
  from functools import partial
  import numpy
  import torch
  import torch_geometric
  from torch_geometric.transforms import Compose, FixedPoints
  import copy
  from torch_points3d.models import model_interface
  from torch_points3d.core.data_transform import instantiate_transforms, MultiScaleTransform
  from torch_points3d.core.data_transform import instantiate_filters
  from torch_points3d.datasets.batch import SimpleBatch
  from torch_points3d.datasets.multiscale_data import MultiScaleBatch
  from torch_points3d.utils.enums import ConvolutionFormat
  from torch_points3d.utils.config import ConvolutionFormatFactory
  from torch_points3d.utils.colors import COLORS, colored_print
label_desc: Use image node_id 43 for calling the BaseDataset obj's underlying member method code with example usage: obj.add_weights(dataset_name, class_weight_method) and returns: dataset