如何在图像大小不固定且不断变化的情况下训练 FCN 网络?
How to train a FCN network while the size of images are not fixed and they are varying?
我已经用固定大小的图像 256x256 训练了 FCN model。请问专家如何在图像大小从一张图像变为另一张图像时训练相同的模型?
非常感谢您的建议。
谢谢
您可以选择以下策略之一:
1。批次 = 1 张图片
通过将每个图像训练为不同的批次,您可以 reshape
网络在数据层的 forward()
(而不是 reshape()
),从而改变网络在每次迭代。
+write reshape
once in forward
method 你不再需要担心输入的形状和大小。
-reshape
上网通常需要 allocation/deallocation 的 CPU/GPU 内存,因此需要时间。
-您可能会发现一批中的单个图像太小了。
例如(假设您使用 层作为输入):
def reshape(self, bottom, top):
pass # you do not reshape here.
def forward(self, bottom, top):
top[0].data.reshape( ... ) # reshape the blob - this will propagate the reshape to the rest of the net at each iteration
top[1].data.reshape( ... ) #
# feed the data to the net
top[0].data[...] = current_img
top[1].data[...] = current_label
2。随机裁剪
您可以决定固定的输入大小,然后随机裁剪所有输入图像(以及相应的基本事实)。
+无需 reshape
每次迭代(更快)。
+在训练过程中控制模型尺寸。
-需要实现图片和标签的随机裁剪
3。固定尺寸
将所有图像调整为相同大小(就像在 SSD 中一样)。
+简单
-如果不是所有图像都具有相同的纵横比,图像就会失真。
-你不是规模不变的
我已经用固定大小的图像 256x256 训练了 FCN model。请问专家如何在图像大小从一张图像变为另一张图像时训练相同的模型?
非常感谢您的建议。 谢谢
您可以选择以下策略之一:
1。批次 = 1 张图片
通过将每个图像训练为不同的批次,您可以 reshape
网络在数据层的 forward()
(而不是 reshape()
),从而改变网络在每次迭代。
+write reshape
once in forward
method 你不再需要担心输入的形状和大小。
-reshape
上网通常需要 allocation/deallocation 的 CPU/GPU 内存,因此需要时间。
-您可能会发现一批中的单个图像太小了。
例如(假设您使用
def reshape(self, bottom, top):
pass # you do not reshape here.
def forward(self, bottom, top):
top[0].data.reshape( ... ) # reshape the blob - this will propagate the reshape to the rest of the net at each iteration
top[1].data.reshape( ... ) #
# feed the data to the net
top[0].data[...] = current_img
top[1].data[...] = current_label
2。随机裁剪
您可以决定固定的输入大小,然后随机裁剪所有输入图像(以及相应的基本事实)。
+无需 reshape
每次迭代(更快)。
+在训练过程中控制模型尺寸。
-需要实现图片和标签的随机裁剪
3。固定尺寸
将所有图像调整为相同大小(就像在 SSD 中一样)。
+简单
-如果不是所有图像都具有相同的纵横比,图像就会失真。
-你不是规模不变的