-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_forward.lua
166 lines (122 loc) · 3.22 KB
/
test_forward.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
require 'nn'
require 'paths'
require 'image'
require 'almostIdentity'
require 'deformableconvolution'
require 'DeformableConvolution'
local nninit= require 'nninit'
--net = nn.Sequential()
net = torch.load('checkpoint4.t7')
testset = torch.load('cifar10-test-normalized.t7')
testset.data = testset.data:double() -- convert from Byte tensor to Double tensor
correct = 0
for i=1,10000 do
local groundtruth = testset.label[i]
local prediction = net:forward(testset.data[i])
local confidences, indices = torch.sort(prediction, true)
if groundtruth == indices[1] then
correct = correct + 1
end
end
print(correct, 100*correct/10000 .. ' % ')
--input = torch.DoubleTensor(1,2,2)
-- input[1][1][1] = 1
-- input[1][1][2] = 2
-- input[1][2][1] = 3
-- input[1][2][2] = 4
-- epsilon = 10e-5
-- del_x =
-- (deformableconvolution.bilinearInterpolation(input,torch.LongTensor(),torch.Tensor(),1,2.5,2.5+epsilon,0,0,0)-
-- deformableconvolution.bilinearInterpolation(input,torch.LongTensor(),torch.Tensor(),1,2.5,2.5-epsilon,0,0,0))/(2*epsilon
-- )
-- for i = 1,100 do
-- x = torch.random(0,300)/100
-- y = torch.random(0,300)/100
--
-- del_y =
-- (deformableconvolution.bilinearInterpolation(input,torch.LongTensor(),torch.Tensor(),1,y+epsilon,x,0,0,0)-
-- deformableconvolution.bilinearInterpolation(input,torch.LongTensor(),torch.Tensor(),1,y-epsilon,x,0,0,0))/(2*
-- epsilon)
--
-- del_x =
-- (deformableconvolution.bilinearInterpolation(input,torch.LongTensor(),torch.Tensor(),1,y,x+epsilon,0,0,0)-
-- deformableconvolution.bilinearInterpolation(input,torch.LongTensor(),torch.Tensor(),1,y,x-epsilon,0,0,0))/(2*epsilon
-- )
--
-- x_proj = x
-- y_proj = y
--
-- if( x > 2) then
-- x_proj = 2
-- end
-- if( x < 1) then
-- x_proj=1
-- end
-- if( y > 2) then
-- y_proj = 2
-- end
-- if( y < 1) then
-- y_proj=1
-- end
--
-- w0 = 1 - torch.abs(1 -y_proj)
-- w1 = 1 - torch.abs(x_proj-1)
-- w2 = 1 - torch.abs(2-y_proj)
-- w3 = 1 - torch.abs(2-x_proj)
--
-- vy=0
-- vx=0
--
-- if( x == x_proj or y == y_proj) then
-- vy = -input[1][1][1]*w1 - input[1][1][2]*w3
-- +input[1][2][1]*w1
-- +input[1][2][2]*w3
-- vx = -input[1][1][1]*w0 + input[1][1][2]*w0
-- -input[1][2][1]*w2
-- +input[1][2][2]*w2
-- end
--
-- if(x ~= x_pro) then
--
--
--
-- if(x ~= x_proj) then
-- vy = -input[1][1][1]*w1 - input[1][1][2]*w3
-- +input[1][2][1]*w1
-- +input[1][2][2]*w3
-- end
--
-- if(y ~= y_proj) then
-- vx = -input[1][1][1]*w0 + input[1][1][2]*w0
-- -input[1][2][1]*w2
-- +input[1][2][2]*w2
-- end
--
-- if( x ~= x_proj and y ~= y_proj) then
-- print("projected twice")
-- vy = 0
-- vx = 0
-- end
--
-- if( x == x_proj and y == y_proj) then
-- vy = -input[1][1][1]*w1 - input[1][1][2]*w3
-- +input[1][2][1]*w1
-- +input[1][2][2]*w3
-- vx = -input[1][1][1]*w0 + input[1][1][2]*w0
-- -input[1][2][1]*w2
-- +input[1][2][2]*w2
-- end
--
-- err_x = torch.abs(del_x - vx)
-- err_y = torch.abs(del_y - vy)
-- if(err_x > 0.1 or err_y > 0.1) then
-- print("point", y,x)
-- print("error", err_y, err_x)
-- print("symbolic" , vy,vx)
-- print("numeric" , del_y,del_x)
-- if( vx == 0 and vy == 0) then
-- print(w0,w1,w2,w3)
-- end
-- end
-- print(i)
-- end