style-GAN Generator 代码解析

style-GAN Generator 代码解析

PART 2 of Sefa study:

对于style-GAN Generator部分的代码解析

<在这里插入图片描述

代码主要分为两个部分:

  • Mapping network
  • Synthesis network

Mapping主要网络组块在 c l a s s D e n s e B l o c k ( ) class\quad DenseBlock() classDenseBlock()

Synthesis主要的网络组块在 c l a s s C o n v B l o c k ( ) class\quad ConvBlock() classConvBlock()依靠输入参数(‘position’)不同进行调整

最后组装为 c l a s s   S t y l e G A N G e n e r a t o r ( n n . M o d u l e ) class\,StyleGANGenerator(nn.Module) classStyleGANGenerator(nn.Module)

StyleGAN部分

分辨率resolution在 2 3 ∼ 2 10 2^3\sim 2^{10} 23210

将潜变量空间$z\in Z(dim=512)\rightarrow w\in W(dim=512) $

n u m _ l a y e r s = l o g 2 ( 2 ⋅ r e s 4 ) ∗ 2 num\_layers=log_2(\frac{2\cdot res}{4})*2 num_layers=log2(42res)2

  • 输入 z : d i m = 2 , s h a p e = [ z . s h a p e [ 0 ] , 512 ] z:dim=2,shape=[z.shape[0],512] z:dim=2,shape=[z.shape[0],512]

  • 先过mapping层得到dict{‘z’: z;‘label’:None;‘w’:w}

    其中 z = p i x e l _ n o r m ( z ) z=pixel\_norm(z) z=pixel_norm(z)

    z z z过8层 F C FC FC,维度不变Linear+relu 变成w

    保持输入输出channels=512, w : [ z . s h a p e [ 0 ] , 512 ] w:[z.shape[0],512] w:[z.shape[0],512]

    self.add_module(f'dense{
           i}',
    				DenseBlock(in_channels=in_channels,
                               out_channels=out_channels,
                               use_wscale=self.use_wscale,#=True
                               lr_mul=self.lr_mul))#=0.01
    
  • 两个tricks(option):

    • truncation(self.training=True进行自学习,用truncation技巧处理每层得到的w)

      ps:其中使用all_gather函数源自.sync_op.py文件,主要把分布运算的w汇总求均值 w ˉ \bar w wˉ

    • style_mix (有0.9的可能性在任意mapping层以后用新的z在后面层产生的w代替原来这些层的w)

  • 一层truncation:

    • l a y e r _ n u m = l o g 2 ( 2 ⋅ r e s o l u t i o n 4 ) ∗ 2 layer\_num=log_2(\frac{2\cdot resolution}{4})*2 layer_num=log2(42re
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值