(enc, gen, dists, layername, combine_z=None,
        batch_size=100, test_batches=10, checkpoint_dir='ckpts',
        resume_from=None, logfile=None, **kwargs)
Inverts a single layer of a multilayer inverter.
    Both enc and should be a nn.Sequential subclasses, and
    layername specifies the layer of enc to train.  That layer
    of enc will be trained to invert a set of gen layers.
    Which layers specifically are determined by split_gen_layers,
    which depends on enc.inverse_info(), to specify how each inverter
    layer relates to layers of gen.
Inverts a single layer of a multilayer inverter.
    Both enc and should be a nn.Sequential subclasses, and
    layername specifies the layer of enc to train.  That layer
    of enc will be trained to invert a set of gen layers.
    Which layers specifically are determined by split_gen_layers,
    which depends on enc.inverse_info(), to specify how each inverter
    layer relates to layers of gen.
Inverts a single layer of a multilayer inverter . Both enc and should be a nn . Sequential subclasses and layername specifies the layer of enc to train . That layer of enc will be trained to invert a set of gen layers . Which layers specifically are determined by split_gen_layers which depends on enc . inverse_info () to specify how each inverter layer relates to layers of gen .
def train_inv_layer(enc, gen, dists, layername, combine_z=None,
        batch_size=100, test_batches=10, checkpoint_dir='ckpts',
        resume_from=None, logfile=None, **kwargs):
    '''
    Inverts a single layer of a multilayer inverter.
    Both enc and should be a nn.Sequential subclasses, and
    layername specifies the layer of enc to train.  That layer
    of enc will be trained to invert a set of gen layers.
    Which layers specifically are determined by split_gen_layers,
    which depends on enc.inverse_info(), to specify how each inverter
    layer relates to layers of gen.
    '''
    if logfile is None:
        logfile = os.path.join(checkpoint_dir, 'log.txt')
    prev_layers, layers, next_layers = split_gen_layers(enc, gen, layername)
    inv = getattr(enc, layername)
    device = next(gen.parameters()).device
    args = enc.inverse_info()[layername]
    kwargs_out = {k: v for k, v in args.items() if k != 'first_layer'}
    kwargs_out.update(kwargs)
    if 'x_weight' not in kwargs_out:
        kwargs_out['x_weight'] = 0
    nethook.set_requires_grad(False, layers, prev_layers, next_layers)
    if combine_z is not None:
        nethook.set_requires_grad(False, combine_z)
        prev_layers_old = prev_layers
        prev_layers = lambda *a: prev_layers_old(combine_z(*a))
    zsampler = infinite_sampler(dists, prev_layers, batch_size, device)
    tsample = test_sampler(dists, prev_layers, batch_size, test_batches, device)
    train_inverse(inv, layers, zsampler, test_sampler=tsample,
            resume_from=resume_from,
            checkpoint_dir=checkpoint_dir, logfile=logfile,
            **kwargs_out)
def train_inv_layer ( enc , gen , dists , layername , combine_z = None , batch_size = 100 , test_batches = 10 , checkpoint_dir = 'ckpts' , resume_from = None , logfile = None , * * kwargs ) : if logfile is None : logfile = os . path . join ( checkpoint_dir , 'log.txt' ) prev_layers , layers , next_layers = split_gen_layers ( enc , gen , layername ) inv = getattr ( enc , layername ) device = next ( gen . parameters ( ) ) . device args = enc . inverse_info ( ) [ layername ] kwargs_out = { k : v for k , v in args . items ( ) if k != 'first_layer' } kwargs_out . update ( kwargs ) if 'x_weight' not in kwargs_out : kwargs_out [ 'x_weight' ] = 0 nethook . set_requires_grad ( False , layers , prev_layers , next_layers ) if combine_z is not None : nethook . set_requires_grad ( False , combine_z ) prev_layers_old = prev_layers prev_layers = lambda * a : prev_layers_old ( combine_z ( * a ) ) zsampler = infinite_sampler ( dists , prev_layers , batch_size , device ) tsample = test_sampler ( dists , prev_layers , batch_size , test_batches , device ) train_inverse ( inv , layers , zsampler , test_sampler = tsample , resume_from = resume_from , checkpoint_dir = checkpoint_dir , logfile = logfile , * * kwargs_out )