[dnn/shift] many bugfixes in strided shift-conv
This commit is contained in:
@@ -58,24 +58,29 @@ def blocksparse_matmul_grad(op, dy):
|
||||
return (dx, dw)
|
||||
|
||||
def run_shift():
|
||||
B, C, H, W = 16, 1, 4, 4
|
||||
R, S, F = 3, 3, 32
|
||||
B, C, H, W = 16, 16, 4, 4
|
||||
R, S, F = 3, 3, 16
|
||||
stride_h, stride_w = 2, 2
|
||||
np.random.seed(2)
|
||||
a = tf.placeholder(tf.float32, shape=[C, H, W, B])
|
||||
b = tf.placeholder(tf.float32, shape=[C, F])
|
||||
hshift_h = np.random.randint(- (R//2), R//2 + 1, size=C, dtype=np.int32)
|
||||
hshift_w = np.random.randint(- (S//2), R//2 + 1, size=C, dtype=np.int32)
|
||||
#hshift_h = np.random.randint(- (R//2), R//2 + 1, size=C, dtype=np.int32)
|
||||
#hshift_w = np.random.randint(- (S//2), R//2 + 1, size=C, dtype=np.int32)
|
||||
hshift_h = np.zeros(C, dtype=np.int32)
|
||||
hshift_w = np.zeros(C, dtype=np.int32)
|
||||
c = module.shift_conv(a, b, stride_h=stride_h, stride_w=stride_w, shift_h=tf.make_tensor_proto(hshift_h), shift_w=tf.make_tensor_proto(hshift_w))
|
||||
# feed values
|
||||
ha = np.ones((C, H, W, B), dtype=np.float32)
|
||||
hb = np.ones((C, F), dtype=np.float32)
|
||||
ha = np.random.rand(C, H, W, B)
|
||||
hb = np.random.rand(C, F)
|
||||
#ha = np.ones((C, H, W, B), dtype=np.float32)
|
||||
#hb = np.ones((C, F), dtype=np.float32)
|
||||
sess = tf.InteractiveSession()
|
||||
# test
|
||||
grads = tf.test.compute_gradient([a, b], [(C, H, W, B), (C, F)], c, (F, H//stride_h, W//stride_w, B),
|
||||
extra_feed_dict = {a: ha, b: hb})
|
||||
dw_t, dw_n = grads[1]
|
||||
dx_t, dx_n = grads[0]
|
||||
print(dw_t, dw_n)
|
||||
print(np.max(np.abs(dw_t - dw_n)))
|
||||
print(np.max(np.abs(dx_t - dx_n)))
|
||||
# Run
|
||||
|
Reference in New Issue
Block a user