class_docstr: ## Configurations
class_docstr_tok: ["#","#","Configurations"]
docstr: ### Initialize
docstr_tok: ["#","#","#","Initialize"]
code: def init(self):
      """
      ### Initialize
      """
      # Create dataset
      dataset = Dataset(self.dataset_path, self.image_size)
      # Create data loader
      dataloader = torch.utils.data.DataLoader(
          dataset,
          batch_size=self.batch_size,
          num_workers=8,
          shuffle=True,
          drop_last=True,
          pin_memory=True,
      )
      # Continuous [cyclic loader](../../utils.html#cycle_dataloader)
      self.loader = cycle_dataloader(dataloader)
  
      # $\log_2$ of image resolution
      log_resolution = int(math.log2(self.image_size))
  
      # Create discriminator and generator
      self.discriminator = Discriminator(log_resolution).to(self.device)
      self.generator = Generator(log_resolution, self.d_latent).to(
          self.device
      )
      # Get number of generator blocks for creating style and noise inputs
      self.n_gen_blocks = self.generator.n_blocks
      # Create mapping network
      self.mapping_network = MappingNetwork(
          self.d_latent, self.mapping_network_layers
      ).to(self.device)
      # Create path length penalty loss
      self.path_length_penalty = PathLengthPenalty(0.99).to(self.device)
  
      # Add model hooks to monitor layer outputs
      if self.log_layer_outputs:
          hook_model_outputs(
              self.mode, self.discriminator, "discriminator"
          )
          hook_model_outputs(self.mode, self.generator, "generator")
          hook_model_outputs(
              self.mode, self.mapping_network, "mapping_network"
          )
  
      # Discriminator and generator losses
      self.discriminator_loss = DiscriminatorLoss().to(self.device)
      self.generator_loss = GeneratorLoss().to(self.device)
  
      # Create optimizers
      self.discriminator_optimizer = torch.optim.Adam(
          self.discriminator.parameters(),
          lr=self.learning_rate,
          betas=self.adam_betas,
      )
      self.generator_optimizer = torch.optim.Adam(
          self.generator.parameters(),
          lr=self.learning_rate,
          betas=self.adam_betas,
      )
      self.mapping_network_optimizer = torch.optim.Adam(
          self.mapping_network.parameters(),
          lr=self.mapping_network_learning_rate,
          betas=self.adam_betas,
      )
  
      # Set tracker configurations
      tracker.set_image("generated", True)
  
imports: import math
  from pathlib import Path
  from typing import Iterator, Tuple
  import torch
  import torch.utils.data
  import torchvision
  from PIL import Image
  from labml import tracker, lab, monit, experiment
  from labml.configs import BaseConfigs
  from labml_helpers.device import DeviceConfigs
  from labml_helpers.train_valid import ModeState, hook_model_outputs
  from labml_nn.gan.stylegan import Discriminator, Generator, MappingNetwork, GradientPenalty, PathLengthPenalty
  from labml_nn.gan.wasserstein import DiscriminatorLoss, GeneratorLoss
  from labml_nn.utils import cycle_dataloader
label_desc: Use image node_id 1 for calling the Configs obj's underlying member method code with example usage: obj.init() without return types