- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在训练 CGAN 从损坏的图像中重建图像。我已经为可变批量大小编写了所有代码,因此我也可以训练可变批量大小(我没有收到错误或任何错误)。当我使用 batch size 1 时,2 分钟后重建的图像不再有任何奇怪的伪影。然而,这是我的问题:对于任何其他批量大小,我都会得到非常奇怪的棋盘伪像,即使我尝试不同的学习率或训练多个小时也是如此。
This是训练一段时间后批量大小为 2 的重建图像。 (这些奇怪的工件不在损坏的数据中。)
This是批量大小为 2 时生成器损失的对抗分量。
This是批量大小为 2 时的生成器损失。
This是批量大小为 2 时的鉴别器损失。
为了比较,批量大小为 1:
橙色是训练,蓝色是验证
一旦批处理大小大于一个,我的代码似乎会做一些完全不同的事情。我确定批处理正在正确加载。我要疯了吗?
我的模型:
self.original = tf.placeholder(tf.float32, shape=(None,conf.fig_size, conf.fig_size, conf.fig_channel), name="original")
self.corrupted = tf.placeholder(tf.float32, shape=(None,conf.fig_size, conf.fig_size, conf.fig_channel), name="corrupted")
self.reconstructed = self.generator(self.corrupted)
pos = self.discriminator(self.original, self.corrupted, False)
neg = self.discriminator(self.original, self.corrupted, True)
pos_loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=pos, labels=tf.ones_like(pos)))
neg_loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=neg, labels=tf.zeros_like(neg)))
self.d_loss = pos_loss + neg_loss
adv_loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=neg, labels=tf.ones_like(neg)))
self.g_loss = adv_loss + conf.l1_lambda * tf.reduce_mean(tf.abs(self.original - self.reconstructed))
t_vars = tf.trainable_variables()
self.d_vars = [var for var in t_vars if 'disc' in var.name]
self.g_vars = [var for var in t_vars if 'gen' in var.name]
self.merged = tf.summary.merge_all()
def generator(self, corrupted):
conf = self.config
with tf.variable_scope("gen"):
feature = conf.conv_channel_base
e1 = conv2d(corrupted, feature, name="e1")
e2 = batch_norm(conv2d(lrelu(e1), feature*2, name="e2"), "e2", conf.batch_norm_decay)
e3 = batch_norm(conv2d(lrelu(e2), feature*4, name="e3"), "e3", conf.batch_norm_decay)
e4 = batch_norm(conv2d(lrelu(e3), feature*8, name="e4"), "e4", conf.batch_norm_decay)
e5 = batch_norm(conv2d(lrelu(e4), feature*8, name="e5"), "e5", conf.batch_norm_decay)
e6 = batch_norm(conv2d(lrelu(e5), feature*8, name="e6"), "e6", conf.batch_norm_decay)
e7 = batch_norm(conv2d(lrelu(e6), feature*8, name="e7"), "e7", conf.batch_norm_decay)
e8 = batch_norm(conv2d(lrelu(e7), feature*8, name="e8"), "e8", conf.batch_norm_decay)
size = conf.fig_size
num = [0] * 9
for i in range(1,9):
num[9-i]=size
size =(size+1)/2
d1 = deconv2d(tf.nn.relu(e8), [num[1],num[1],feature*8], name="d1")
d1 = tf.concat([tf.nn.dropout(batch_norm(d1, "d1", conf.batch_norm_decay), 0.5), e7], 3)
d2 = deconv2d(tf.nn.relu(d1), [num[2],num[2],feature*8], name="d2")
d2 = tf.concat([tf.nn.dropout(batch_norm(d2, "d2", conf.batch_norm_decay), 0.5), e6], 3)
d3 = deconv2d(tf.nn.relu(d2), [num[3],num[3],feature*8], name="d3")
d3 = tf.concat([tf.nn.dropout(batch_norm(d3, "d3", conf.batch_norm_decay), 0.5), e5], 3)
d4 = deconv2d(tf.nn.relu(d3), [num[4],num[4],feature*8], name="d4")
d4 = tf.concat([batch_norm(d4, "d4", conf.batch_norm_decay), e4], 3)
d5 = deconv2d(tf.nn.relu(d4), [num[5],num[5],feature*4], name="d5")
d5 = tf.concat([batch_norm(d5, "d5", conf.batch_norm_decay), e3], 3)
d6 = deconv2d(tf.nn.relu(d5), [num[6],num[6],feature*2], name="d6")
d6 = tf.concat([batch_norm(d6, "d6", conf.batch_norm_decay), e2], 3)
d7 = deconv2d(tf.nn.relu(d6), [num[7],num[7],feature], name="d7")
d7 = tf.concat([batch_norm(d7, "d7", conf.batch_norm_decay), e1], 3)
d8 = deconv2d(tf.nn.relu(d7), [num[8],num[8],conf.fig_channel], name="d8")
return tf.nn.tanh(d8)
def discriminator(self, original, corrupted, reuse):
conf = self.config
dim = len(original.get_shape())
with tf.variable_scope("disc", reuse=reuse):
image_pair = tf.concat([original, corrupted], dim - 1)
feature = conf.conv_channel_base
h0 = lrelu(conv2d(image_pair, feature, name="h0"))
h1 = lrelu(batch_norm(conv2d(h0, feature*2, name="h1"), "h1", conf.batch_norm_decay))
h2 = lrelu(batch_norm(conv2d(h1, feature*4, name="h2"), "h2", conf.batch_norm_decay))
h3 = lrelu(batch_norm(conv2d(h2, feature*8, name="h3"), "h3", conf.batch_norm_decay))
h4 = linear(tf.reshape(h3, [-1,h3.shape[1]*h3.shape[2]*h3.shape[3]]), 1, "linear")
return h4
def batch_norm(x, scope, decay):
return tf.contrib.layers.batch_norm(x, decay=decay, updates_collections=None, epsilon=1e-5, scale=True, scope=scope)
def conv2d(input, output_dim, k_h=4, k_w=4, d_h=2, d_w=2, stddev=0.02, name="conv2d"):
with tf.variable_scope(name):
weight = tf.get_variable('weight', [k_h, k_w, input.get_shape()[-1], output_dim],
initializer=tf.truncated_normal_initializer(stddev=stddev))
bias = tf.get_variable('bias', [output_dim], initializer=tf.constant_initializer(0.0))
conv = tf.nn.bias_add(tf.nn.conv2d(input, weight, strides=[1, d_h, d_w, 1], padding='SAME'), bias)
return conv
def deconv2d(input, output_shape, k_h=4, k_w=4, d_h=2, d_w=2, stddev=0.02, name="deconv2d"):
with tf.variable_scope(name):
dyn_batch_size = tf.shape(input)[0]
weight = tf.get_variable('weight', [k_h, k_w, output_shape[-1], input.get_shape()[-1]],initializer=tf.random_normal_initializer(stddev=stddev))
bias = tf.get_variable('bias', [output_shape[-1]], initializer=tf.constant_initializer(0.0))
output_shape = tf.stack([dyn_batch_size,output_shape[0],output_shape[1],output_shape[2]])
deconv = tf.nn.bias_add(tf.nn.conv2d_transpose(input, weight, output_shape=output_shape, strides=[1, d_h, d_w, 1]), bias)
return deconv
def lrelu(x, leak=0.2):
return tf.maximum(x, leak * x)
def linear(input, output_size, name="Linear", stddev=0.02, bias_start=0.0):
shape = input.get_shape().as_list()
with tf.variable_scope(name):
weight = tf.get_variable("weight", [shape[1], output_size], tf.float32,
tf.random_normal_initializer(stddev=stddev))
bias = tf.get_variable("bias", [output_size],
initializer=tf.constant_initializer(bias_start))
return tf.matmul(input, weight) + bias
我的训练:
d_opt = tf.train.AdamOptimizer(learning_rate=conf.learning_rate).minimize(model.d_loss, var_list=model.d_vars)
g_opt = tf.train.AdamOptimizer(learning_rate=conf.learning_rate).minimize(model.g_loss, var_list=model.g_vars)
with tf.Session(config=configProto) as sess:
for epoch in xrange(0, conf.max_epoch):
batch_index = 0
for original, corrupted in data.iterate_batches_train():
feed_dict = {model.original:preprocess(original), model.corrupted:preprocess(corrupted)}
sess.run([d_opt], feed_dict = feed_dict)
sess.run([d_opt], feed_dict = feed_dict)
sess.run([g_opt], feed_dict = feed_dict)
批量大小一的默认配置:
self.fig_size = 424
self.fig_channel = 1
self.conv_channel_base = 64
self.l1_lambda = 100
self.batch_norm_decay = 0.9
self.batch_size = 1
self.max_epoch = 20
self.learning_rate = 0.0002
我很感激你可能有的任何见解......
最佳答案
我认为这是因为您使用了批量归一化。
批量大小 = 1 时,BN 并不是真正有意义的操作。
对于小批量 > 1,您使用的统计数据并不能真正反射(reflect)您的人口,因此事情会变得不稳定。
您可以尝试使用批量大小 = 2 且没有 BN 进行训练吗?
关于python - Tensorflow GAN 仅在批量大小等于 1 时有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51365865/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!