TD 8 : Convolution Neural Networks

Programmation pour l’IA

Calculer les convolutions suivantes :

  1. \(L * K\) où \(L = \begin{pmatrix} 1 & -2 & 3 & -4 & -3 & 2 & -1 \end{pmatrix}\) et \(K=\begin{pmatrix} 1 & -2 & 1\end{pmatrix}\)
  2. \(M * K\) où \(M = \begin{pmatrix} 1 & 0 & 1 \\ 2 & 1 & 2 \\ 3 & -1 & 2 \end{pmatrix}\) et \(K = \begin{pmatrix} -1 & 1 \\ 1 & -1 \\ \end{pmatrix}\)
  3. \(M*K\) où \(M = \begin{pmatrix} 1 & -2 & 3 & -1 & 0 \\ 2 & 3 & 0 & 1 & 5 \\ 1 & 0 & 1 & 0 & -1 \\ 0 & 1 & 0 & 1 & 0 \\ 1 & 1 & 0 & 1 & 3 \end{pmatrix}\) et \(K=\begin{pmatrix} 1 & 0 & 1 \\ 0 & -2 & 0 \\ 1 & 0 & 1 \end{pmatrix}\)

Calculer les pool suivants :

  1. Un MaxPool 2D avec un kernel de taille 3 pour \(M = \begin{pmatrix} 1 & 0 & 1 & 0 & 3 & 2\\ 1 & 1 & 2 & 2 & 2 & 1\\ 3 & 3 & 2 & 2 & 1 & 2\\ 1 & 2 & 2 & 2 & 0 & 0\\ 1 & 0 & 1 & 2 & 2 & 1\\ 2 & 1 & 1 & 3 & 2 & 0 \end{pmatrix}\)

  2. Même question avec un kernel de taille \(2\).

  3. Un Avg Pool 2D avec un kernel de taille \(3 \times 2\) de

\(M = \begin{pmatrix} 2 & 1 & 1 & 3\\ 2 & 3 & 2 & 3\\ 3 & 1 & 1 & 0\\ 2 & 3 & 0 & 1\\ 2 & 0 & 3 & 1\\ 0 & 1 & 2 & 0 \end{pmatrix}\)

Donnez les formes des vecteurs d’entrées acceptées par les réseaux suivants, la taille de la sortie correspondante et le nombre de paramètres :

nn.Conv2d(input_channel=3, out_channel=2, kernel_size=3)
nn.Sequential(
    nn.Conv2d(input_channel=3, out_channel=1, kernel_size=3, padding=1), 
    nn.Flatten(start_dim=1), 
    nn.Linear(35, 1)
)
nn.Sequential(
    nn.Conv2d(input_channel=3, out_channel=1, kernel_size=3, padding=1), 
    nn.MaxPool2d(2)
)