def on_build(self, in_ch, d_ch, d_mask_ch, **kwargs): self.upscale0 = Upscale(in_ch, d_ch * 8, kernel_size=3) self.upscale1 = Upscale(d_ch * 8, d_ch * 4, kernel_size=3) self.upscale2 = Upscale(d_ch * 4, d_ch * 2, kernel_size=3) self.res0 = ResidualBlock(d_ch * 8, kernel_size=3) self.res1 = ResidualBlock(d_ch * 4, kernel_size=3) self.res2 = ResidualBlock(d_ch * 2, kernel_size=3) self.out_conv = nn.Conv2D(d_ch * 2, 3, kernel_size=1, padding='SAME') self.upscalem0 = Upscale(in_ch, d_mask_ch * 8, kernel_size=3) self.upscalem1 = Upscale(d_mask_ch * 8, d_mask_ch * 4, kernel_size=3) self.upscalem2 = Upscale(d_mask_ch * 4, d_mask_ch * 2, kernel_size=3) self.out_convm = nn.Conv2D(d_mask_ch * 2, 1, kernel_size=1, padding='SAME')
def on_build(self, patch_size, in_ch, base_ch = 16, use_fp16 = False): self.use_fp16 = use_fp16 conv_dtype = tf.float16 if use_fp16 else tf.float32 class ResidualBlock(nn.ModelBase): def on_build(self, ch, kernel_size=3 ): self.conv1 = nn.Conv2D( ch, ch, kernel_size=kernel_size, padding='SAME', dtype=conv_dtype) self.conv2 = nn.Conv2D( ch, ch, kernel_size=kernel_size, padding='SAME', dtype=conv_dtype) def forward(self, inp): x = self.conv1(inp) x = tf.nn.leaky_relu(x, 0.2) x = self.conv2(x) x = tf.nn.leaky_relu(inp + x, 0.2) return x prev_ch = in_ch self.convs = [] self.upconvs = [] layers = self.find_archi(patch_size) level_chs = { i-1:v for i,v in enumerate([ min( base_ch * (2**i), 512 ) for i in range(len(layers)+1)]) } self.in_conv = nn.Conv2D( in_ch, level_chs[-1], kernel_size=1, padding='VALID', dtype=conv_dtype) for i, (kernel_size, strides) in enumerate(layers): self.convs.append ( nn.Conv2D( level_chs[i-1], level_chs[i], kernel_size=kernel_size, strides=strides, padding='SAME', dtype=conv_dtype) ) self.upconvs.insert (0, nn.Conv2DTranspose( level_chs[i]*(2 if i != len(layers)-1 else 1), level_chs[i-1], kernel_size=kernel_size, strides=strides, padding='SAME', dtype=conv_dtype) ) self.out_conv = nn.Conv2D( level_chs[-1]*2, 1, kernel_size=1, padding='VALID', dtype=conv_dtype) self.center_out = nn.Conv2D( level_chs[len(layers)-1], 1, kernel_size=1, padding='VALID', dtype=conv_dtype) self.center_conv = nn.Conv2D( level_chs[len(layers)-1], level_chs[len(layers)-1], kernel_size=1, padding='VALID', dtype=conv_dtype)
def on_build(self, in_ch, d_ch, d_mask_ch): self.upscale0 = Upscale(in_ch, d_ch * 8, kernel_size=3) self.upscale1 = Upscale(d_ch * 8, d_ch * 4, kernel_size=3) self.upscale2 = Upscale(d_ch * 4, d_ch * 2, kernel_size=3) self.upscale3 = Upscale(d_ch * 2, d_ch * 1, kernel_size=3) self.res0 = ResidualBlock(d_ch * 8, kernel_size=3) self.res1 = ResidualBlock(d_ch * 4, kernel_size=3) self.res2 = ResidualBlock(d_ch * 2, kernel_size=3) self.res3 = ResidualBlock(d_ch * 1, kernel_size=3) self.out_conv = nn.Conv2D( d_ch * 1, 3, kernel_size=1, padding='SAME', kernel_initializer=conv_kernel_initializer) self.upscalem0 = Upscale(in_ch, d_mask_ch * 8, kernel_size=3) self.upscalem1 = Upscale(d_mask_ch * 8, d_mask_ch * 4, kernel_size=3) self.upscalem2 = Upscale(d_mask_ch * 4, d_mask_ch * 2, kernel_size=3) self.upscalem3 = Upscale(d_mask_ch * 2, d_mask_ch * 1, kernel_size=3) self.out_convm = nn.Conv2D( d_mask_ch * 1, 1, kernel_size=1, padding='SAME', kernel_initializer=conv_kernel_initializer)
def on_build(self): self.conv1 = nn.Conv2D (3, 64, kernel_size=7, strides=2, padding='SAME') self.bn1 = nn.BatchNorm2D(64) self.conv2 = ConvBlock(64, 128) self.conv3 = ConvBlock(128, 128) self.conv4 = ConvBlock(128, 256) self.m = [] self.top_m = [] self.conv_last = [] self.bn_end = [] self.l = [] self.bl = [] self.al = [] for i in range(4): self.m += [ HourGlass(256, 4) ] self.top_m += [ ConvBlock(256, 256) ] self.conv_last += [ nn.Conv2D (256, 256, kernel_size=1, strides=1, padding='VALID') ] self.bn_end += [ nn.BatchNorm2D(256) ] self.l += [ nn.Conv2D (256, 68, kernel_size=1, strides=1, padding='VALID') ] if i < 4-1: self.bl += [ nn.Conv2D (256, 256, kernel_size=1, strides=1, padding='VALID') ] self.al += [ nn.Conv2D (68, 256, kernel_size=1, strides=1, padding='VALID') ]
def on_build(self, in_ch, d_ch): self.upscale0_1 = Upscale(in_ch, d_ch * 1) self.upscale0_2 = Upscale(d_ch * 1, d_ch * 1) self.upscale0_3 = Upscale(d_ch * 1, d_ch * 1) self.out0 = nn.Conv2D( d_ch * 1, 3, kernel_size=1, padding='SAME', kernel_initializer=conv_kernel_initializer) self.upscale1_1 = Upscale(in_ch, d_ch * 1) self.upscale1_2 = Upscale(d_ch * 2, d_ch * 1) self.upscale1_3 = Upscale(d_ch * 2, d_ch * 1) self.out1 = nn.Conv2D( d_ch * 2, 3, kernel_size=1, padding='SAME', kernel_initializer=conv_kernel_initializer) self.upscalem1 = Upscale(in_ch, d_ch) self.upscalem2 = Upscale(d_ch, d_ch // 2) self.upscalem3 = Upscale(d_ch // 2, d_ch // 2) self.outm = nn.Conv2D( d_ch // 2, 1, kernel_size=1, padding='SAME', kernel_initializer=conv_kernel_initializer)
def on_build(self, in_ch): self.upscale6 = Upscale(in_ch, in_ch//2) self.upscale5 = Upscale(in_ch//2, in_ch//4) self.upscale4 = Upscale(in_ch//4, in_ch//8) self.upscale3 = Upscale(in_ch//8, in_ch//16) self.upscale2 = Upscale(in_ch//16, in_ch//32) #self.upscale1 = Upscale(in_ch//32, in_ch//64) self.out_conv = nn.Conv2D( in_ch//32, 3, kernel_size=1, padding='SAME', kernel_initializer=conv_kernel_initializer) self.res61 = ResidualBlock(in_ch//2, mod=8) self.res62 = ResidualBlock(in_ch//2, mod=8) self.res63 = ResidualBlock(in_ch//2, mod=8) self.res51 = ResidualBlock(in_ch//4, mod=8) self.res52 = ResidualBlock(in_ch//4, mod=8) self.res53 = ResidualBlock(in_ch//4, mod=8) self.res41 = ResidualBlock(in_ch//8, mod=8) self.res42 = ResidualBlock(in_ch//8, mod=8) self.res43 = ResidualBlock(in_ch//8, mod=8) self.res31 = ResidualBlock(in_ch//16, mod=8) self.res32 = ResidualBlock(in_ch//16, mod=8) self.res33 = ResidualBlock(in_ch//16, mod=8) self.res21 = ResidualBlock(in_ch//32, mod=8) self.res22 = ResidualBlock(in_ch//32, mod=8) self.res23 = ResidualBlock(in_ch//32, mod=8) m_ch = in_ch//2 self.upscalem6 = Upscale(in_ch, m_ch//2) self.upscalem5 = Upscale(m_ch//2, m_ch//4) self.upscalem4 = Upscale(m_ch//4, m_ch//8) self.upscalem3 = Upscale(m_ch//8, m_ch//16) self.upscalem2 = Upscale(m_ch//16, m_ch//32) #self.upscalem1 = Upscale(m_ch//32, m_ch//64) self.out_convm = nn.Conv2D( m_ch//32, 1, kernel_size=1, padding='SAME', kernel_initializer=conv_kernel_initializer)
def on_build(self, patch_size, in_ch, base_ch=None, conv_kernel_initializer=None): suggested_base_ch, kernels_strides = patch_discriminator_kernels[ patch_size] if base_ch is None: base_ch = suggested_base_ch prev_ch = in_ch self.convs = [] for i, (kernel_size, strides) in enumerate(kernels_strides): cur_ch = base_ch * min((2**i), 8) self.convs.append( nn.Conv2D(prev_ch, cur_ch, kernel_size=kernel_size, strides=strides, padding='SAME', kernel_initializer=conv_kernel_initializer)) prev_ch = cur_ch self.out_conv = nn.Conv2D(prev_ch, 1, kernel_size=1, padding='VALID', kernel_initializer=conv_kernel_initializer)
def on_build(self): in_ch, ae_ch = self.in_ch, self.ae_ch self.dense_conv1 = nn.Conv2D( in_ch, 64, kernel_size=1, padding='SAME', kernel_initializer=conv_kernel_initializer) self.dense_conv2 = nn.Conv2D( 64, in_ch, kernel_size=1, padding='SAME', kernel_initializer=conv_kernel_initializer) self.conv7 = Upscale(in_ch, in_ch//2) self.conv6 = Upscale(in_ch//2, in_ch//4)
def on_build(self, ch, kernel_size=3): self.conv1 = nn.Conv2D(ch, ch, kernel_size=kernel_size, padding='SAME') self.conv2 = nn.Conv2D(ch, ch, kernel_size=kernel_size, padding='SAME')
def on_build(self, ch, kernel_size=3): self.conv1 = nn.Conv2D(ch, ch * 2, kernel_size=kernel_size, padding='SAME') self.conv2 = nn.Conv2D(ch * 2, ch, kernel_size=kernel_size, padding='SAME') self.scale_add = nn.ScaleAdd(ch)
def on_build(self, in_ch, out_ch, level): self.zero_level = level == 0 self.conv1 = nn.Conv2D( in_ch, out_ch, kernel_size=4 if self.zero_level else 3, padding=3 if self.zero_level else 'SAME') self.conv2 = nn.Conv2D(out_ch, out_ch, kernel_size=3, padding='SAME')
def on_build(self, in_ch, code_res, ch=256): n_downscales = 2 + code_res // 8 self.convs = [] prev_ch = in_ch for i in range(n_downscales): cur_ch = ch * min( (2**i), 8 ) self.convs.append ( nn.Conv2D( prev_ch, cur_ch, kernel_size=4 if i == 0 else 3, strides=2, padding='SAME', kernel_initializer=conv_kernel_initializer) ) prev_ch = cur_ch self.out_conv = nn.Conv2D( prev_ch, 1, kernel_size=1, padding='VALID', kernel_initializer=conv_kernel_initializer)
def on_build(self, ch, kernel_size=3): self.conv1 = nn.Conv2D( ch, ch, kernel_size=kernel_size, padding='SAME', kernel_initializer=conv_kernel_initializer) self.conv2 = nn.Conv2D( ch, ch, kernel_size=kernel_size, padding='SAME', kernel_initializer=conv_kernel_initializer)
def on_build(self, in_ch, d_ch): self.upscale1 = Upscale(in_ch, d_ch*4) self.res1 = ResidualBlock(d_ch*4) self.upscale2 = Upscale(d_ch*4, d_ch*2) self.res2 = ResidualBlock(d_ch*2) self.upscale3 = Upscale(d_ch*2, d_ch*1) self.res3 = ResidualBlock(d_ch*1) self.upscalem1 = Upscale(in_ch, d_ch) self.upscalem2 = Upscale(d_ch, d_ch//2) self.upscalem3 = Upscale(d_ch//2, d_ch//2) self.out_conv = nn.Conv2D( d_ch*1, 3, kernel_size=1, padding='SAME') self.out_convm = nn.Conv2D( d_ch//2, 1, kernel_size=1, padding='SAME')
def on_build(self, in_ch, out_ch): self.conv = nn.Conv2D(in_ch, out_ch, kernel_size=3, padding='SAME') self.frn = nn.FRNorm2D(out_ch) self.tlu = nn.TLU(out_ch)
def on_build(self, base_ch, out_ch): self.up4 = UpConvBlock(base_ch * 8, base_ch * 4) self.conv43 = ConvBlock(base_ch * 12, base_ch * 8) self.conv42 = ConvBlock(base_ch * 8, base_ch * 8) self.conv41 = ConvBlock(base_ch * 8, base_ch * 8) self.up3 = UpConvBlock(base_ch * 8, base_ch * 4) self.conv33 = ConvBlock(base_ch * 12, base_ch * 8) self.conv32 = ConvBlock(base_ch * 8, base_ch * 8) self.conv31 = ConvBlock(base_ch * 8, base_ch * 8) self.up2 = UpConvBlock(base_ch * 8, base_ch * 4) self.conv23 = ConvBlock(base_ch * 8, base_ch * 4) self.conv22 = ConvBlock(base_ch * 4, base_ch * 4) self.conv21 = ConvBlock(base_ch * 4, base_ch * 4) self.up1 = UpConvBlock(base_ch * 4, base_ch * 2) self.conv12 = ConvBlock(base_ch * 4, base_ch * 2) self.conv11 = ConvBlock(base_ch * 2, base_ch * 2) self.up0 = UpConvBlock(base_ch * 2, base_ch) self.conv02 = ConvBlock(base_ch * 2, base_ch) self.conv01 = ConvBlock(base_ch, base_ch) self.out_conv = nn.Conv2D(base_ch, out_ch, kernel_size=3, padding='SAME')
def on_build(self, in_ch, out_ch, kernel_size=3): self.conv1 = nn.Conv2D( in_ch, out_ch * 4, kernel_size=kernel_size, padding='SAME', kernel_initializer=conv_kernel_initializer)
def on_build(self, *args, **kwargs): self.conv1 = nn.Conv2D(self.in_ch, self.out_ch, kernel_size=self.kernel_size, strides=2, padding='SAME', dtype=conv_dtype)
def on_build(self, *args, **kwargs): self.conv1 = nn.Conv2D(self.in_ch, self.out_ch // (4 if self.subpixel else 1), kernel_size=self.kernel_size, strides=1 if self.subpixel else 2, padding='SAME', dilations=self.dilations)
def on_build(self, in_ch, d_ch, d_mask_ch): self.upscale0 = Upscale(in_ch, d_ch * 8, kernel_size=3) self.upscale1 = Upscale(d_ch * 8, d_ch * 4, kernel_size=3) self.upscale2 = Upscale(d_ch * 4, d_ch * 2, kernel_size=3) self.res0 = ResidualBlock(d_ch * 8, kernel_size=3) self.res1 = ResidualBlock(d_ch * 4, kernel_size=3) self.res2 = ResidualBlock(d_ch * 2, kernel_size=3) self.out_conv = nn.Conv2D(d_ch * 2, 3, kernel_size=1, padding='SAME', dtype=conv_dtype) self.upscalem0 = Upscale(in_ch, d_mask_ch * 8, kernel_size=3) self.upscalem1 = Upscale(d_mask_ch * 8, d_mask_ch * 4, kernel_size=3) self.upscalem2 = Upscale(d_mask_ch * 4, d_mask_ch * 2, kernel_size=3) self.out_convm = nn.Conv2D(d_mask_ch * 2, 1, kernel_size=1, padding='SAME', dtype=conv_dtype) if 'd' in opts: self.out_conv1 = nn.Conv2D(d_ch * 2, 3, kernel_size=3, padding='SAME', dtype=conv_dtype) self.out_conv2 = nn.Conv2D(d_ch * 2, 3, kernel_size=3, padding='SAME', dtype=conv_dtype) self.out_conv3 = nn.Conv2D(d_ch * 2, 3, kernel_size=3, padding='SAME', dtype=conv_dtype) self.upscalem3 = Upscale(d_mask_ch * 2, d_mask_ch * 1, kernel_size=3) self.out_convm = nn.Conv2D(d_mask_ch * 1, 1, kernel_size=1, padding='SAME', dtype=conv_dtype) else: self.out_convm = nn.Conv2D(d_mask_ch * 2, 1, kernel_size=1, padding='SAME', dtype=conv_dtype)
def on_build(self, *args, **kwargs): self.conv1 = nn.Conv2D( self.in_ch, self.out_ch, kernel_size=self.kernel_size, strides=2, padding='SAME', dilations=self.dilations, kernel_initializer=conv_kernel_initializer)
def on_build(self, in_planes, out_planes): self.in_planes = in_planes self.out_planes = out_planes self.bn1 = nn.BatchNorm2D(in_planes) self.conv1 = nn.Conv2D (in_planes, out_planes//2, kernel_size=3, strides=1, padding='SAME', use_bias=False ) self.bn2 = nn.BatchNorm2D(out_planes//2) self.conv2 = nn.Conv2D (out_planes//2, out_planes//4, kernel_size=3, strides=1, padding='SAME', use_bias=False ) self.bn3 = nn.BatchNorm2D(out_planes//4) self.conv3 = nn.Conv2D (out_planes//4, out_planes//4, kernel_size=3, strides=1, padding='SAME', use_bias=False ) if self.in_planes != self.out_planes: self.down_bn1 = nn.BatchNorm2D(in_planes) self.down_conv1 = nn.Conv2D (in_planes, out_planes, kernel_size=1, strides=1, padding='VALID', use_bias=False ) else: self.down_bn1 = None self.down_conv1 = None
def on_build(self, in_ch, d_ch, d_mask_ch, is_hd): self.is_hd = is_hd self.upscale0 = Upscale(in_ch, d_ch * 8, kernel_size=3) self.upscale1 = Upscale(d_ch * 8, d_ch * 4, kernel_size=3) self.upscale2 = Upscale(d_ch * 4, d_ch * 2, kernel_size=3) if is_hd: self.res0 = UpdownResidualBlock(in_ch, d_ch * 8, kernel_size=3) self.res1 = UpdownResidualBlock(d_ch * 8, d_ch * 4, kernel_size=3) self.res2 = UpdownResidualBlock(d_ch * 4, d_ch * 2, kernel_size=3) self.res3 = UpdownResidualBlock(d_ch * 2, d_ch, kernel_size=3) else: self.res0 = ResidualBlock(d_ch * 8, kernel_size=3) self.res1 = ResidualBlock(d_ch * 4, kernel_size=3) self.res2 = ResidualBlock(d_ch * 2, kernel_size=3) self.out_conv = nn.Conv2D(d_ch * 2, 3, kernel_size=1, padding='SAME') self.upscalem0 = Upscale(in_ch, d_mask_ch * 8, kernel_size=3) self.upscalem1 = Upscale(d_mask_ch * 8, d_mask_ch * 4, kernel_size=3) self.upscalem2 = Upscale(d_mask_ch * 4, d_mask_ch * 2, kernel_size=3) self.out_convm = nn.Conv2D(d_mask_ch * 2, 1, kernel_size=1, padding='SAME')
def on_build(self ): self.upscale0 = Upscale(inter_dims, d_dims*8, kernel_size=3) self.upscale1 = Upscale(d_dims*8, d_dims*8, kernel_size=3) self.upscale2 = Upscale(d_dims*8, d_dims*4, kernel_size=3) self.upscale3 = Upscale(d_dims*4, d_dims*2, kernel_size=3) self.res0 = ResidualBlock(d_dims*8, kernel_size=3) self.res1 = ResidualBlock(d_dims*8, kernel_size=3) self.res2 = ResidualBlock(d_dims*4, kernel_size=3) self.res3 = ResidualBlock(d_dims*2, kernel_size=3) self.upscalem0 = Upscale(inter_dims, d_mask_dims*8, kernel_size=3) self.upscalem1 = Upscale(d_mask_dims*8, d_mask_dims*8, kernel_size=3) self.upscalem2 = Upscale(d_mask_dims*8, d_mask_dims*4, kernel_size=3) self.upscalem3 = Upscale(d_mask_dims*4, d_mask_dims*2, kernel_size=3) self.upscalem4 = Upscale(d_mask_dims*2, d_mask_dims*1, kernel_size=3) self.out_convm = nn.Conv2D( d_mask_dims*1, 1, kernel_size=1, padding='SAME', dtype=conv_dtype) self.out_conv = nn.Conv2D( d_dims*2, 3, kernel_size=1, padding='SAME', dtype=conv_dtype) self.out_conv1 = nn.Conv2D( d_dims*2, 3, kernel_size=3, padding='SAME', dtype=conv_dtype) self.out_conv2 = nn.Conv2D( d_dims*2, 3, kernel_size=3, padding='SAME', dtype=conv_dtype) self.out_conv3 = nn.Conv2D( d_dims*2, 3, kernel_size=3, padding='SAME', dtype=conv_dtype)
def on_build(self, in_ch, base_ch, out_ch=None): self.convs = [ nn.Conv2D( in_ch, base_ch, kernel_size=7, strides=1, padding='SAME'), nn.Conv2D( base_ch, base_ch, kernel_size=3, strides=1, use_bias=False, padding='SAME'), nn.Conv2D( base_ch, base_ch*2, kernel_size=3, strides=2, use_bias=False, padding='SAME'), nn.Conv2D( base_ch*2, base_ch*2, kernel_size=3, strides=1, use_bias=False, padding='SAME'), nn.Conv2D( base_ch*2, base_ch*4, kernel_size=3, strides=2, use_bias=False, padding='SAME'), nn.Conv2D( base_ch*4, base_ch*4, kernel_size=3, strides=1, use_bias=False, padding='SAME'), nn.Conv2D( base_ch*4, base_ch*8, kernel_size=3, strides=2, use_bias=False, padding='SAME'), nn.Conv2D( base_ch*8, base_ch*8, kernel_size=3, strides=1, use_bias=False, padding='SAME') ] self.frns = [ None, nn.FRNorm2D(base_ch), nn.FRNorm2D(base_ch*2), nn.FRNorm2D(base_ch*2), nn.FRNorm2D(base_ch*4), nn.FRNorm2D(base_ch*4), nn.FRNorm2D(base_ch*8), nn.FRNorm2D(base_ch*8), ] self.tlus = [ nn.TLU(base_ch), nn.TLU(base_ch), nn.TLU(base_ch*2), nn.TLU(base_ch*2), nn.TLU(base_ch*4), nn.TLU(base_ch*4), nn.TLU(base_ch*8), nn.TLU(base_ch*8), ] if out_ch is not None: self.out_conv = nn.Conv2D( base_ch*8, out_ch, kernel_size=1, strides=1, use_bias=False, padding='VALID') else: self.out_conv = None
def on_build(self, in_ch, d_ch, d_mask_ch, n_upscales=4): self.ups = [] self.res = [] self.upms = [] last_ch = in_ch last_ch_m = in_ch kernel_size = 3 for i in reversed(range(1, n_upscales)): cur_ch = d_ch * (min(2**i, 8)) m_cur_ch = d_mask_ch * (min(2**i, 8)) self.ups.append( Upscale(last_ch, cur_ch, kernel_size=kernel_size)) self.res.append(ResidualBlock(cur_ch, kernel_size=3)) self.upms.append( Upscale(last_ch_m, m_cur_ch, kernel_size=kernel_size)) last_ch = self.ups[-1].get_out_ch() last_ch_m = self.upms[-1].get_out_ch() self.out_conv = nn.Conv2D(d_ch * 2, 3, kernel_size=1, padding='SAME') if 'd' in opts: self.out_conv1 = nn.Conv2D(d_ch * 2, 3, kernel_size=3, padding='SAME') self.out_conv2 = nn.Conv2D(d_ch * 2, 3, kernel_size=3, padding='SAME') self.out_conv3 = nn.Conv2D(d_ch * 2, 3, kernel_size=3, padding='SAME') self.upscalem3 = Upscale(d_mask_ch * 2, d_mask_ch * 1, kernel_size=3) self.out_convm = nn.Conv2D(d_mask_ch * 1, 1, kernel_size=1, padding='SAME') else: self.out_convm = nn.Conv2D(d_mask_ch * 2, 1, kernel_size=1, padding='SAME')
def on_build(self, lmrks_ch, base_ch, out_ch): self.convs = [ nn.Conv2D( base_ch*8+lmrks_ch, base_ch*8, kernel_size=3, strides=1, use_bias=False, padding='SAME'), nn.Conv2D( base_ch*8, base_ch*8*4, kernel_size=3, strides=1, use_bias=False, padding='SAME'), nn.Conv2D( base_ch*8, base_ch*4, kernel_size=3, strides=1, use_bias=False, padding='SAME'), nn.Conv2D( base_ch*4, base_ch*4*4, kernel_size=3, strides=1, use_bias=False, padding='SAME'), nn.Conv2D( base_ch*4, base_ch*2, kernel_size=3, strides=1, use_bias=False, padding='SAME'), nn.Conv2D( base_ch*2, base_ch*2*4, kernel_size=3, strides=1, use_bias=False, padding='SAME'), nn.Conv2D( base_ch*2, base_ch, kernel_size=3, strides=1, use_bias=False, padding='SAME'), ] self.frns = [ nn.FRNorm2D(base_ch*8), nn.FRNorm2D(base_ch*8*4), nn.FRNorm2D(base_ch*4), nn.FRNorm2D(base_ch*4*4), nn.FRNorm2D(base_ch*2), nn.FRNorm2D(base_ch*2*4), nn.FRNorm2D(base_ch), ] self.tlus = [ nn.TLU(base_ch*8), nn.TLU(base_ch*8*4), nn.TLU(base_ch*4), nn.TLU(base_ch*4*4), nn.TLU(base_ch*2), nn.TLU(base_ch*2*4), nn.TLU(base_ch), ] self.use_upscale = [ False, True, False, True, False, True, False, ] self.out_conv = nn.Conv2D( base_ch, out_ch, kernel_size=3, strides=1, padding='SAME')
def on_build(self, *args, **kwargs): self.conv1 = nn.Conv2D(self.in_ch, self.out_ch * 4, kernel_size=self.kernel_size, padding='SAME')
def on_build(self): self.conv1 = nn.Conv2D(3, 64, kernel_size=3, strides=1, padding='SAME') self.dense1 = nn.Dense(1, 64, use_bias=False) self.dense2 = nn.Dense(1, 64, use_bias=False) self.e0_conv0 = nn.Conv2D(64, 64, kernel_size=3, strides=1, padding='SAME') self.e0_conv1 = nn.Conv2D(64, 64, kernel_size=3, strides=1, padding='SAME') self.e1_conv0 = nn.Conv2D(64, 112, kernel_size=3, strides=1, padding='SAME') self.e1_conv1 = nn.Conv2D(112, 112, kernel_size=3, strides=1, padding='SAME') self.e2_conv0 = nn.Conv2D(112, 192, kernel_size=3, strides=1, padding='SAME') self.e2_conv1 = nn.Conv2D(192, 192, kernel_size=3, strides=1, padding='SAME') self.e3_conv0 = nn.Conv2D(192, 336, kernel_size=3, strides=1, padding='SAME') self.e3_conv1 = nn.Conv2D(336, 336, kernel_size=3, strides=1, padding='SAME') self.e4_conv0 = nn.Conv2D(336, 512, kernel_size=3, strides=1, padding='SAME') self.e4_conv1 = nn.Conv2D(512, 512, kernel_size=3, strides=1, padding='SAME') self.center_conv0 = nn.Conv2D(512, 512, kernel_size=3, strides=1, padding='SAME') self.center_conv1 = nn.Conv2D(512, 512, kernel_size=3, strides=1, padding='SAME') self.center_conv2 = nn.Conv2D(512, 512, kernel_size=3, strides=1, padding='SAME') self.center_conv3 = nn.Conv2D(512, 512, kernel_size=3, strides=1, padding='SAME') self.d4_conv0 = nn.Conv2D(1024, 512, kernel_size=3, strides=1, padding='SAME') self.d4_conv1 = nn.Conv2D(512, 512, kernel_size=3, strides=1, padding='SAME') self.d3_conv0 = nn.Conv2D(848, 512, kernel_size=3, strides=1, padding='SAME') self.d3_conv1 = nn.Conv2D(512, 512, kernel_size=3, strides=1, padding='SAME') self.d2_conv0 = nn.Conv2D(704, 288, kernel_size=3, strides=1, padding='SAME') self.d2_conv1 = nn.Conv2D(288, 288, kernel_size=3, strides=1, padding='SAME') self.d1_conv0 = nn.Conv2D(400, 160, kernel_size=3, strides=1, padding='SAME') self.d1_conv1 = nn.Conv2D(160, 160, kernel_size=3, strides=1, padding='SAME') self.d0_conv0 = nn.Conv2D(224, 96, kernel_size=3, strides=1, padding='SAME') self.d0_conv1 = nn.Conv2D(96, 96, kernel_size=3, strides=1, padding='SAME') self.out1x_conv0 = nn.Conv2D(96, 48, kernel_size=3, strides=1, padding='SAME') self.out1x_conv1 = nn.Conv2D(48, 3, kernel_size=3, strides=1, padding='SAME') self.dec2x_conv0 = nn.Conv2D(96, 96, kernel_size=3, strides=1, padding='SAME') self.dec2x_conv1 = nn.Conv2D(96, 96, kernel_size=3, strides=1, padding='SAME') self.out2x_conv0 = nn.Conv2D(96, 48, kernel_size=3, strides=1, padding='SAME') self.out2x_conv1 = nn.Conv2D(48, 3, kernel_size=3, strides=1, padding='SAME') self.dec4x_conv0 = nn.Conv2D(96, 72, kernel_size=3, strides=1, padding='SAME') self.dec4x_conv1 = nn.Conv2D(72, 72, kernel_size=3, strides=1, padding='SAME') self.out4x_conv0 = nn.Conv2D(72, 36, kernel_size=3, strides=1, padding='SAME') self.out4x_conv1 = nn.Conv2D(36, 3, kernel_size=3, strides=1, padding='SAME')
def on_build(self): self.minus = tf.constant([104,117,123], dtype=nn.floatx ) self.conv1_1 = nn.Conv2D(3, 64, kernel_size=3, strides=1, padding='SAME') self.conv1_2 = nn.Conv2D(64, 64, kernel_size=3, strides=1, padding='SAME') self.conv2_1 = nn.Conv2D(64, 128, kernel_size=3, strides=1, padding='SAME') self.conv2_2 = nn.Conv2D(128, 128, kernel_size=3, strides=1, padding='SAME') self.conv3_1 = nn.Conv2D(128, 256, kernel_size=3, strides=1, padding='SAME') self.conv3_2 = nn.Conv2D(256, 256, kernel_size=3, strides=1, padding='SAME') self.conv3_3 = nn.Conv2D(256, 256, kernel_size=3, strides=1, padding='SAME') self.conv4_1 = nn.Conv2D(256, 512, kernel_size=3, strides=1, padding='SAME') self.conv4_2 = nn.Conv2D(512, 512, kernel_size=3, strides=1, padding='SAME') self.conv4_3 = nn.Conv2D(512, 512, kernel_size=3, strides=1, padding='SAME') self.conv5_1 = nn.Conv2D(512, 512, kernel_size=3, strides=1, padding='SAME') self.conv5_2 = nn.Conv2D(512, 512, kernel_size=3, strides=1, padding='SAME') self.conv5_3 = nn.Conv2D(512, 512, kernel_size=3, strides=1, padding='SAME') self.fc6 = nn.Conv2D(512, 1024, kernel_size=3, strides=1, padding=3) self.fc7 = nn.Conv2D(1024, 1024, kernel_size=1, strides=1, padding='SAME') self.conv6_1 = nn.Conv2D(1024, 256, kernel_size=1, strides=1, padding='SAME') self.conv6_2 = nn.Conv2D(256, 512, kernel_size=3, strides=2, padding='SAME') self.conv7_1 = nn.Conv2D(512, 128, kernel_size=1, strides=1, padding='SAME') self.conv7_2 = nn.Conv2D(128, 256, kernel_size=3, strides=2, padding='SAME') self.conv3_3_norm = L2Norm(256) self.conv4_3_norm = L2Norm(512) self.conv5_3_norm = L2Norm(512) self.conv3_3_norm_mbox_conf = nn.Conv2D(256, 4, kernel_size=3, strides=1, padding='SAME') self.conv3_3_norm_mbox_loc = nn.Conv2D(256, 4, kernel_size=3, strides=1, padding='SAME') self.conv4_3_norm_mbox_conf = nn.Conv2D(512, 2, kernel_size=3, strides=1, padding='SAME') self.conv4_3_norm_mbox_loc = nn.Conv2D(512, 4, kernel_size=3, strides=1, padding='SAME') self.conv5_3_norm_mbox_conf = nn.Conv2D(512, 2, kernel_size=3, strides=1, padding='SAME') self.conv5_3_norm_mbox_loc = nn.Conv2D(512, 4, kernel_size=3, strides=1, padding='SAME') self.fc7_mbox_conf = nn.Conv2D(1024, 2, kernel_size=3, strides=1, padding='SAME') self.fc7_mbox_loc = nn.Conv2D(1024, 4, kernel_size=3, strides=1, padding='SAME') self.conv6_2_mbox_conf = nn.Conv2D(512, 2, kernel_size=3, strides=1, padding='SAME') self.conv6_2_mbox_loc = nn.Conv2D(512, 4, kernel_size=3, strides=1, padding='SAME') self.conv7_2_mbox_conf = nn.Conv2D(256, 2, kernel_size=3, strides=1, padding='SAME') self.conv7_2_mbox_loc = nn.Conv2D(256, 4, kernel_size=3, strides=1, padding='SAME')