Posts

Showing posts with the label computer-vision

Why does this order of the Gaussian filter in scipy give the x and y derivative?

Why does this order of the Gaussian filter in scipy give the x and y derivative? I'm using a Gaussian filter with Scipy and I saw this code online which I'm curious about. imx = zeros(im.shape) filters.gaussian_filter(im, (sigma,sigma), (0,1), imx) imy = zeros(im.shape) filters.gaussian_filter(im, (sigma,sigma), (1,0), imy) For the first Gaussian filter call, the order is (0,1) and according to this link, that should give the the first order derivative of a Gaussian in y-direction. However, on running the code, I can see that the Gaussian is along the X direction. The same thing applies to imy. Why does the code work that way? For reference, running: filters.gaussian_filter(im, (sigma, sigma), (0, 1), output= imx) on this array: [[0 3 2] [1 4 1] [3 4 2]] Returns: [[0.00071801 0.00148952 0.00077151] [0.0006947 0.00144284 0.00074815] [0.00067141 0.00139622 0.00072482]] Which is a Gaussian in the x direction, even though the order (0, 1) suggests that it should be in the y dire...

PyTorch Autograd automatic differentiation feature

Image
PyTorch Autograd automatic differentiation feature I am just curious to know, how does PyTorch track operations on tensors (after the .requires_grad is set as True and how does it later calculate the gradients automatically. Please help me understand the idea behind autograd . Thanks. .requires_grad True autograd 1 Answer 1 That's a great question! Generally, the idea of automatic differentiation ( AutoDiff ) is based on the multivariable chain rule, i.e. . What this means is that you can express the derivative of x with respect to z via a "proxy" variable y; in fact, that allows you to break up almost any operation in a bunch of simpler (or atomic) operations that can then be "chained" together. Now, what AutoDiff packages like Autograd do, is simply to store the derivative of such an atomic operation block, e.g., a division, multiplication, etc. Then, at runtime, your p...