我想训练一个从图片中去除划痕的神经网络。我选择了一个带有生成器 (G) 和鉴别器 (D) 的 GAN 架构,以及具有相似动机的两组粗糙和不粗糙的图像。G 在我的设置中主要使用卷积和反卷积层ReLU。作为输入,它使用粗糙的图像。D 区分 G 的输出和非划痕图像。
例如,生成器将执行以下转换:
(128, 128, 3) > (128, 128, 128) > (128, 128, 3)
元组包含(宽度、高度、通道)的位置。输入和输出需要具有相同的格式。
但是为了获得与输入具有相同全局结构的输出(即街道、房屋等),我似乎必须使用过滤器大小和步幅为 1,并且基本上通过网络传递完整的图片。
但是,我正在查看的功能相当小且本地化。对卷积使用最大 20 像素大小的过滤器就足够了。然后将网络应用到输入图片的所有部分。
对于这样的任务,什么是好的生成器架构?您是否同意生成器的结构,或者您是否希望不同的设计在局部更改上表现更好?
这是我在 tensorflow 中使用的生成器的代码。
def generator(x, batch_size, reuse=False):
with tf.variable_scope('generator') as scope:
if (reuse):
tf.get_variable_scope().reuse_variables()
s = 1
f = 1
assert ((WIDTH + f - 1) / s) % 1 == 0
keep_prob = 0.5
n_ch1 = 32
w = init_weights('g_wc1', [f, f, CHANNELS, n_ch1])
b = init_bias('g_bc1', [n_ch1])
h = conv2d(x, w, s, b)
h = bn(h, 'g_bn1')
h = tf.nn.relu(h)
h = tf.nn.dropout(h, keep_prob)
h1 = h
n_ch2 = 128
w = init_weights('g_wc2', [f, f, n_ch1, n_ch2])
b = init_bias('g_bc2', [n_ch2])
h = conv2d(h, w, s, b)
h = bn(h, "g_bn2")
h = tf.nn.relu(h)
h = tf.nn.dropout(h, keep_prob)
h2 = h
n_ch3 = 256
w = init_weights('g_wc3', [f, f, n_ch2, n_ch3])
b = init_bias('g_bc3', [n_ch3])
h = conv2d(h, w, s, b)
h = bn(h, "g_bn3")
h = tf.nn.relu(h)
h = tf.nn.dropout(h, keep_prob)
output_shape = [batch_size, HEIGHT//s//s, WIDTH//s//s, n_ch2]
w = init_weights('g_wdc3', [f, f, n_ch2, n_ch3])
b = init_bias('g_bdc3', [n_ch2])
h = deconv2d(h, w, s, b, output_shape)
h = bn(h, "g_bnd3")
h = tf.nn.relu(h)
h = h + h2
output_shape = [batch_size, HEIGHT//s, WIDTH//s, n_ch1]
w = init_weights('g_wdc2', [f, f, n_ch1, n_ch2])
b = init_bias('g_bdc2', [n_ch1])
h = deconv2d(h, w, s, b, output_shape)
h = bn(h, "g_bnd2")
h = tf.nn.relu(h)
h = h + h1
output_shape = [batch_size, HEIGHT, WIDTH, CHANNELS]
w = init_weights('g_wdc1', [f, f, CHANNELS, n_ch1])
b = init_bias('g_bdc1', [CHANNELS])
h = deconv2d(h, w, s, b, output_shape)
return tf.nn.sigmoid(h+x)
当你使用跨步时s>1,你会得到一个沙漏,其中层变得更小但更深。深度由n_ch变量独立控制。
顺便说一句,我在 Google colab 笔记本上运行它。免费拥有这样的引擎并能够尝试深度学习,真是太棒了!极好的!
