-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark.lua
64 lines (44 loc) · 1.58 KB
/
benchmark.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
59
60
61
62
63
require 'nn'
require 'paths'
require 'image'
require 'DeformableConvolution'
local nninit= require 'nninit'
w = 32
h = 32
nInputPlane = 3
nOutputPlane = 6
kW = 5
kH = 5
scale = 0.001
weights = torch.rand(nOutputPlane*nInputPlane*kH*kW+nInputPlane*2*kH*kW*kH*kW)
bias = torch.rand(nOutputPlane+2*kH*kW)
weights1 = torch.Tensor(weights:storage(),1,torch.LongStorage{nOutputPlane,nInputPlane,kH,kW})
bias1 = torch.Tensor(bias:storage(),1,torch.LongStorage{nOutputPlane})
net = nn.Sequential()
net:add(nn.SpatialConvolution(nInputPlane,nOutputPlane,kW,kH))
net_new = nn.Sequential()
net_new:add(nn.DeformableConvolution(nInputPlane,nOutputPlane,kW,kH))
--trainset = torch.load('cifar10-train-normalized.t7')
--testset = torch.load('cifar10-test-normalized.t7')
classes = {'airplane', 'automobile', 'bird', 'cat',
'deer', 'dog', 'frog', 'horse', 'ship', 'truck'}
input = torch.rand(nInputPlane,h,w)
gradOutput =torch.rand(nOutputPlane,h-kH+1,w-kW+1)
local x = torch.Timer()
for i = 1,100 do
output_new=net_new:forward(input)
net_new:backward(input, gradOutput)
end
netNewElapsedTime = x:time().real
netnewpara, netnewgradpara = net_new:getParameters()
netnewgradinput = net_new:updateGradInput(input,gradOutput)
x = torch.Timer()
for i = 1,100 do
output = net:forward(input)
net:backward(input,gradOutput)
end
netElapsedTime = x:time().real
netpara, netgradpara = net:getParameters()
netgradinput = net:updateGradInput(input,gradOutput)
print(string.format("elapsed time for new net: %.2f\n", netNewElapsedTime))
--print(string.format("elapsed time for net: %.2f\n", netElapsedTime))