-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdoIterative.lua
More file actions
96 lines (59 loc) · 2.99 KB
/
Copy pathdoIterative.lua
File metadata and controls
96 lines (59 loc) · 2.99 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function doIterative(thePos,theInputs,thePosDec,theChangeDec,theMagDec)
if(not (#lstm.modules == #slstm.modules)) then
print("lstm != slstm. SOMETHING IS WRONG.");
end
for i = 1,#lstm.modules do
if(slstm.modules[i].weight) then
slstm.modules[i].weight = lstm.modules[i].weight:clone();
end
if(slstm.modules[i].bias) then
slstm.modules[i].bias = lstm.modules[i].bias:clone();
end
end
local inputPose = torch.CudaTensor(opt.batchsize, opt.numSteps, 54);
inputPose = inputPose:zero();
thePos = thePos:reshape(opt.batchsize, opt.numSteps, 54);
inputPose = inputPose:reshape(opt.batchsize, opt.numSteps, 54);
inputPose:narrow(2,1,1):add(thePos:narrow(2,1,1):clone());
local unNormdiff = torch.CudaTensor(opt.batchsize, opt.numSteps*36);
unNormdiff = unNormdiff:zero();
local unNormdiff = unNormdiff:reshape(opt.batchsize, opt.numSteps*36);
local unNormmag = torch.CudaTensor(opt.batchsize, opt.numSteps*2);
unNormmag = unNormmag:zero();
local predictions = dpt:forward({theInputs, thePosDec, theChangeDec, theMagDec});
local poutput = {};
slstm.modules[13].hiddenInput = dpt.modules[1].modules[45].hiddenOutput:clone()
slstm.modules[13].cellInput = dpt.modules[1].modules[45].cellOutput:clone()
poutput = slstm:forward({theSamps:narrow(2,1,4), inputPose:narrow(2,1,1)})
slstm.modules[13].hiddenInput = slstm.modules[13].hiddenOutput:clone()
slstm.modules[13].cellInput = slstm.modules[13].cellOutput:clone()
unNormdiff:narrow(2,1, 36):add(poutput[1]);
unNormmag:narrow(2,1, 2):add(poutput[2]);
local steps = opt.numSteps;
opt.numSteps = 1;
poutput[1] = poutput[1]:reshape(opt.batchsize, 36, 1);
doScalingInv(inputPose:clone(), poutput[1], poutput[2], opt.numSteps);
poutput[1] = torch.cat(poutput[1], torch.CudaTensor(opt.batchsize,18):zero(),2)
inputPose:narrow(2,2,1):add(inputPose:narrow(2,1,1), poutput[1]);
opt.numSteps = steps;
for i = 2,(opt.numSteps - 1) do
poutput = slstm:forward({theSamps:narrow(2,(i-1)*5+1,4), inputPose:narrow(2,i,1)})
slstm.modules[13].hiddenInput = slstm.modules[13].hiddenOutput:clone();
slstm.modules[13].cellInput = slstm.modules[13].cellOutput:clone();
unNormdiff:narrow(2,(i-1)*36 + 1, 36):add(poutput[1]);
unNormmag:narrow(2,(i-1)*2 + 1, 2):add(poutput[2]);
local steps = opt.numSteps;
opt.numSteps = 1;
poutput[1] = poutput[1]:reshape(opt.batchsize, 36, 1);
doScalingInv(thePos:narrow(2,1,1):clone(), poutput[1], poutput[2], opt.numSteps);
poutput[1] = torch.cat(poutput[1], torch.CudaTensor(opt.batchsize,18):zero(),2)
inputPose:narrow(2,i+1,1):add(inputPose:narrow(2,i,1), poutput[1]);
opt.numSteps = steps;
end
local poutput = slstm:forward({theSamps:narrow(2,opt.numSteps,4), inputPose:narrow(2,opt.numSteps,1)})
unNormdiff:narrow(2,(opt.numSteps-1)*36 + 1, 36):add(poutput[1]);
unNormmag:narrow(2,(opt.numSteps-1)*2 + 1, 2):add(poutput[2]);
unNormdiff = unNormdiff:reshape(opt.batchsize, opt.numSteps, 36);
unNormdiff = unNormdiff:transpose(3,2);
return {unNormdiff, inputPose, unNormmag};
end