You can print the gradient as described here and pass it to Scipy. You can also do optimizations in Theano - see this question .
However, perhaps the most straightforward approach is to create a get_gradients() function that uses theano.grad() to return the gradients of the filters relative to the input, and then calls scipy.optimize.minimize with jac=get_gradients . According to the documentation:
jac: bool or called, optional Jacobian (gradient) of an objective function. [...] jac can also be called, returning a gradient Target. In this case, it should accept the same arguments as fun.
source share