I had the same question and found the answer in the pytorch documentation for ConvTranspose2d
which provides a formula [1] to determine the output width and height of the transposed convolution (scroll to section of doc labeled Shape
). A simplified version of that formula is copied below.
\begin{align}
n_{out} &= (n_{in} - 1) s - 2 p + (f - 1) + p + 1 \\
&= (n_{in} - 1) s - p + f
\end{align}
where
- n_{out} is the output width or height (same in both dimensions)
- n_{in} is the input width or height (same in both dimensions)
- s is the stride (same in both dimensions)
- p is the padding (same in both dimensions)
- f is the filter dimensions (same in both dimensions)
[1] ConvTranspose2d — PyTorch 2.0 documentation
In the week 3 lecture on transpose convolution we have the following values for the parameters:
- n_{in} = 2
- s = 2
- p = 1
- f = 3
Plugging these values into the formula above I get the same dimensions from in the video.
n_{out} = (2 - 1) 2 - 1+ 3 = 2 - 1 + 3 = 4
Note: The formula in the pytorch doc is different from what @paulinpaloalto pasted at the end of this thread Lecture slide 44 (of 47) -Using Keras to duplicate calculations