Skip to content

Commit 76a7f23

Browse files
authored
Model file with Receptive Field details & comments
1 parent 60a4b0d commit 76a7f23

File tree

1 file changed

+47
-18
lines changed

1 file changed

+47
-18
lines changed

models/model.py

+47-18
Original file line numberDiff line numberDiff line change
@@ -15,78 +15,107 @@ def __init__(self, dropout_value = 0.01):
1515
nn.ReLU(),
1616
nn.BatchNorm2d(32),
1717
nn.Dropout(dropout_value),
18+
# Input: 32x32x3 | Output: 32x32x32 | RF: 3x3
1819

1920
nn.Conv2d(in_channels=32, out_channels=64, kernel_size=(3, 3), padding=1, bias=False),
2021
nn.ReLU(),
2122
nn.BatchNorm2d(64),
2223
nn.Dropout(dropout_value),
24+
# Input: 32x32x32 | Output: 32x32x64 | RF: 5x5
2325
) # Input: 32x32x3 | Output: 32x32x64 | RF: 5x5
2426

2527
# TRANSITION BLOCK 1
2628
self.transblock1 = nn.Sequential(
27-
#nn.Conv2d(in_channels=64, out_channels=32, kernel_size=(1, 1), stride=2),
28-
nn.Conv2d(in_channels=64, out_channels=32, kernel_size=(1, 1)),
29+
# Pointwise Convolution to reduce number of channels
30+
nn.Conv2d(in_channels=64, out_channels=32, kernel_size=(1, 1)), # Input: 32x32x64 | Output: 32x32x32 | RF: 5x5
31+
32+
# Depthwise Convolution with stride=2 to reduce the channel size to half
2933
nn.Conv2d(in_channels=32, out_channels=32, kernel_size=(3, 3), padding=1, stride=2, groups=32, bias=False)
30-
) # Input: 32x32x64 | Output: 16x16x32 | RF: 10x10
34+
# Input: 32x32x32 | Output: 16x16x32 | RF: 7x7
35+
36+
) # Input: 32x32x64 | Output: 16x16x32 | RF: 7x7
3137

3238
# CONVOLUTION BLOCK 2
3339
self.convblock2 = nn.Sequential(
3440
nn.Conv2d(in_channels=32, out_channels=32, kernel_size=(3, 3), padding=1, bias=False),
3541
nn.ReLU(),
3642
nn.BatchNorm2d(32),
37-
nn.Dropout(dropout_value), # Input: 8x8x32 | Output: 6x6x64 | RF: 34x34
43+
nn.Dropout(dropout_value), # Input: 16x16x32 | Output: 16x16x32 | RF: 11x11
3844

3945
#Depthwise Seperable Convolution
46+
47+
# Depthwise Convolution
4048
nn.Conv2d(in_channels=32, out_channels=32, kernel_size=(3, 3), padding=1, groups=32, bias=False),
49+
# Input: 16x16x32 | Output: 16x16x32 | RF: 15x15
50+
51+
# Pointwise Convolution
4152
nn.Conv2d(32, 64, kernel_size=1, padding=1),
53+
# Input: 16x16x32 | Output: 18x18x64 | RF: 15x15
54+
4255
nn.ReLU(),
4356
nn.BatchNorm2d(64),
44-
nn.Dropout(dropout_value), # Input: 16x16x32 | Output: 16x16x64 | RF: 14x14
45-
)
57+
nn.Dropout(dropout_value),
58+
) # Input: 16x16x32 | Output: 18x18x64 | RF: 15x15
4659

4760
# TRANSITION BLOCK 2
4861
self.transblock2 = nn.Sequential(
49-
nn.Conv2d(in_channels=64, out_channels=32, kernel_size=(1, 1)),
62+
# Pointwise Convolution to reduce number of channels
63+
nn.Conv2d(in_channels=64, out_channels=32, kernel_size=(1, 1)), # Input: 18x18x64 | Output: 18x18x32 | RF: 15x15
64+
65+
# Depthwise Convolution with stride=2 to reduce the channel size to half
5066
nn.Conv2d(in_channels=32, out_channels=32, kernel_size=(3, 3), padding=1, stride=2, groups=32, bias=False)
51-
) # Input: 16x16x32 | Output: 8x8x32 | RF: 17x17
67+
# Input: 18x18x32 | Output: 9x9x32 | RF: 19x19
68+
) # Input: 18x18x64 | Output: 9x9x32 | RF: 19x19
5269

5370
# CONVOLUTION BLOCK 3
5471
self.convblock3 = nn.Sequential(
5572
nn.Conv2d(in_channels=32, out_channels=64, kernel_size=(3, 3), padding=1, dilation=2, bias=False),
5673
nn.ReLU(),
5774
nn.BatchNorm2d(64),
58-
nn.Dropout(dropout_value), # Input: 8x8x32 | Output: 6x6x64 | RF: 34x34
75+
nn.Dropout(dropout_value), # Input: 9x9x32 | Output: 7x7x64 | RF: 35x35
5976

6077
nn.Conv2d(in_channels=64, out_channels=64, kernel_size=(3, 3), padding=1, bias=False),
6178
nn.ReLU(),
6279
nn.BatchNorm2d(64),
63-
nn.Dropout(dropout_value), # Input: 16x16x64 | Output: 16x16x64 | RF: 36x36
80+
nn.Dropout(dropout_value), # Input: 7x7x64 | Output: 7x7x64 | RF: 43x43
6481

6582
#Depthwise Seperable Convolution
83+
84+
# Depthwise Convolution
6685
nn.Conv2d(in_channels=64, out_channels=64, kernel_size=(3, 3), padding=1, groups=64, bias=False),
86+
# Input: 7x7x64 | Output: 7x7x64 | RF: 51x51
87+
88+
# Pointwise Convolution
6789
nn.Conv2d(64, 32, kernel_size=1, padding=1),
90+
# Input: 7x7x64 | Output: 9x9x32 | RF: 51x51
91+
6892
nn.ReLU(),
69-
nn.BatchNorm2d(32),# Input: 16x16x32 | Output: 16x16x64 | RF: 14x14
70-
)
93+
nn.BatchNorm2d(32),
94+
) # Input: 9x9x32 | Output: 9x9x32 | RF: 51x51
7195

7296
# TRANSITION BLOCK 3
7397
self.transblock3 = nn.Sequential(
74-
nn.Conv2d(in_channels=32, out_channels=16, kernel_size=(1, 1)),
98+
# Pointwise Convolution to reduce number of channels
99+
nn.Conv2d(in_channels=32, out_channels=16, kernel_size=(1, 1)), # Input: 9x9x32 | Output: 9x9x16 | RF: 51x51
100+
101+
# Depthwise Convolution with stride=2 to reduce the channel size to half
75102
nn.Conv2d(in_channels=16, out_channels=16, kernel_size=(3, 3), padding=1, stride=2, groups=16, bias=False)
76-
)# Input: 16x16x64 | Output: 8x8x32 | RF: 44x44
103+
# Input: 9x9x16 | Output: 5x5x16 | RF: 59x59
104+
)# Input: 9x9x32 | Output: 5x5x16 | RF: 59x59
77105

78106
# CONVOLUTION BLOCK 4
79107
self.convblock4 = nn.Sequential(
80108
nn.Conv2d(in_channels=16, out_channels=10, kernel_size=(3, 3), padding=1, bias=False),
81109
nn.ReLU(),
82110
nn.BatchNorm2d(10),
83-
) # Input: 8x8x32 | Output: 8x8x64 | RF: 46x46
111+
) # Input: 5x5x16 | Output: 5x5x10 | RF: 75x75
84112

85113
# OUTPUT BLOCK
114+
# Average Pooling to obtain 10-output channels of size 1x1
86115
self.opblock = nn.Sequential(
87-
nn.AvgPool2d(kernel_size=5) # Input: 8x8x64 | Output: 1x1x64 | RF: 46x46
88-
#nn.Conv2d(in_channels=32, out_channels=10, kernel_size=(1, 1), padding=0, bias=False),
89-
) # Input: 1x1x64 | Output: 1x1x10 | RF: 46x46
116+
nn.AvgPool2d(kernel_size=5)
117+
118+
) # Input: 5x5x10 | Output: 1x1x10 | RF: 107x107
90119

91120

92121
def forward(self, x):

0 commit comments

Comments
 (0)