\documentclass[12pt]{exam}		%Doc : https://mirrors.ircam.fr/pub/CTAN/macros/latex/contrib/exam/examdoc.pdf
\printanswers					%Comment this line to hide the answers 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}      %Originally for french document, change to english or relevant language

\usepackage{amsmath,amssymb}
\usepackage{multicol}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
	\usetikzlibrary{fadings}
	\usetikzlibrary{calc}
	
\usepackage{tkz-tab}
\usepackage{pgfplots}

%Format Header and footer
\pagestyle{headandfoot}
\headrule
\footrule
\setlength{\columnsep}{0.25cm}
%\setlength{\columnseprule}{1pt}
\footer{}{Page \thepage}{}
%\extrafootheight{-2cm}

% Change section command behaviour
\usepackage{titlesec}
\titleformat{\section}[frame]{\Huge\bfseries\filright}{}{2mm}{\centering}

% Add a watermark if answers are shown

%Format the name of each exercise
\qformat{\textbf{Exercice \thequestion~:}\hfill}
\extrawidth{1.5cm}

\title{Title}
\begin{document}
\section{VIR exercises}
\begin{questions}
	\question Consider a CNN with following layers:\\
	l1 = Conv2d(in\_channels=3, out\_channels=n, kernel\_size=(7,7), padding=3, stride=2)\\
	l2 = Conv2d(in\_channels=n, out\_channels=2*n, kernel\_size=(3,3), padding=1, stride=1)\\
	l3 = Conv2d(in\_channels=2*n, out\_channels=4*n, kernel\_size=(3,3), padding=1, stride=2)\\
	l4 = Linear(in\_features=x, out\_features=5)\\
	where $x$ is unknown and $n$ is a parameter. Input is passed sequentially and output of layer3 is flattened. The network is supposed to process $64 \times 64$ RGB images.
	
		\begin{itemize}
			\item What is the receptive field of filters at layer3, that is, what is the size of the part of an input image that they can "see" (disregard padding)
				\begin{solution}
					Receptive field of layer3 and layer 2 combined is $5\times 5$ (not $9 \times 9$ due to overlap) that combined with layer 1 gives us $15 \times 15$ ($7\times7$ base and 2(stride=2) added per remaining "pixel" of previous receptive field)
				\end{solution}
			\item express $x$ int terms of $n$
				\begin{solution}
    				The image is downsampled twice via stride by a factor of 2 that makes $x = 16 \cdot 16 \cdot 4n = 1024n$
				\end{solution}
			\item What is the maximal value of $n$ if we the network parameters are needed to be less than 128KiB given the parameters are of type float32? (1KiB = 1024B)
			    \begin{solution}
			        Let's first calculate the number of paramaters for each layer:\\
layer1: $(7 \cdot 7 \cdot 3 +1)n = 148n$\\
layer2: $(3\cdot 3\cdot n +1)2n = 18n^2 + 2n$\\
layer3: $(3 \cdot 3\cdot 2n +1)4n = 72n^2 + 4n$\\
layer4: $1024n \cdot 5 + 5 = 5120n + 5$\\
That gives us: $90n^2 + 5274n + 5 \leq \dfrac{128}{4}\cdot 1024 \longrightarrow 90n^2 + 5274n -32763 \leq 0$\\
after solving the quadratic we get that the answer is 5
			    \end{solution}
		\end{itemize}
\end{questions}
\end{document}
