Convolutions for Images

http://d2l.ai/chapter_convolutional-neural-networks/conv-layer.html

Hey @anirudh in section 6.2.4 Learning A Kernel
when printing this at the bottom of our for loop:

if (i+1) % 2 == 0:
print(f'batch {i+1}, loss {l.sum():.3f}')

should it be batch or epoch? I thought it was epoch, could you explain why its batch instead?

  1. When you try to automatically find the gradient for the Conv2D class we created, what kind of error message do you see?

Got Error Message: Inplace operations are not supported using autograd .

  1. How do you represent a cross-correlation operation as a matrix multiplication by changing the input and kernel tensors?

–> flip the two-dimensional kernel tensor both horizontally and vertically, and then perform the cross-correlation operation with the input tensor

K = torch.tensor([[1.0, -1.0]]) # filter shape: (1, 2)
# flip horizontally
K = torch.flip(K, [1])
# flip vertically
K = torch.flip(K, [0])
print(K)
print(K)

 Y = corr2d(X, K)
 plt.imshow(Y, cmap="gray")

What is the minimum size of a kernel to obtain a derivative of degree d?
–> I have no idea about this. Can someone clarify?

1 Like

For Exercise 2, l.sum().backward() is already computing the gradient, is it not?

how did you automatically try to find gradient?

yes through backpropagation the leaf tensor gradient is stored in net.grad

Exercises

  1. Construct an image X with diagonal edges.

    1. What happens if you apply the kernel K in this section to it?

      • zero matrix.
    2. What happens if you transpose X?

      • No change
    3. What happens if you transpose K?

      • zero matrix.
  2. When you try to automatically find the gradient for the Conv2D class we created, what kind

of error message do you see?

* I am able to do `net.weights.grad`, when I try `net.grad` I get the error `'Conv2d' object has no attribute 'grad'`
  1. How do you represent a cross-correlation operation as a matrix multiplication by changing

the input and kernel tensors?

* cross correlation is basically matrix multiplication between slices of tensorfrom X of the shape of kernel and summing.

* It can be done by padding Kand X based on what is needed to multiply
  1. Design some kernels manually.

    1. What is the form of a kernel for the second derivative?

    2. What is the kernel for an integral?

      • how do you actually make it manually
  2. What is the minimum size of a kernel to obtain a derivative of degree d

     * dont know.