ResNet-34
| Layer | # Filters / neurons | Filter Size | Stride | Padding | Size of Feature Map |
|---|---|---|---|---|---|
| Input | - | - | - | - | 224 x 224 x 3 |
| Convolution 1 | 64 | 7 x 7 | 2 | 3 | 112 x 112 x 64 |
| Max Pool 1 | - | 3 x 3 | 2 | 1 | 56 x 56 x 64 |
| Convolution 2_A(Repetition: 6) | 64 | 3 x 3 | 1 | 1 | 56 x 56 x 64 |
| Convolution 3_A | 128 | 3 x 3 | 2 | 1 | 28 x 28 x 128 |
| Convolution 3_B(Repetition: 7) | 128 | 3 x 3 | 1 | 1 | 28 x 28 x 128 |
| Convolution 4_A | 256 | 3 x 3 | 2 | 1 | 14 x 14 x 256 |
| Convolution 4_B(Repetition: 11) | 256 | 3 x 3 | 1 | 1 | 14 x 14 x 256 |
| Convolution 5_A | 512 | 3 x 3 | 2 | 1 | 7 x 7 x 512 |
| Convolution 5_B(Repetition: 5) | 512 | 3 x 3 | 1 | 1 | 7 x 7 x 512 |
| Average Pool 1 | - | 7 x 7 | 1 | - | 1 x 1 x 512 |
| Dense(FC) 1 | 1000 | - | - | - | 1 x 1000 |
| Softmax | 1000 | - | - | - | 1 x 1000 |
StreamlinedNet
| Layer | # Filters / neurons | Filter Size | Stride | Padding | Size of Feature Map |
|---|---|---|---|---|---|
| Input | - | - | - | - | 224 x 224 x 3 |
| Convolution 1 | 64 | 7 x 7 | 2 | 3 | 112 x 112 x 64 |
| Max Pool 1 | - | 3 x 3 | 2 | 1 | 56 x 56 x 64 |
| 1xn Convolution A | 64 | 1 x 9 | 1 | (0, 4) | 56 x 56 x 64 |
| 3x3 Dilated Convolution A | 64 | 3 x 3 | 2 | 2 | 28 x 28 x 128 |
| 1xn Convolution B | |||||
| Shortcuts and Repetition: 3 | 128 | 1 x 9 | 1 | (0, 4) | 28 x 28 x 128 |
| 3x3 Dilated Convolution B | 128 | 3 x 3 | 2 | 2 | 14 x 14 x 256 |
| 1xn Convolution C | |||||
| Shortcuts and Repetition: 4 | 256 | 1 x 9 | 1 | (0, 4) | 14 x 14 x 256 |
| 3x3 Dilated Convolution C | 256 | 3 x 3 | 2 | 2 | 7 x 7 x 512 |
| 1xn Convolution D | |||||
| Shortcuts and Repetition: 5 | 512 | 1 x 7 | 1 | (0, 3) | 7 x 7 x 512 |
| Avgerage Pool 1 | - | 7 x 7 | 1 | - | 1 x 1 x 512 |
| Dense(FC) 1 | 1000 | - | - | - | 1 x 1000 |
| Softmax | 1000 | - | - | - | 1 x 1000 |
Model Code
import torch
class StreamlinedNet(torch.nn.Module):
"""
Implementation of the StreamlinedNet model.
> 1xn or nx1 Convolution, Dilated Convolution
Input: Image tensor (batch_size, 3, 224, 224)
Output: Class scores (batch_size, 1000)
"""
def __init__(self, dropout_rate=0.5):
"""
Args:
dropout_rate (float): Dropout probability (default=0.5)
"""
super(StreamlinedNet, self).__init__()
# Convolutional and pooling layers
# Layer1 > Convolution 1 & Max Pool 1
self.layer1 = torch.nn.Sequential(
ConvolutionalLayer.create(3, 64, 7, 2, 3),
torch.nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
)
# Layer2 > 1xn Convolution 1
self.layer2 = ConvolutionalLayer.create(64, 64, (1, 9), 1, (0, 4))
# Layer3 > 3x3 Dilated Convolution 1
self.layer3 = torch.nn.Sequential(
torch.nn.Conv2d(64, 64, kernel_size=3, stride=2, padding=2, dilation=2),
torch.nn.BatchNorm2d(64),
CustomReLU()
)
# Layer4 > 1xn Convolution 2; Shortcuts and Repetition: 3
self.layer4 = torch.nn.Sequential(
PlainBlock(64, 128, (1, 9), (0, 4)),
*[PlainBlock(128, 128, (1, 9), (0, 4)) for _ in range(2)]
)
# Layer5 > 3x3 Dilated Convolution 2
self.layer5 = torch.nn.Sequential(
torch.nn.Conv2d(128, 128, kernel_size=3, stride=2, padding=2, dilation=2),
torch.nn.BatchNorm2d(128),
CustomReLU()
)
# Layer6 > 1xn Convolution 3; Shortcuts and Repetition: 4
self.layer6 = torch.nn.Sequential(
PlainBlock(128, 256, (1, 9), (0, 4)),
*[PlainBlock(256, 256, (1, 9), (0, 4)) for _ in range(3)]
)
# Layer7 > 3x3 Dilated Convolution 3
self.layer7 = torch.nn.Sequential(
torch.nn.Conv2d(256, 256, kernel_size=3, stride=2, padding=2, dilation=2),
torch.nn.BatchNorm2d(256),
CustomReLU()
)
# Layer8 > 1xn Convolution 4; Shortcuts and Repetition: 5
self.layer8 = torch.nn.Sequential(
PlainBlock(256, 512, (1, 7), (0, 3)),
*[PlainBlock(512, 512, (1, 7), (0, 3)) for _ in range(4)]
)
# Layer9 > Gloval Average Pooling to reduce spatial dimensions to 1x1
self.layer9 = torch.nn.AvgPool2d(kernel_size=7, stride=1, padding=0)
# Fully Connected layers and dropout
self.layer_drop = torch.nn.Dropout(p=dropout_rate)
self.layer10 = FullyConnectedLayer.Dense(1 * 1 * 512, 1000)
self.layer11 = FullyConnectedLayer.Dense(1000, 1000)
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""
Defines the forward pass of the model.
Args:
x (torch.Tensor): Input image tensor (batch_size, 3, 224, 224)
Returns:
torch.Tensor: Class scores (batch_size, 1000)
"""
x = self.layer1(x)
x = self.layer2(x)
x = self.layer3(x)
x = self.layer4(x)
x = self.layer5(x)
x = self.layer6(x)
x = self.layer7(x)
x = self.layer8(x)
x = self.layer9(x)
x = self.layer_drop(x)
x = x.view(x.size(0), -1) # Flatten
x = self.layer10(x)
x = self.layer11(x)
return x
PyTorch Food101
Test0(Kaggle)
[Epoch: 1] cost = 4.66245747 | Train Accuracy = 2.89%
[Epoch: 2] cost = 4.10329485 | Train Accuracy = 7.53%
[Epoch: 3] cost = 3.81392169 | Train Accuracy = 11.65%
[Epoch: 4] cost = 3.59057093 | Train Accuracy = 15.48%
[Epoch: 5] cost = 3.38048482 | Train Accuracy = 19.35%
[Epoch: 6] cost = 3.17903066 | Train Accuracy = 23.22%
[Epoch: 7] cost = 2.99323297 | Train Accuracy = 26.80%
[Epoch: 8] cost = 2.8377564 | Train Accuracy = 30.25%
[Epoch: 9] cost = 2.67238164 | Train Accuracy = 33.66%
[Epoch: 10] cost = 2.52783251 | Train Accuracy = 36.85%
[Epoch: 11] cost = 2.39527988 | Train Accuracy = 39.49%
[Epoch: 12] cost = 2.26512456 | Train Accuracy = 42.37%
[Epoch: 13] cost = 2.14713264 | Train Accuracy = 45.00%
[Epoch: 14] cost = 2.02744007 | Train Accuracy = 47.44%
[Epoch: 15] cost = 1.9079479 | Train Accuracy = 50.32%
[Epoch: 16] cost = 1.78312731 | Train Accuracy = 53.00%
[Epoch: 17] cost = 1.69548333 | Train Accuracy = 54.94%
[Epoch: 18] cost = 1.56390786 | Train Accuracy = 57.66%
[Epoch: 19] cost = 1.42279017 | Train Accuracy = 60.84%
[Epoch: 20] cost = 1.28580725 | Train Accuracy = 64.03%
[Epoch: 21] cost = 1.16848469 | Train Accuracy = 66.77%
[Epoch: 22] cost = 1.04328561 | Train Accuracy = 69.70%
[Epoch: 23] cost = 0.924164772 | Train Accuracy = 72.77%
[Epoch: 24] cost = 0.814349592 | Train Accuracy = 75.44%
[Epoch: 25] cost = 0.729309857 | Train Accuracy = 77.93%
[Epoch: 26] cost = 0.634472549 | Train Accuracy = 80.33%
[Epoch: 27] cost = 0.571774662 | Train Accuracy = 82.18%
[Epoch: 28] cost = 0.516791224 | Train Accuracy = 83.76%
[Epoch: 29] cost = 0.464977682 | Train Accuracy = 85.20%
[Epoch: 30] cost = 0.426421076 | Train Accuracy = 86.37%
[Epoch: 31] cost = 0.408697188 | Train Accuracy = 87.03%
[Epoch: 32] cost = 0.376045227 | Train Accuracy = 88.16%
[Epoch: 33] cost = 0.342416942 | Train Accuracy = 88.97%
[Epoch: 34] cost = 0.328432947 | Train Accuracy = 89.63%
[Epoch: 35] cost = 0.315804303 | Train Accuracy = 90.03%
[Epoch: 36] cost = 0.292550355 | Train Accuracy = 90.66%
[Epoch: 37] cost = 0.284003198 | Train Accuracy = 91.00%
[Epoch: 38] cost = 0.270740956 | Train Accuracy = 91.42%
[Epoch: 39] cost = 0.266808569 | Train Accuracy = 91.52%
[Epoch: 40] cost = 0.24558875 | Train Accuracy = 92.18%
[Epoch: 41] cost = 0.236012876 | Train Accuracy = 92.39%
[Epoch: 42] cost = 0.230435148 | Train Accuracy = 92.72%
[Epoch: 43] cost = 0.244548112 | Train Accuracy = 92.20%
[Epoch: 44] cost = 0.214064136 | Train Accuracy = 93.21%
[Epoch: 45] cost = 0.210372195 | Train Accuracy = 93.36%
[Epoch: 46] cost = 0.205122143 | Train Accuracy = 93.48%
[Epoch: 47] cost = 0.202804595 | Train Accuracy = 93.64%
[Epoch: 48] cost = 0.198964417 | Train Accuracy = 93.74%
[Epoch: 49] cost = 0.185472012 | Train Accuracy = 94.13%
**[Epoch: 50] cost = 0.184777334 | Train Accuracy = 94.23%**
Test1(Google Colab)
[Epoch: 1] cost = 4.63286686 | Train Accuracy = 3.22%
[Epoch: 2] cost = 4.10520792 | Train Accuracy = 7.72%
[Epoch: 3] cost = 3.81570077 | Train Accuracy = 12.10%
[Epoch: 4] cost = 3.55455017 | Train Accuracy = 16.29%
[Epoch: 5] cost = 3.31452513 | Train Accuracy = 20.62%
[Epoch: 6] cost = 3.10248852 | Train Accuracy = 24.72%
[Epoch: 7] cost = 2.91098142 | Train Accuracy = 28.83%
[Epoch: 8] cost = 2.7413168 | Train Accuracy = 32.28%
[Epoch: 9] cost = 2.58862662 | Train Accuracy = 35.32%
[Epoch: 10] cost = 2.43815517 | Train Accuracy = 38.63%
[Epoch: 11] cost = 2.30618572 | Train Accuracy = 41.53%
[Epoch: 12] cost = 2.35105157 | Train Accuracy = 41.13%
[Epoch: 13] cost = 2.18907833 | Train Accuracy = 44.19%
[Epoch: 14] cost = 1.98132408 | Train Accuracy = 48.76%
[Epoch: 15] cost = 1.86699438 | Train Accuracy = 51.35%
[Epoch: 16] cost = 1.73786211 | Train Accuracy = 53.61%
[Epoch: 17] cost = 1.6146971 | Train Accuracy = 56.45%
**[Epoch: 18] cost = 1.49757981 | Train Accuracy = 59.05%**
Test2(Google Colab)
[Epoch: 1] cost = 4.64463949 | Train Accuracy = 3.45%
[Epoch: 2] cost = 4.05979538 | Train Accuracy = 8.33%
[Epoch: 3] cost = 3.75822496 | Train Accuracy = 12.79%
[Epoch: 4] cost = 3.52590299 | Train Accuracy = 16.75%
[Epoch: 5] cost = 3.3062396 | Train Accuracy = 20.89%
[Epoch: 6] cost = 3.10596752 | Train Accuracy = 24.81%
[Epoch: 7] cost = 2.90648746 | Train Accuracy = 28.83%
[Epoch: 8] cost = 2.7514317 | Train Accuracy = 32.24%
[Epoch: 9] cost = 2.5767386 | Train Accuracy = 35.91%
[Epoch: 10] cost = 2.55877733 | Train Accuracy = 36.30%
[Epoch: 11] cost = 2.3319118 | Train Accuracy = 40.91%
[Epoch: 12] cost = 2.20079851 | Train Accuracy = 43.85%
[Epoch: 13] cost = 2.08096933 | Train Accuracy = 46.65%
[Epoch: 14] cost = 1.96262825 | Train Accuracy = 49.00%
[Epoch: 15] cost = 1.85471165 | Train Accuracy = 51.51%
[Epoch: 16] cost = 1.71026862 | Train Accuracy = 54.73%
[Epoch: 17] cost = 1.58452141 | Train Accuracy = 57.11%
**[Epoch: 18] cost = 1.4524734 | Train Accuracy = 60.25%**
Test3(Google Colab)
[Epoch: 1] cost = 4.64526272 | Train Accuracy = 2.85%
[Epoch: 2] cost = 4.0693264 | Train Accuracy = 8.35%
[Epoch: 3] cost = 3.73745489 | Train Accuracy = 13.18%
[Epoch: 4] cost = 3.50912642 | Train Accuracy = 17.11%
[Epoch: 5] cost = 3.37433243 | Train Accuracy = 19.90%
[Epoch: 6] cost = 3.1333003 | Train Accuracy = 24.31%
[Epoch: 7] cost = 2.93988013 | Train Accuracy = 28.06%
[Epoch: 8] cost = 2.7723 | Train Accuracy = 31.56%
[Epoch: 9] cost = 2.621418 | Train Accuracy = 34.82%
[Epoch: 10] cost = 2.46938396 | Train Accuracy = 37.92%
[Epoch: 11] cost = 2.33324432 | Train Accuracy = 40.95%
[Epoch: 12] cost = 2.19547772 | Train Accuracy = 43.85%
[Epoch: 13] cost = 2.06170535 | Train Accuracy = 46.78%
[Epoch: 14] cost = 1.93124735 | Train Accuracy = 49.62%
[Epoch: 15] cost = 1.80505764 | Train Accuracy = 52.55%
[Epoch: 16] cost = 1.66252995 | Train Accuracy = 55.61%
**[Epoch: 17] cost = 1.52216458 | Train Accuracy = 58.56%**
Test4(Google Colab)
[Epoch: 1] cost = 4.69737673 | Train Accuracy = 2.43%
[Epoch: 2] cost = 4.15832233 | Train Accuracy = 6.93%
[Epoch: 3] cost = 3.83768678 | Train Accuracy = 11.54%
[Epoch: 4] cost = 3.62141037 | Train Accuracy = 15.13%
[Epoch: 5] cost = 3.3984046 | Train Accuracy = 19.00%
[Epoch: 6] cost = 3.1942234 | Train Accuracy = 22.97%
[Epoch: 7] cost = 3.00066614 | Train Accuracy = 26.85%
[Epoch: 8] cost = 2.81827188 | Train Accuracy = 30.64%
[Epoch: 9] cost = 2.65976906 | Train Accuracy = 33.93%
[Epoch: 10] cost = 2.51142859 | Train Accuracy = 37.03%
[Epoch: 11] cost = 2.35400581 | Train Accuracy = 40.38%
[Epoch: 12] cost = 2.20701766 | Train Accuracy = 43.46%
[Epoch: 13] cost = 2.07967377 | Train Accuracy = 46.32%
[Epoch: 14] cost = 1.95324934 | Train Accuracy = 49.08%
[Epoch: 15] cost = 1.80599356 | Train Accuracy = 52.29%
[Epoch: 16] cost = 1.65747666 | Train Accuracy = 55.50%
**[Epoch: 17] cost = 1.51262736 | Train Accuracy = 58.78%**
Test5(Google Colab)
[Epoch: 1] cost = 4.65966272 | Train Accuracy = 3.03%
[Epoch: 2] cost = 4.13851261 | Train Accuracy = 7.32%
[Epoch: 3] cost = 3.84493947 | Train Accuracy = 11.52%
[Epoch: 4] cost = 3.59627366 | Train Accuracy = 15.47%
[Epoch: 5] cost = 3.37425065 | Train Accuracy = 19.39%
[Epoch: 6] cost = 3.16760945 | Train Accuracy = 23.31%
[Epoch: 7] cost = 2.9613378 | Train Accuracy = 27.81%
[Epoch: 8] cost = 2.77564049 | Train Accuracy = 31.64%
[Epoch: 9] cost = 2.61471176 | Train Accuracy = 34.73%
[Epoch: 10] cost = 2.46067524 | Train Accuracy = 38.14%
[Epoch: 11] cost = 2.31782818 | Train Accuracy = 41.05%
[Epoch: 12] cost = 2.17893553 | Train Accuracy = 44.09%
[Epoch: 13] cost = 2.04192352 | Train Accuracy = 47.07%
[Epoch: 14] cost = 1.91332364 | Train Accuracy = 49.98%
[Epoch: 15] cost = 1.78040743 | Train Accuracy = 52.89%
[Epoch: 16] cost = 1.64149928 | Train Accuracy = 55.90%
[Epoch: 17] cost = 1.48815262 | Train Accuracy = 59.15%
**[Epoch: 18] cost = 1.33682942 | Train Accuracy = 62.64%**