【论文复现】显存占用问题
Created by: txyugood
在复现论文《Representation Flow for Action Recognition》的光流层的过程中,在动态图中迭代循环20次去计算光流,在循环中会调用如下函数,会导致显存占用暴涨10G,导致 batch_size 十分小。请问这是由于什么原因导致的,怎样才能解决,已经卡在这好几天了,望回复谢谢!
self.f_div_conv = Conv2D(
num_channels=channels,
num_filters=channels,
filter_size=(1, 2),
groups=self.channels,
param_attr=ParamAttr(initializer=NumpyArrayInitializer(self.div)),
bias_attr=False
)
def divergence(self, x, y):
tx = fluid.layers.pad(x[:, :, :, :-1], [0, 0, 0, 0, 0, 0, 1, 0])
ty = fluid.layers.pad(y[:, :, :-1, :], [0, 0, 0, 0, 1, 0, 0, 0])
tx = fluid.layers.pad(tx, [0, 0, 0, 0, 0, 0, 0, 1])
ty = fluid.layers.pad(ty, [0, 0, 0, 0, 0, 1, 0, 0])
grad_x = self.f_div_conv(tx)
grad_y = self.f_div2_conv(ty)
#pytorch 实现方法
# grad_x = F.conv2d(F.pad(tx, (0, 0, 0, 1)), self.div) # , groups=self.channels)
# grad_y = F.conv2d(F.pad(ty, (0, 0, 0, 1)), self.div2) # , groups=self.channels)
return grad_x + grad_y
self.n_iter = 20
for i in range(self.n_iter):
some code ....
u1 = v1 + self.t * self.divergence(p11, p12)
u2 = v2 + self.t * self.divergence(p21, p22)
some code ..
p11 = (p11 + taut * u1x) / (1. + taut * fluid.layers.sqrt(u1x ** 2 + u1y ** 2 + 1e-12))
p12 = (p12 + taut * u1y) / (1. + taut * fluid.layers.sqrt(u1x ** 2 + u1y ** 2 + 1e-12))
p21 = (p21 + taut * u2x) / (1. + taut * fluid.layers.sqrt(u2x ** 2 + u2y ** 2 + 1e-12))
p22 = (p22 + taut * u2y) / (1. + taut * fluid.layers.sqrt(u2x ** 2 + u2y ** 2 + 1e-12))
return u1,u2