Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def receptive_field(model, X):
- half_size = 14
- xs_f = torch.tensor(
- X.astype(np.float32),
- requires_grad=True
- ).to(DEVICE)
- xs = torch.tensor(X)
- ps = model1(xs_f)
- ps = ps[:, 0, half_size, half_size].reshape(-1, 1, 1, 1, 4)
- xs = xs[:, 0, half_size, half_size].reshape(-1, 1, 1, 1).to(DEVICE)
- criterion = MyNLLLoss
- loss = criterion(xs, ps)
- xs_f.retain_grad()
- loss.backward()
- img = xs_f.grad.abs().sum(dim=(0, 1))
- img = img.float().cpu().numpy()
- plt.imshow(img)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement