Back to topic
Optional
Convolution output size and parameters
H′ formula and NumPy cross-correlation on the topic example; ResNet stem parameter count. Self-check in the notebook.
- Version
- v1
- Minutes
- ~20
- Evidence
- Self-check in the notebook
Until platform auto-check exists, compare cell output with the expected numbers in the notebook. This is not a debt and does not affect mastery.
Download the notebook and run it locally. Its environment requirements are listed inside.
Notebook contents
Readable on your phone. The code below has not been executed in the browser; download the notebook to run it.
DL · Размер выхода свёртки / Convolution output sizing
Activity version: 1 · Seed: n/a · Данные: синтетические тензоры; без внешних датасетов.
Сверяет формулу стороны после свёртки с NumPy cross-correlation (тема Свёртка):
и число параметров .
Ожидаемые числа
| Case | params | ||
|---|---|---|---|
| same | (, bias) | ||
| ResNet stem | / без bias | ||
| topic | , cols | , row0 [5,7] |
Самопроверка в ноутбуке
Активность не входит в процент освоения.
import numpy as np
def out_side(H, k, p, s):
return (H + 2 * p - k) // s + 1
assert out_side(224, 3, 1, 1) == 224
assert out_side(224, 7, 3, 2) == 112
assert out_side(4, 3, 0, 1) == 2
def n_params(C_in, C_out, k, bias=True):
return C_out * (C_in * k * k + (1 if bias else 0))
assert n_params(3, 64, 3, True) == 1792
assert n_params(3, 64, 7, True) == 9472
assert n_params(3, 64, 7, False) == 9408
print("sizes OK", out_side(224, 7, 3, 2), n_params(3, 64, 3, True))
X = np.array([[1, 0, 2, 3], [0, 1, 3, 2], [1, 0, 2, 3], [0, 1, 2, 3]], dtype=float)
K = np.array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]], dtype=float)
def corr2d(X, K):
H, W = X.shape
k = K.shape[0]
out = np.zeros((H - k + 1, W - k + 1))
for i in range(out.shape[0]):
for j in range(out.shape[1]):
out[i, j] = np.sum(X[i:i + k, j:j + k] * K)
return out
Y = corr2d(X, K)
print("Y", Y)
assert Y[0, 0] == 5
assert list(Y[0]) == [5.0, 7.0]
assert list(Y[1]) == [6.0, 6.0]
print("OK: convolution sizing + worked example")
Самопроверка в ноутбуке
- same / ResNet stem размеры совпали
- params 1792 и 9472 (с bias) / 9408 без bias
- , первая строка
[5, 7]