Skip to content

Instantly share code, notes, and snippets.

@anna-hope
Last active October 17, 2018 15:15
Show Gist options
  • Save anna-hope/c6090fbe62bf648ec6191938cf470b86 to your computer and use it in GitHub Desktop.
Save anna-hope/c6090fbe62bf648ec6191938cf470b86 to your computer and use it in GitHub Desktop.
Get output dimension after all conv layers
import numpy as np
def get_conv_out(dim_in, padding, kernel_size, stride):
out_dim = (dim_in + 2 * padding - kernel_size) / stride
out_dim += 1
return int(np.floor(out_dim))
layers = [(0, 7, 1),
(0, 3, 3),
(0, 7, 1),
(0, 3, 3),
(0, 3, 1),
(0, 3, 1),
(0, 3, 1),
(0, 3, 1),
(0, 3, 3)]
dim_in = 1014
for padding, f, s in layers:
dim_in = get_conv_out(dim_in, padding, f, s)
# dim_in is now 34
# 34 * 27 + 96 = 1014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment