By the way, PGGAN is one of the “growing layer by layer” network. Here’s its implemetation, using add_module

  
      github.com
  
  
    nashory/pggan-pytorch/blob/070cc23c7f1ba57122d0140cbe129f13f8021c1d/network.py#L126-L151

def grow_network(self, resl):    # we make new network since pytorch does not support remove_module()    new_model = nn.Sequential()    names = get_module_names(self.model)    for name, module in self.model.named_children():        if not name=='to_rgb_block':            new_model.add_module(name, module)                      # make new structure and,            new_model[-1].load_state_dict(module.state_dict())      # copy pretrained weights            if resl >= 3 and resl <= 9:        print('growing network[{}x{} to {}x{}]. It may take few seconds...'.format(int(pow(2,resl-1)), int(pow(2,resl-1)), int(pow(2,resl)), int(pow(2,resl))))        low_resl_to_rgb = deepcopy_module(self.model, 'to_rgb_block')        prev_block = nn.Sequential()        prev_block.add_module('low_resl_upsample', nn.Upsample(scale_factor=2, mode='nearest'))        prev_block.add_module('low_resl_to_rgb', low_resl_to_rgb)        inter_block, ndim, self.layer_name = self.intermediate_block(resl)        next_block = nn.Sequential()        next_block.add_module('high_resl_block', inter_block)        next_block.add_module('high_resl_to_rgb', self.to_rgb_block(ndim))


  This file has been truncated. show original