MCPcopy
hub / github.com/junyanz/iGAN / get_hog

Method get_hog

lib/HOGNet.py:37–84  ·  view source on GitHub ↗
(self, x_o)

Source from the content-addressed store, hash-verified

35 return masks
36
37 def get_hog(self, x_o):
38 use_bin = self.use_bin
39 NO = self.NO
40 BS = self.BS
41 nc = self.nc
42 x = (x_o + sharedX(1)) / (sharedX(2))
43 Gx = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) / 4.0
44 Gy = Gx.T
45 f1_w = []
46 for i in range(NO):
47 t = np.pi / NO * i
48 g = np.cos(t) * Gx + np.sin(t) * Gy
49 gg = np.tile(g[np.newaxis, np.newaxis, :, :], [1, 1, 1, 1])
50 f1_w.append(gg)
51 f1_w = np.concatenate(f1_w, axis=0)
52 G = np.concatenate([Gx[np.newaxis, np.newaxis, :, :], Gy[np.newaxis, np.newaxis, :, :]], axis=0)
53 G_f = sharedX(floatX(G))
54
55 a = np.cos(np.pi / NO)
56 l1 = sharedX(floatX(1 / (1 - a)))
57 l2 = sharedX(floatX(a / (1 - a)))
58 eps = sharedX(1e-3)
59 if nc == 3:
60 x_gray = T.mean(x, axis=1).dimshuffle(0, 'x', 1, 2)
61 else:
62 x_gray = x
63 f1 = sharedX(floatX(f1_w))
64 h0 = T.abs_(dnn_conv(x_gray, f1, subsample=(1, 1), border_mode=(1, 1)))
65 g = dnn_conv(x_gray, G_f, subsample=(1, 1), border_mode=(1, 1))
66
67 if use_bin:
68 gx = g[:, [0], :, :]
69 gy = g[:, [1], :, :]
70 gg = T.sqrt(gx * gx + gy * gy + eps)
71 hk = T.maximum(0, l1 * h0 - l2 * gg)
72
73 bf_w = np.zeros((NO, NO, 2 * BS, 2 * BS))
74 b = 1 - np.abs((np.arange(1, 2 * BS + 1) - (2 * BS + 1.0) / 2.0) / BS)
75 b = b[np.newaxis, :]
76 bb = b.T.dot(b)
77 for n in range(NO):
78 bf_w[n, n] = bb
79
80 bf = sharedX(floatX(bf_w))
81 h_f = dnn_conv(hk, bf, subsample=(BS, BS), border_mode=(BS / 2, BS / 2))
82 return h_f
83 else:
84 return g

Callers 2

def_bfgsFunction · 0.80
def_invertMethod · 0.80

Calls 2

sharedXFunction · 0.90
floatXFunction · 0.90

Tested by

no test coverage detected