MCPcopy Create free account
hub / github.com/XingangPan/DragGAN / training_loop

Function training_loop

training/training_loop.py:90–425  ·  view source on GitHub ↗
(
    run_dir                 = '.',      # Output directory.
    training_set_kwargs     = {},       # Options for training set.
    data_loader_kwargs      = {},       # Options for torch.utils.data.DataLoader.
    G_kwargs                = {},       # Options for generator network.
    D_kwargs                = {},       # Options for discriminator network.
    G_opt_kwargs            = {},       # Options for generator optimizer.
    D_opt_kwargs            = {},       # Options for discriminator optimizer.
    augment_kwargs          = None,     # Options for augmentation pipeline. None = disable.
    loss_kwargs             = {},       # Options for loss function.
    metrics                 = [],       # Metrics to evaluate during training.
    random_seed             = 0,        # Global random seed.
    num_gpus                = 1,        # Number of GPUs participating in the training.
    rank                    = 0,        # Rank of the current process in [0, num_gpus[.
    batch_size              = 4,        # Total batch size for one training iteration. Can be larger than batch_gpu * num_gpus.
    batch_gpu               = 4,        # Number of samples processed at a time by one GPU.
    ema_kimg                = 10,       # Half-life of the exponential moving average (EMA) of generator weights.
    ema_rampup              = 0.05,     # EMA ramp-up coefficient. None = no rampup.
    G_reg_interval          = None,     # How often to perform regularization for G? None = disable lazy regularization.
    D_reg_interval          = 16,       # How often to perform regularization for D? None = disable lazy regularization.
    augment_p               = 0,        # Initial value of augmentation probability.
    ada_target              = None,     # ADA target value. None = fixed p.
    ada_interval            = 4,        # How often to perform ADA adjustment?
    ada_kimg                = 500,      # ADA adjustment speed, measured in how many kimg it takes for p to increase/decrease by one unit.
    total_kimg              = 25000,    # Total length of the training, measured in thousands of real images.
    kimg_per_tick           = 4,        # Progress snapshot interval.
    image_snapshot_ticks    = 50,       # How often to save image snapshots? None = disable.
    network_snapshot_ticks  = 50,       # How often to save network snapshots? None = disable.
    resume_pkl              = None,     # Network pickle to resume training from.
    resume_kimg             = 0,        # First kimg to report when resuming training.
    cudnn_benchmark         = True,     # Enable torch.backends.cudnn.benchmark?
    abort_fn                = None,     # Callback function for determining whether to abort training. Must return consistent results across ranks.
    progress_fn             = None,     # Callback function for updating training progress. Called for all ranks.
)

Source from the content-addressed store, hash-verified

88#----------------------------------------------------------------------------
89
90def training_loop(
91 run_dir = '.', # Output directory.
92 training_set_kwargs = {}, # Options for training set.
93 data_loader_kwargs = {}, # Options for torch.utils.data.DataLoader.
94 G_kwargs = {}, # Options for generator network.
95 D_kwargs = {}, # Options for discriminator network.
96 G_opt_kwargs = {}, # Options for generator optimizer.
97 D_opt_kwargs = {}, # Options for discriminator optimizer.
98 augment_kwargs = None, # Options for augmentation pipeline. None = disable.
99 loss_kwargs = {}, # Options for loss function.
100 metrics = [], # Metrics to evaluate during training.
101 random_seed = 0, # Global random seed.
102 num_gpus = 1, # Number of GPUs participating in the training.
103 rank = 0, # Rank of the current process in [0, num_gpus[.
104 batch_size = 4, # Total batch size for one training iteration. Can be larger than batch_gpu * num_gpus.
105 batch_gpu = 4, # Number of samples processed at a time by one GPU.
106 ema_kimg = 10, # Half-life of the exponential moving average (EMA) of generator weights.
107 ema_rampup = 0.05, # EMA ramp-up coefficient. None = no rampup.
108 G_reg_interval = None, # How often to perform regularization for G? None = disable lazy regularization.
109 D_reg_interval = 16, # How often to perform regularization for D? None = disable lazy regularization.
110 augment_p = 0, # Initial value of augmentation probability.
111 ada_target = None, # ADA target value. None = fixed p.
112 ada_interval = 4, # How often to perform ADA adjustment?
113 ada_kimg = 500, # ADA adjustment speed, measured in how many kimg it takes for p to increase/decrease by one unit.
114 total_kimg = 25000, # Total length of the training, measured in thousands of real images.
115 kimg_per_tick = 4, # Progress snapshot interval.
116 image_snapshot_ticks = 50, # How often to save image snapshots? None = disable.
117 network_snapshot_ticks = 50, # How often to save network snapshots? None = disable.
118 resume_pkl = None, # Network pickle to resume training from.
119 resume_kimg = 0, # First kimg to report when resuming training.
120 cudnn_benchmark = True, # Enable torch.backends.cudnn.benchmark?
121 abort_fn = None, # Callback function for determining whether to abort training. Must return consistent results across ranks.
122 progress_fn = None, # Callback function for updating training progress. Called for all ranks.
123):
124 # Initialize.
125 start_time = time.time()
126 device = torch.device('cuda', rank)
127 np.random.seed(random_seed * num_gpus + rank)
128 torch.manual_seed(random_seed * num_gpus + rank)
129 torch.backends.cudnn.benchmark = cudnn_benchmark # Improves training speed.
130 torch.backends.cuda.matmul.allow_tf32 = False # Improves numerical accuracy.
131 torch.backends.cudnn.allow_tf32 = False # Improves numerical accuracy.
132 conv2d_gradfix.enabled = True # Improves training speed.
133 grid_sample_gradfix.enabled = True # Avoids errors with the augmentation pipe.
134
135 # Load training set.
136 if rank == 0:
137 print('Loading training set...')
138 training_set = dnnlib.util.construct_class_by_name(**training_set_kwargs) # subclass of training.dataset.Dataset
139 training_set_sampler = misc.InfiniteSampler(dataset=training_set, rank=rank, num_replicas=num_gpus, seed=random_seed)
140 training_set_iterator = iter(torch.utils.data.DataLoader(dataset=training_set, sampler=training_set_sampler, batch_size=batch_size//num_gpus, **data_loader_kwargs))
141 if rank == 0:
142 print()
143 print('Num images: ', len(training_set))
144 print('Image shape:', training_set.image_shape)
145 print('Label shape:', training_set.label_shape)
146 print()
147

Callers

nothing calls this directly

Calls 9

updateMethod · 0.95
as_dictMethod · 0.95
save_image_gridFunction · 0.70
trainMethod · 0.45
get_labelMethod · 0.45
accumulate_gradientsMethod · 0.45
writeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected