fixed bug
This commit is contained in:
@@ -61,30 +61,30 @@ def run_shift():
|
||||
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 = -1*np.ones(C, dtype=np.int32)
|
||||
hshift_w = -1*np.ones(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))
|
||||
c = tf.math.reduce_sum(c)
|
||||
# Reference
|
||||
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)
|
||||
#ha = np.ones((C, H, W, B), dtype=np.int32)
|
||||
#hb = np.ones((C, F), dtype=np.int32)
|
||||
sess = tf.InteractiveSession()
|
||||
grads = tf.test.compute_gradient([a, b], [(C, H, W, B), (C, F)], c, (C, H, W, B),
|
||||
grads = tf.test.compute_gradient([a, b], [(C, H, W, B), (C, F)], c, (1,),
|
||||
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 - 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))
|
||||
print(np.max(np.abs(dw_t - dw_n)))
|
||||
print(np.max(np.abs(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')
|
||||
|
Reference in New Issue
Block a user