Tensorflow 上的全卷积网络 (FCN)
Fully Convolution Net (FCN) on Tensorflow
我正在尝试在 tensorflow 上重新实现 FCN。我已经实现了反卷积层。
up8_filter = tf.Variable(tf.truncated_normal([64, 64, 21, 21]))
prob_32 = tf.nn.conv2d_transpose(score, up8_filter, output_shape = [batch_size, 224, 224, 21], strides = [1, 32, 32, 1])
tf.histogram_summary('fc8_filter', up8_filter)
训练看起来很好,损失值下降直到变为 Nan
。我检查了 tensorboard,它表明 up8_filter
似乎出现了分歧。
有没有办法在 Tensorflow 中调整权重值?
我尝试了以下方法
- 较低的学习率
- 零均值图像
我没有按照 FCN 实现将图像填充到 100 像素,因为 Tensorflow conv2d
不支持它。我使用 caffe-tensorflow 转换了 VGG 权重,我无法改变它的网络结构。
对于这个令人困惑的问题,我深表歉意,有太多地方出错了,我不确定从哪里开始。
损失值的片段。
Step 1: loss = 732171599872.00
Step 10: loss = 391914520576.00
Step 20: loss = 32141299712.00
Step 30: loss = 1255705344.00
[更新]:
损失函数
损失32
loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(
tf.reshape(prob_32, [batch_size*224*224, 21]),
tf.reshape(lbl_ph, [-1]) ))
[更新2]
我遵循了 ziky90 的建议,它奏效了。训练现在收敛了,deconv 过滤器似乎停止了发散。我将报告 agian 的准确性。
如果我将其与参考 caffe 实现进行比较,那么我发现您不是通过 deconvolution
/tf.nn.conv2d_transpose
层中的双线性插值来初始化权重,而是通过 tf.truncated_normal
.
另请查看我的 Tensorflow FCN implementation. Training works when using this loss function in combination with this 训练脚本。
以下是我在实施 FCN 时获得的一些见解。
- deconv 滤波器需要初始化为双线性。
tf.nn.sparse_softmax_cross_entropy_with_logits
可以使用,但在某些情况下会导致数值不稳定。另见此 Tensorflow issue。因此,我决定使用张量运算来实现交叉熵。
- 当使用大图像(导致大
softmax batches
)时,降低训练率很有用。 Adam 优化器结合 1e-6
的学习率似乎很有用。
我正在尝试在 tensorflow 上重新实现 FCN。我已经实现了反卷积层。
up8_filter = tf.Variable(tf.truncated_normal([64, 64, 21, 21]))
prob_32 = tf.nn.conv2d_transpose(score, up8_filter, output_shape = [batch_size, 224, 224, 21], strides = [1, 32, 32, 1])
tf.histogram_summary('fc8_filter', up8_filter)
训练看起来很好,损失值下降直到变为 Nan
。我检查了 tensorboard,它表明 up8_filter
似乎出现了分歧。
有没有办法在 Tensorflow 中调整权重值?
我尝试了以下方法
- 较低的学习率
- 零均值图像
我没有按照 FCN 实现将图像填充到 100 像素,因为 Tensorflow conv2d
不支持它。我使用 caffe-tensorflow 转换了 VGG 权重,我无法改变它的网络结构。
对于这个令人困惑的问题,我深表歉意,有太多地方出错了,我不确定从哪里开始。
损失值的片段。
Step 1: loss = 732171599872.00
Step 10: loss = 391914520576.00
Step 20: loss = 32141299712.00
Step 30: loss = 1255705344.00
[更新]:
损失函数 损失32
loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(
tf.reshape(prob_32, [batch_size*224*224, 21]),
tf.reshape(lbl_ph, [-1]) ))
[更新2]
我遵循了 ziky90 的建议,它奏效了。训练现在收敛了,deconv 过滤器似乎停止了发散。我将报告 agian 的准确性。
如果我将其与参考 caffe 实现进行比较,那么我发现您不是通过 deconvolution
/tf.nn.conv2d_transpose
层中的双线性插值来初始化权重,而是通过 tf.truncated_normal
.
另请查看我的 Tensorflow FCN implementation. Training works when using this loss function in combination with this 训练脚本。
以下是我在实施 FCN 时获得的一些见解。
- deconv 滤波器需要初始化为双线性。
tf.nn.sparse_softmax_cross_entropy_with_logits
可以使用,但在某些情况下会导致数值不稳定。另见此 Tensorflow issue。因此,我决定使用张量运算来实现交叉熵。- 当使用大图像(导致大
softmax batches
)时,降低训练率很有用。 Adam 优化器结合1e-6
的学习率似乎很有用。