def phi(x): _ = x / 255.0 # Nature structure with O.argscope(O.conv2d, nonlin=O.relu): _ = O.conv2d('conv1', _, 32, 8, stride=4) _ = O.conv2d('conv2', _, 64, 4, stride=2) _ = O.conv2d('conv3', _, 64, 3, stride=1) return _
def forward_conv(x): _ = x / 255.0 with O.argscope(O.conv2d, nonlin=O.relu): _ = O.conv2d('conv0', _, 32, 5) _ = O.max_pooling2d('pool0', _, 2) _ = O.conv2d('conv1', _, 32, 5) _ = O.max_pooling2d('pool1', _, 2) _ = O.conv2d('conv2', _, 64, 4) _ = O.max_pooling2d('pool2', _, 2) _ = O.conv2d('conv3', _, 64, 3) return _
def forward(x): _ = x / 255.0 with O.argscope(O.conv2d, nonlin=O.relu): _ = O.conv2d('conv0', _, 32, 5) _ = O.max_pooling2d('pool0', _, 2) _ = O.conv2d('conv1', _, 32, 5) _ = O.max_pooling2d('pool1', _, 2) _ = O.conv2d('conv2', _, 64, 4) _ = O.max_pooling2d('pool2', _, 2) _ = O.conv2d('conv3', _, 64, 3) dpc.add_output(_, name='feature')
def encoder(x, nonlin): w_init = O.truncated_normal_initializer(stddev=0.02) with O.argscope(O.conv2d, O.deconv2d, kernel=4, stride=2, W=w_init),\ O.argscope(O.leaky_relu, alpha=0.2): _ = x _ = O.conv2d('conv1', _, 64, nonlin=O.leaky_relu) _ = O.conv2d('conv2', _, 128, nonlin=nonlin, use_bias=False) _ = O.conv2d('conv3', _, 256, nonlin=nonlin, use_bias=False) _ = O.conv2d('conv4', _, 512, nonlin=nonlin, use_bias=False) z = _ return z
def discriminator(img): w_init = O.truncated_normal_initializer(stddev=0.02) with O.argscope(O.conv2d, O.deconv2d, kernel=4, stride=2, W=w_init),\ O.argscope(O.fc, W=w_init),\ O.argscope(O.leaky_relu, alpha=0.2): _ = img _ = O.conv2d('conv1', _, 64, nonlin=O.leaky_relu) _ = O.conv2d('conv2', _, 128, nonlin=O.bn_nonlin) _ = O.leaky_relu(_) _ = O.fc('fc1', _, 1024, nonlin=O.bn_nonlin) _ = O.leaky_relu(_) _ = O.fc('fct', _, 1) return _
def forward(img): _ = img _ = O.conv2d('conv1', _, 16, (3, 3), padding='SAME', nonlin=O.relu) _ = O.pooling2d('pool1', _, kernel=2) _ = O.conv2d('conv2', _, 32, (3, 3), padding='SAME', nonlin=O.relu) _ = O.pooling2d('pool2', _, kernel=2) dpc.add_output(_, name='feature')
def forward(img): _ = img _ = O.conv2d('conv1', _, 16, (3, 3), padding='SAME', nonlin=O.identity) _ = O.batch_norm('bn1', _) _ = O.relu(_) _ = O.pooling2d('pool1', _, kernel=2) _ = O.conv2d('conv2', _, 32, (3, 3), padding='SAME', nonlin=O.identity) _ = O.batch_norm('bn2', _) _ = O.relu(_) _ = O.pooling2d('pool2', _, kernel=2) dpc.add_output(_, name='feature')
def discriminator(img): w_init = O.truncated_normal_initializer(stddev=0.02) with O.argscope(O.conv2d, O.deconv2d, kernel=4, stride=2, W=w_init),\ O.argscope(O.fc, W=w_init),\ O.argscope(O.leaky_relu, alpha=0.2): _ = img _ = O.conv2d('conv1', _, 64, nonlin=O.leaky_relu) _ = O.conv2d('conv2', _, 128, nonlin=O.bn_nonlin) _ = O.leaky_relu(_) _ = O.fc('fc1', _, 1024, nonlin=O.bn_nonlin) _ = O.leaky_relu(_) with env.variable_scope('score'): logits = O.fc('fct', _, 1) with env.variable_scope('code'): _ = O.fc('fc1', _, 128, nonlin=O.bn_nonlin) _ = O.leaky_relu(_) code = O.fc('fc2', _, zc_distrib.param_size) return logits, code
def forward(img): _ = img _ = O.conv2d('conv1', _, 4, (3, 3), stride=2, padding='SAME', nonlin=O.relu) # shape = (14, 14) _ = O.conv2d('conv2', _, 8, (3, 3), stride=2, padding='SAME', nonlin=O.relu) # shape = (7, 7) _ = O.fc('fc', _, 392) _ = _.reshape([-1, 7, 7, 8]) _ = O.deconv2d('deconv1', _, 4, (3, 3), stride=2, padding='SAME', nonlin=O.relu) # shape = (14, 14) _ = O.deconv2d('deconv2', _, 1, (3, 3), stride=2, padding='SAME', nonlin=O.sigmoid) # shape = (28, 28) out = _ loss = O.raw_cross_entropy_prob('raw_loss', out, img) loss = O.get_pn_balanced_loss('loss', loss, img) dpc.add_output(out, name='output') dpc.add_output(loss, name='loss', reduce_method='sum')
def stacked_conv(prefix, nr_convs, in_, channel, kernel=(3, 3), padding='SAME', nonlin=O.relu): for i in range(1, nr_convs + 1): in_ = O.conv2d('{}_{}'.format(prefix, i), in_, channel, kernel, padding=padding, nonlin=nonlin) return in_