Make the gradient jacobian matrix calculation between two images faster


i try to make the gradient jacobian matrix calculation between two images faster, i want to apply difference approximation but i did not see any example about that.


Could you explain in more details what you mean by “gradient jacobian matrix calculation between two images” ?

I mean that i want to calculate the gradient for each pixel from output image according to each pixel from input image so we have as result (256256256*256) value

Well, just the output matrix is going to be very expensive as it will take 4GB. So working with it will require a machine with a lot of memory.

But to go back to you original question, there is nothing much better than repetitive call to autograd.grad I’m afraid. As automatic differentiation only gives a row of the Jacobian at a time.

autograd.grad take alot of time maybe 2 dayes! for this reaseon i want to make this calulation for the matrix output faster

I’m afraid this is “expected”. autograd.grad only uses automatic differentiation. And automatic differentiation is not built to compute full Jacobians. It has to construct them row by row.
But since it;s so big in your case, it takes a very long time.

Note as well that even if you manage to compute the Jacobian matrix, since it will take 4GB just to store it, you definitely won’t be able to do any autograd with it. And you won’t be able to do much operations on it before running out of memory I’m afraid.

1 Like