dx works but that makes no sense?
This commit is contained in:
@@ -58,12 +58,15 @@ def blocksparse_matmul_grad(op, dy):
|
||||
def run_shift():
|
||||
B, C, H, W = 1, 16, 4, 4
|
||||
R, S, F = 3, 3, 16
|
||||
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.ones(C, dtype=np.int32)
|
||||
hshift_w = np.ones(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)
|
||||
print(hshift_h)
|
||||
print(hshift_w)
|
||||
#hshift_h = np.ones(C, dtype=np.int32)
|
||||
#hshift_w = np.ones(C, dtype=np.int32)
|
||||
c = module.shift_conv(a, b, shift_h=tf.make_tensor_proto(hshift_h), shift_w=tf.make_tensor_proto(hshift_w))
|
||||
# Reference
|
||||
ha = np.random.rand(C, H, W, B)
|
||||
@@ -75,13 +78,16 @@ def run_shift():
|
||||
extra_feed_dict={a: ha, b: hb})
|
||||
dx_t, dx_n = grads[0]
|
||||
dw_t, dw_n = grads[1]
|
||||
print(dx_t)
|
||||
print(dx_n)
|
||||
#print(np.max(dw_t - dw_n))
|
||||
print(dw_t)
|
||||
print(dw_n)
|
||||
print(np.max(dw_t - dw_n))
|
||||
#np.savetxt('diff.dat', dw_t - dw_n, fmt='%2.4f')
|
||||
#np.savetxt('theoretical.dat', dw_t, fmt='%2.4f')
|
||||
#np.savetxt('numerical.dat', dw_n, fmt='%2.4f')
|
||||
print(np.max(dx_t - dx_n))
|
||||
np.savetxt('diff.dat', dx_t - dx_n, fmt='%2.4f')
|
||||
np.savetxt('theoretical.dat', dx_t, fmt='%2.4f')
|
||||
np.savetxt('numerical.dat', dx_n, fmt='%2.4f')
|
||||
#np.savetxt('diff.dat', dx_t - dx_n, fmt='%2.4f')
|
||||
#np.savetxt('theoretical.dat', dx_t, fmt='%2.4f')
|
||||
#np.savetxt('numerical.dat', dx_n, fmt='%2.4f')
|
||||
# Run
|
||||
sess.run(tf.global_variables_initializer())
|
||||
result = sess.run([c], feed_dict = {a: ha,
|
||||
|
Reference in New Issue
Block a user