Eh, I don’t know much about keras…
input = torch.autograd.Variable(torch.from_numpy(np.ones([1,1,32,32]))
output = model(input)
v = torch.autograd.Variable(torch.from_numpy(np.ones([1,10])))
loss = ((v - output) ** 2).sum()
grad = torch.autograd.grad(loss, input)