forked from torch/nn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VolumetricConvolution.lua
58 lines (50 loc) · 1.66 KB
/
VolumetricConvolution.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
local VolumetricConvolution, parent = torch.class('nn.VolumetricConvolution', 'nn.Module')
function VolumetricConvolution:__init(nInputPlane, nOutputPlane, kT, kW, kH, dT, dW, dH)
parent.__init(self)
dT = dT or 1
dW = dW or 1
dH = dH or 1
self.nInputPlane = nInputPlane
self.nOutputPlane = nOutputPlane
self.kT = kT
self.kW = kW
self.kH = kH
self.dT = dT
self.dW = dW
self.dH = dH
self.weight = torch.Tensor(nOutputPlane, nInputPlane, kT, kH, kW)
self.bias = torch.Tensor(nOutputPlane)
self.gradWeight = torch.Tensor(nOutputPlane, nInputPlane, kT, kH, kW)
self.gradBias = torch.Tensor(nOutputPlane)
-- temporary buffers for unfolding (CUDA)
self.finput = torch.Tensor()
self.fgradInput = torch.Tensor()
self:reset()
end
function VolumetricConvolution:reset(stdv)
if stdv then
stdv = stdv * math.sqrt(3)
else
stdv = 1/math.sqrt(self.kT*self.kW*self.kH*self.nInputPlane)
end
if nn.oldSeed then
self.weight:apply(function()
return torch.uniform(-stdv, stdv)
end)
self.bias:apply(function()
return torch.uniform(-stdv, stdv)
end)
else
self.weight:uniform(-stdv, stdv)
self.bias:uniform(-stdv, stdv)
end
end
function VolumetricConvolution:updateOutput(input)
return input.nn.VolumetricConvolution_updateOutput(self, input)
end
function VolumetricConvolution:updateGradInput(input, gradOutput)
return input.nn.VolumetricConvolution_updateGradInput(self, input, gradOutput)
end
function VolumetricConvolution:accGradParameters(input, gradOutput, scale)
return input.nn.VolumetricConvolution_accGradParameters(self, input, gradOutput, scale)
end