Skip to content

Commit

Permalink
check_gradient_dpooling()
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesShang committed Dec 10, 2018
1 parent 617458f commit fcee04e
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,26 @@ def check_pooling_zero_offset():
s = ', '.join(['%f' % dout[i, :, :, :].mean().item() for i in range(rois.shape[0])])
print(s)

# def check_gradient_dpooling():
# input = torch.randn(2, 32, 64, 64).cuda()
# batch_inds = torch.randint(2, (20, 1)).cuda().float()
# x = torch.randint(256, (20, 1)).cuda().float()
# y = torch.randint(256, (20, 1)).cuda().float()
# w = torch.randint(64, (20, 1)).cuda().float()
# h = torch.randint(64, (20, 1)).cuda().float()
# rois = torch.cat((batch_inds, x, y, x + w, y + h), dim=1)
# offset = torch.randn(20, 2, 7, 7).cuda()
def check_gradient_dpooling():
input = torch.randn(2, 3, 5, 5).cuda() * 0.01
N = 4
batch_inds = torch.randint(2, (N, 1)).cuda().float()
x = torch.rand((N, 1)).cuda().float() * 15
y = torch.rand((N, 1)).cuda().float() * 15
w = torch.rand((N, 1)).cuda().float() * 10
h = torch.rand((N, 1)).cuda().float() * 10
rois = torch.cat((batch_inds, x, y, x + w, y + h), dim=1)
offset = torch.randn(N, 2, 3, 3).cuda()
dpooling = DCNv2Pooling(spatial_scale=1.0 / 4,
pooled_size=3,
output_dim=3,
no_trans=False,
group_size=1,
trans_std=0.0).cuda()
input.requires_grad = True
offset.requires_grad = True
print('check_gradient_dpooling', gradcheck(dpooling, (input, rois, offset), eps=1e-4))


def example_dconv():
from dcn_v2 import DCN
Expand Down Expand Up @@ -246,7 +257,9 @@ def example_mdpooling():
# zero offset check
if inC == outC:
check_zero_offset()
#

check_gradient_dpooling()

# # gradient check
# try:
# check_gradient_double()
Expand Down

0 comments on commit fcee04e

Please sign in to comment.