Professional Documents
Culture Documents
Project Mini
Project Mini
March 6, 2024
0.1 Mobilenet
0.1.1 1. Load the Data
[2]: import torch
import torchvision.transforms as transforms
import torchvision.datasets as datasets
from torch.utils.data import DataLoader
])
# Load dataset
train_dataset = datasets.ImageFolder(root='train', transform=transform)
test_dataset = datasets.ImageFolder(root='test', transform=transform)
[15]: train_dataset.classes
[15]: ['001.Black_footed_Albatross',
'002.Laysan_Albatross',
'003.Sooty_Albatross',
'004.Groove_billed_Ani',
'005.Crested_Auklet',
'006.Least_Auklet',
'007.Parakeet_Auklet',
'008.Rhinoceros_Auklet',
'009.Brewer_Blackbird',
'010.Red_winged_Blackbird',
'011.Rusty_Blackbird',
'012.Yellow_headed_Blackbird',
1
'013.Bobolink',
'014.Indigo_Bunting',
'015.Lazuli_Bunting',
'016.Painted_Bunting',
'017.Cardinal',
'018.Spotted_Catbird',
'019.Gray_Catbird',
'020.Yellow_breasted_Chat',
'021.Eastern_Towhee',
'022.Chuck_will_Widow',
'023.Brandt_Cormorant',
'024.Red_faced_Cormorant',
'025.Pelagic_Cormorant',
'026.Bronzed_Cowbird',
'027.Shiny_Cowbird',
'028.Brown_Creeper',
'029.American_Crow',
'030.Fish_Crow',
'031.Black_billed_Cuckoo',
'032.Mangrove_Cuckoo',
'033.Yellow_billed_Cuckoo',
'034.Gray_crowned_Rosy_Finch',
'035.Purple_Finch',
'036.Northern_Flicker',
'037.Acadian_Flycatcher',
'038.Great_Crested_Flycatcher',
'039.Least_Flycatcher',
'040.Olive_sided_Flycatcher',
'041.Scissor_tailed_Flycatcher',
'042.Vermilion_Flycatcher',
'043.Yellow_bellied_Flycatcher',
'044.Frigatebird',
'045.Northern_Fulmar',
'046.Gadwall',
'047.American_Goldfinch',
'048.European_Goldfinch',
'049.Boat_tailed_Grackle',
'050.Eared_Grebe',
'051.Horned_Grebe',
'052.Pied_billed_Grebe',
'053.Western_Grebe',
'054.Blue_Grosbeak',
'055.Evening_Grosbeak',
'056.Pine_Grosbeak',
'057.Rose_breasted_Grosbeak',
'058.Pigeon_Guillemot',
'059.California_Gull',
2
'060.Glaucous_winged_Gull',
'061.Heermann_Gull',
'062.Herring_Gull',
'063.Ivory_Gull',
'064.Ring_billed_Gull',
'065.Slaty_backed_Gull',
'066.Western_Gull',
'067.Anna_Hummingbird',
'068.Ruby_throated_Hummingbird',
'069.Rufous_Hummingbird',
'070.Green_Violetear',
'071.Long_tailed_Jaeger',
'072.Pomarine_Jaeger',
'073.Blue_Jay',
'074.Florida_Jay',
'075.Green_Jay',
'076.Dark_eyed_Junco',
'077.Tropical_Kingbird',
'078.Gray_Kingbird',
'079.Belted_Kingfisher',
'080.Green_Kingfisher',
'081.Pied_Kingfisher',
'082.Ringed_Kingfisher',
'083.White_breasted_Kingfisher',
'084.Red_legged_Kittiwake',
'085.Horned_Lark',
'086.Pacific_Loon',
'087.Mallard',
'088.Western_Meadowlark',
'089.Hooded_Merganser',
'090.Red_breasted_Merganser',
'091.Mockingbird',
'092.Nighthawk',
'093.Clark_Nutcracker',
'094.White_breasted_Nuthatch',
'095.Baltimore_Oriole',
'096.Hooded_Oriole',
'097.Orchard_Oriole',
'098.Scott_Oriole',
'099.Ovenbird',
'100.Brown_Pelican',
'101.White_Pelican',
'102.Western_Wood_Pewee',
'103.Sayornis',
'104.American_Pipit',
'105.Whip_poor_Will',
'106.Horned_Puffin',
3
'107.Common_Raven',
'108.White_necked_Raven',
'109.American_Redstart',
'110.Geococcyx',
'111.Loggerhead_Shrike',
'112.Great_Grey_Shrike',
'113.Baird_Sparrow',
'114.Black_throated_Sparrow',
'115.Brewer_Sparrow',
'116.Chipping_Sparrow',
'117.Clay_colored_Sparrow',
'118.House_Sparrow',
'119.Field_Sparrow',
'120.Fox_Sparrow',
'121.Grasshopper_Sparrow',
'122.Harris_Sparrow',
'123.Henslow_Sparrow',
'124.Le_Conte_Sparrow',
'125.Lincoln_Sparrow',
'126.Nelson_Sharp_tailed_Sparrow',
'127.Savannah_Sparrow',
'128.Seaside_Sparrow',
'129.Song_Sparrow',
'130.Tree_Sparrow',
'131.Vesper_Sparrow',
'132.White_crowned_Sparrow',
'133.White_throated_Sparrow',
'134.Cape_Glossy_Starling',
'135.Bank_Swallow',
'136.Barn_Swallow',
'137.Cliff_Swallow',
'138.Tree_Swallow',
'139.Scarlet_Tanager',
'140.Summer_Tanager',
'141.Artic_Tern',
'142.Black_Tern',
'143.Caspian_Tern',
'144.Common_Tern',
'145.Elegant_Tern',
'146.Forsters_Tern',
'147.Least_Tern',
'148.Green_tailed_Towhee',
'149.Brown_Thrasher',
'150.Sage_Thrasher',
'151.Black_capped_Vireo',
'152.Blue_headed_Vireo',
'153.Philadelphia_Vireo',
4
'154.Red_eyed_Vireo',
'155.Warbling_Vireo',
'156.White_eyed_Vireo',
'157.Yellow_throated_Vireo',
'158.Bay_breasted_Warbler',
'159.Black_and_white_Warbler',
'160.Black_throated_Blue_Warbler',
'161.Blue_winged_Warbler',
'162.Canada_Warbler',
'163.Cape_May_Warbler',
'164.Cerulean_Warbler',
'165.Chestnut_sided_Warbler',
'166.Golden_winged_Warbler',
'167.Hooded_Warbler',
'168.Kentucky_Warbler',
'169.Magnolia_Warbler',
'170.Mourning_Warbler',
'171.Myrtle_Warbler',
'172.Nashville_Warbler',
'173.Orange_crowned_Warbler',
'174.Palm_Warbler',
'175.Pine_Warbler',
'176.Prairie_Warbler',
'177.Prothonotary_Warbler',
'178.Swainson_Warbler',
'179.Tennessee_Warbler',
'180.Wilson_Warbler',
'181.Worm_eating_Warbler',
'182.Yellow_Warbler',
'183.Northern_Waterthrush',
'184.Louisiana_Waterthrush',
'185.Bohemian_Waxwing',
'186.Cedar_Waxwing',
'187.American_Three_toed_Woodpecker',
'188.Pileated_Woodpecker',
'189.Red_bellied_Woodpecker',
'190.Red_cockaded_Woodpecker',
'191.Red_headed_Woodpecker',
'192.Downy_Woodpecker',
'193.Bewick_Wren',
'194.Cactus_Wren',
'195.Carolina_Wren',
'196.House_Wren',
'197.Marsh_Wren',
'198.Rock_Wren',
'199.Winter_Wren',
'200.Common_Yellowthroat']
5
0.1.2 2. Initialise the Training Model
Here, we are using the Mobile Net Architecture for the same since it has proved to be fast and at
the same time has good accuracy
# Modify the last fully connected layer for the number of classes in your␣
↪dataset
num_classes = len(train_dataset.classes)
mobilenet.classifier[1] = nn.Linear(in_features=1280, out_features=num_classes)
C:\Users\ASUS\anaconda3\lib\site-packages\torchvision\models\_utils.py:208:
UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be
removed in the future, please use 'weights' instead.
warnings.warn(
C:\Users\ASUS\anaconda3\lib\site-packages\torchvision\models\_utils.py:223:
UserWarning: Arguments other than a weight enum or `None` for 'weights' are
deprecated since 0.13 and may be removed in the future. The current behavior is
equivalent to passing `weights=MobileNet_V2_Weights.IMAGENET1K_V1`. You can also
use `weights=MobileNet_V2_Weights.DEFAULT` to get the most up-to-date weights.
warnings.warn(msg)
Downloading: "https://download.pytorch.org/models/mobilenet_v2-b0353104.pth" to
C:\Users\ASUS/.cache\torch\hub\checkpoints\mobilenet_v2-b0353104.pth
100%|���������������������������������������������������������������������������
��| 13.6M/13.6M [00:02<00:00, 5.51MB/s]
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(mobilenet.parameters(), lr=0.001)
6
def train_m(model, train_loader, criterion, optimizer, num_epochs=30):
train_losses = []
train_accuracy = []
optimizer.zero_grad()
outputs = model(inputs)
loss = criterion(outputs, labels)
loss.backward()
optimizer.step()
running_loss += loss.item()
_, predicted = outputs.max(1)
total += labels.size(0)
correct += predicted.eq(labels).sum().item()
7
Epoch [9/30], Loss: 0.1964, Accuracy: 97.58%
Epoch [10/30], Loss: 0.1796, Accuracy: 98.01%
Epoch [11/30], Loss: 0.1658, Accuracy: 98.65%
Epoch [12/30], Loss: 0.1613, Accuracy: 97.85%
Epoch [13/30], Loss: 0.1466, Accuracy: 98.33%
Epoch [14/30], Loss: 0.1360, Accuracy: 98.72%
Epoch [15/30], Loss: 0.1280, Accuracy: 98.67%
Epoch [16/30], Loss: 0.1220, Accuracy: 98.88%
Epoch [17/30], Loss: 0.1200, Accuracy: 98.67%
Epoch [18/30], Loss: 0.1089, Accuracy: 99.03%
Epoch [19/30], Loss: 0.1046, Accuracy: 99.02%
Epoch [20/30], Loss: 0.0983, Accuracy: 99.03%
Epoch [21/30], Loss: 0.0903, Accuracy: 99.18%
Epoch [22/30], Loss: 0.0901, Accuracy: 99.20%
Epoch [23/30], Loss: 0.0840, Accuracy: 99.20%
Epoch [24/30], Loss: 0.0829, Accuracy: 99.17%
Epoch [25/30], Loss: 0.0815, Accuracy: 99.08%
Epoch [26/30], Loss: 0.0783, Accuracy: 99.17%
Epoch [27/30], Loss: 0.0738, Accuracy: 99.25%
Epoch [28/30], Loss: 0.0730, Accuracy: 99.12%
Epoch [29/30], Loss: 0.0727, Accuracy: 99.18%
Epoch [30/30], Loss: 0.0722, Accuracy: 99.12%
# Plot architecture
print(mobilenet)
MobileNetV2(
(features): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(3, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1),
bias=False)
(1): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
8
(1): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1),
groups=32, bias=False)
(1): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2d(32, 16, kernel_size=(1, 1), stride=(1, 1), bias=False)
(2): BatchNorm2d(16, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(2): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(16, 96, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(96, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(96, 96, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1),
groups=96, bias=False)
(1): BatchNorm2d(96, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(2): Conv2d(96, 24, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(24, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(3): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(24, 144, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(144, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(144, 144, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), groups=144, bias=False)
(1): BatchNorm2d(144, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
9
)
(2): Conv2d(144, 24, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(24, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(4): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(24, 144, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(144, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(144, 144, kernel_size=(3, 3), stride=(2, 2), padding=(1,
1), groups=144, bias=False)
(1): BatchNorm2d(144, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(2): Conv2d(144, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(5): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(32, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(192, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(192, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), groups=192, bias=False)
(1): BatchNorm2d(192, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(2): Conv2d(192, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(6): InvertedResidual(
(conv): Sequential(
10
(0): Conv2dNormActivation(
(0): Conv2d(32, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(192, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(192, 192, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), groups=192, bias=False)
(1): BatchNorm2d(192, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(2): Conv2d(192, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(7): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(32, 192, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(192, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(192, 192, kernel_size=(3, 3), stride=(2, 2), padding=(1,
1), groups=192, bias=False)
(1): BatchNorm2d(192, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(2): Conv2d(192, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(8): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(64, 384, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(384, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1,
11
1), groups=384, bias=False)
(1): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(2): Conv2d(384, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(9): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(64, 384, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(384, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), groups=384, bias=False)
(1): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(2): Conv2d(384, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(10): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(64, 384, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(384, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), groups=384, bias=False)
(1): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(2): Conv2d(384, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
12
)
)
(11): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(64, 384, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(384, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), groups=384, bias=False)
(1): BatchNorm2d(384, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(2): Conv2d(384, 96, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(96, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(12): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(96, 576, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(576, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(576, 576, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), groups=576, bias=False)
(1): BatchNorm2d(576, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(2): Conv2d(576, 96, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(96, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(13): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(96, 576, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(576, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
13
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(576, 576, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), groups=576, bias=False)
(1): BatchNorm2d(576, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(2): Conv2d(576, 96, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(96, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(14): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(96, 576, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(576, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(576, 576, kernel_size=(3, 3), stride=(2, 2), padding=(1,
1), groups=576, bias=False)
(1): BatchNorm2d(576, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(2): Conv2d(576, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(15): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(160, 960, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(960, 960, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), groups=960, bias=False)
(1): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
14
)
(2): Conv2d(960, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(16): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(160, 960, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(960, 960, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), groups=960, bias=False)
(1): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(2): Conv2d(960, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(17): InvertedResidual(
(conv): Sequential(
(0): Conv2dNormActivation(
(0): Conv2d(160, 960, kernel_size=(1, 1), stride=(1, 1), bias=False)
(1): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(1): Conv2dNormActivation(
(0): Conv2d(960, 960, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), groups=960, bias=False)
(1): BatchNorm2d(960, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
(2): Conv2d(960, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)
(3): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(18): Conv2dNormActivation(
(0): Conv2d(320, 1280, kernel_size=(1, 1), stride=(1, 1), bias=False)
15
(1): BatchNorm2d(1280, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(2): ReLU6(inplace=True)
)
)
(classifier): Sequential(
(0): Dropout(p=0.2, inplace=False)
(1): Linear(in_features=1280, out_features=200, bias=True)
)
)
[48]: device
[48]: device(type='cuda')
16
with torch.no_grad():
for inputs, labels in test_loader:
inputs, labels = inputs.to(device), labels.to(device)
outputs = model(inputs)
_, predicted = torch.max(outputs, 1)
total += labels.size(0)
correct += (predicted == labels).sum().item()
evaluate_m(mobilenet, test_loader)
0.2 Inception
[ ]:
17
0.2.2 2. Load the Data
[53]: import torchvision.transforms as transforms
from torchvision.datasets import ImageFolder
from torch.utils.data import DataLoader
])
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(inception_model.parameters(), lr=0.001)
18
optimizer.zero_grad()
# Forward pass
outputs, aux_outputs = model(inputs)
# Calculate loss
loss = criterion(main_outputs, labels)
running_loss += loss.item()
# Calculate accuracy
_, predicted = main_outputs.max(1)
total += labels.size(0)
correct += predicted.eq(labels).sum().item()
19
Epoch [11/20], Loss: 0.9476, Accuracy: 76.24%
Epoch [12/20], Loss: 0.8681, Accuracy: 78.45%
Epoch [13/20], Loss: 0.8172, Accuracy: 79.13%
Epoch [14/20], Loss: 0.7826, Accuracy: 80.25%
Epoch [15/20], Loss: 0.7598, Accuracy: 80.53%
Epoch [16/20], Loss: 0.6949, Accuracy: 82.20%
Epoch [17/20], Loss: 0.7028, Accuracy: 81.26%
Epoch [18/20], Loss: 0.6456, Accuracy: 82.35%
Epoch [19/20], Loss: 0.6203, Accuracy: 83.60%
Epoch [20/20], Loss: 0.6106, Accuracy: 83.88%
[59]: ([4.510051303721489,
2.9086139341618154,
2.240238940462153,
1.8574077417241766,
1.634935606667336,
1.4252428710460663,
1.2798798058895355,
1.1566238967662161,
1.0691858834408698,
1.000948575265864,
0.947598285973072,
0.8681064024567604,
0.8172275359009175,
0.7825873259534227,
0.7598109075680692,
0.694906362669265,
0.702841191691287,
0.6455970829788674,
0.6202751841950924,
0.6106431853580983],
[12.178845512178846,
36.97030363697031,
49.1991991991992,
57.741074407741074,
61.94527861194528,
66.59993326659993,
69.70303636970304,
72.82282282282283,
74.02402402402403,
75.95929262595929,
76.24290957624291,
78.44511177844511,
79.12912912912913,
80.24691358024691,
80.53053053053053,
82.19886553219887,
20
81.2645979312646,
82.34901568234902,
83.60026693360027,
83.88388388388388])
with torch.no_grad():
for inputs, labels in test_loader:
inputs, labels = inputs.to(device), labels.to(device)
outputs = model(inputs)
_, predicted = torch.max(outputs, 1)
total += labels.size(0)
correct += (predicted == labels).sum().item()
evaluate(inception_model, test_loader)
plt.subplot(1, 2, 2)
plt.plot(train_accuracy, label='Train Accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy (%)')
plt.title('Training Accuracy Curve')
21
plt.legend()
plt.show()
0.3 EfficientNet
[ ]:
Collecting efficientnet_pytorch
Downloading efficientnet_pytorch-0.7.1.tar.gz (21 kB)
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status 'done'
Requirement already satisfied: torch in c:\users\asus\anaconda3\lib\site-
packages (from efficientnet_pytorch) (2.1.0+cu118)
Requirement already satisfied: filelock in c:\users\asus\anaconda3\lib\site-
packages (from torch->efficientnet_pytorch) (3.6.0)
Requirement already satisfied: typing-extensions in
c:\users\asus\anaconda3\lib\site-packages (from torch->efficientnet_pytorch)
(4.7.1)
Requirement already satisfied: sympy in c:\users\asus\anaconda3\lib\site-
packages (from torch->efficientnet_pytorch) (1.10.1)
Requirement already satisfied: networkx in c:\users\asus\anaconda3\lib\site-
packages (from torch->efficientnet_pytorch) (2.7.1)
Requirement already satisfied: jinja2 in c:\users\asus\anaconda3\lib\site-
packages (from torch->efficientnet_pytorch) (3.1.3)
Requirement already satisfied: fsspec in c:\users\asus\anaconda3\lib\site-
22
packages (from torch->efficientnet_pytorch) (2024.2.0)
Requirement already satisfied: MarkupSafe>=2.0 in
c:\users\asus\anaconda3\lib\site-packages (from
jinja2->torch->efficientnet_pytorch) (2.0.1)
Requirement already satisfied: mpmath>=0.19 in c:\users\asus\anaconda3\lib\site-
packages (from sympy->torch->efficientnet_pytorch) (1.2.1)
Building wheels for collected packages: efficientnet_pytorch
Building wheel for efficientnet_pytorch (setup.py): started
Building wheel for efficientnet_pytorch (setup.py): finished with status
'done'
Created wheel for efficientnet_pytorch:
filename=efficientnet_pytorch-0.7.1-py3-none-any.whl size=16428
sha256=7e66585381237a390daa1f439fd5ee3f06ee24e47402634d0b009bfb9c1d7e10
Stored in directory: c:\users\asus\appdata\local\pip\cache\wheels\29\16\24\752
e89d88d333af39a288421e64d613b5f652918e39ef1f8e3
Successfully built efficientnet_pytorch
Installing collected packages: efficientnet_pytorch
Successfully installed efficientnet_pytorch-0.7.1
# Define transforms
transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])
# Load datasets
train_dataset = datasets.ImageFolder('train/', transform=transform)
test_dataset = datasets.ImageFolder('test/', transform=transform)
23
test_loader = torch.utils.data.DataLoader(test_dataset, batch_size=32)
[69]: efficientnet
[69]: EfficientNet(
(_conv_stem): Conv2dStaticSamePadding(
3, 32, kernel_size=(3, 3), stride=(2, 2), bias=False
(static_padding): ZeroPad2d((0, 1, 0, 1))
)
(_bn0): BatchNorm2d(32, eps=0.001, momentum=0.010000000000000009, affine=True,
track_running_stats=True)
(_blocks): ModuleList(
(0): MBConvBlock(
(_depthwise_conv): Conv2dStaticSamePadding(
32, 32, kernel_size=(3, 3), stride=[1, 1], groups=32, bias=False
(static_padding): ZeroPad2d((1, 1, 1, 1))
)
(_bn1): BatchNorm2d(32, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_se_reduce): Conv2dStaticSamePadding(
32, 8, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_se_expand): Conv2dStaticSamePadding(
8, 32, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_project_conv): Conv2dStaticSamePadding(
32, 16, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn2): BatchNorm2d(16, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
24
(_swish): MemoryEfficientSwish()
)
(1): MBConvBlock(
(_expand_conv): Conv2dStaticSamePadding(
16, 96, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn0): BatchNorm2d(96, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_depthwise_conv): Conv2dStaticSamePadding(
96, 96, kernel_size=(3, 3), stride=[2, 2], groups=96, bias=False
(static_padding): ZeroPad2d((0, 1, 0, 1))
)
(_bn1): BatchNorm2d(96, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_se_reduce): Conv2dStaticSamePadding(
96, 4, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_se_expand): Conv2dStaticSamePadding(
4, 96, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_project_conv): Conv2dStaticSamePadding(
96, 24, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn2): BatchNorm2d(24, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_swish): MemoryEfficientSwish()
)
(2): MBConvBlock(
(_expand_conv): Conv2dStaticSamePadding(
24, 144, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn0): BatchNorm2d(144, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_depthwise_conv): Conv2dStaticSamePadding(
144, 144, kernel_size=(3, 3), stride=(1, 1), groups=144, bias=False
(static_padding): ZeroPad2d((1, 1, 1, 1))
)
(_bn1): BatchNorm2d(144, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_se_reduce): Conv2dStaticSamePadding(
144, 6, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
25
)
(_se_expand): Conv2dStaticSamePadding(
6, 144, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_project_conv): Conv2dStaticSamePadding(
144, 24, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn2): BatchNorm2d(24, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_swish): MemoryEfficientSwish()
)
(3): MBConvBlock(
(_expand_conv): Conv2dStaticSamePadding(
24, 144, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn0): BatchNorm2d(144, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_depthwise_conv): Conv2dStaticSamePadding(
144, 144, kernel_size=(5, 5), stride=[2, 2], groups=144, bias=False
(static_padding): ZeroPad2d((1, 2, 1, 2))
)
(_bn1): BatchNorm2d(144, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_se_reduce): Conv2dStaticSamePadding(
144, 6, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_se_expand): Conv2dStaticSamePadding(
6, 144, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_project_conv): Conv2dStaticSamePadding(
144, 40, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn2): BatchNorm2d(40, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_swish): MemoryEfficientSwish()
)
(4): MBConvBlock(
(_expand_conv): Conv2dStaticSamePadding(
40, 240, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
26
(_bn0): BatchNorm2d(240, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_depthwise_conv): Conv2dStaticSamePadding(
240, 240, kernel_size=(5, 5), stride=(1, 1), groups=240, bias=False
(static_padding): ZeroPad2d((2, 2, 2, 2))
)
(_bn1): BatchNorm2d(240, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_se_reduce): Conv2dStaticSamePadding(
240, 10, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_se_expand): Conv2dStaticSamePadding(
10, 240, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_project_conv): Conv2dStaticSamePadding(
240, 40, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn2): BatchNorm2d(40, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_swish): MemoryEfficientSwish()
)
(5): MBConvBlock(
(_expand_conv): Conv2dStaticSamePadding(
40, 240, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn0): BatchNorm2d(240, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_depthwise_conv): Conv2dStaticSamePadding(
240, 240, kernel_size=(3, 3), stride=[2, 2], groups=240, bias=False
(static_padding): ZeroPad2d((0, 1, 0, 1))
)
(_bn1): BatchNorm2d(240, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_se_reduce): Conv2dStaticSamePadding(
240, 10, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_se_expand): Conv2dStaticSamePadding(
10, 240, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_project_conv): Conv2dStaticSamePadding(
240, 80, kernel_size=(1, 1), stride=(1, 1), bias=False
27
(static_padding): Identity()
)
(_bn2): BatchNorm2d(80, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_swish): MemoryEfficientSwish()
)
(6-7): 2 x MBConvBlock(
(_expand_conv): Conv2dStaticSamePadding(
80, 480, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn0): BatchNorm2d(480, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_depthwise_conv): Conv2dStaticSamePadding(
480, 480, kernel_size=(3, 3), stride=(1, 1), groups=480, bias=False
(static_padding): ZeroPad2d((1, 1, 1, 1))
)
(_bn1): BatchNorm2d(480, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_se_reduce): Conv2dStaticSamePadding(
480, 20, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_se_expand): Conv2dStaticSamePadding(
20, 480, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_project_conv): Conv2dStaticSamePadding(
480, 80, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn2): BatchNorm2d(80, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_swish): MemoryEfficientSwish()
)
(8): MBConvBlock(
(_expand_conv): Conv2dStaticSamePadding(
80, 480, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn0): BatchNorm2d(480, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_depthwise_conv): Conv2dStaticSamePadding(
480, 480, kernel_size=(5, 5), stride=[1, 1], groups=480, bias=False
(static_padding): ZeroPad2d((2, 2, 2, 2))
)
(_bn1): BatchNorm2d(480, eps=0.001, momentum=0.010000000000000009,
28
affine=True, track_running_stats=True)
(_se_reduce): Conv2dStaticSamePadding(
480, 20, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_se_expand): Conv2dStaticSamePadding(
20, 480, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_project_conv): Conv2dStaticSamePadding(
480, 112, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn2): BatchNorm2d(112, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_swish): MemoryEfficientSwish()
)
(9-10): 2 x MBConvBlock(
(_expand_conv): Conv2dStaticSamePadding(
112, 672, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn0): BatchNorm2d(672, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_depthwise_conv): Conv2dStaticSamePadding(
672, 672, kernel_size=(5, 5), stride=(1, 1), groups=672, bias=False
(static_padding): ZeroPad2d((2, 2, 2, 2))
)
(_bn1): BatchNorm2d(672, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_se_reduce): Conv2dStaticSamePadding(
672, 28, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_se_expand): Conv2dStaticSamePadding(
28, 672, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_project_conv): Conv2dStaticSamePadding(
672, 112, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn2): BatchNorm2d(112, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_swish): MemoryEfficientSwish()
)
(11): MBConvBlock(
29
(_expand_conv): Conv2dStaticSamePadding(
112, 672, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn0): BatchNorm2d(672, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_depthwise_conv): Conv2dStaticSamePadding(
672, 672, kernel_size=(5, 5), stride=[2, 2], groups=672, bias=False
(static_padding): ZeroPad2d((1, 2, 1, 2))
)
(_bn1): BatchNorm2d(672, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_se_reduce): Conv2dStaticSamePadding(
672, 28, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_se_expand): Conv2dStaticSamePadding(
28, 672, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_project_conv): Conv2dStaticSamePadding(
672, 192, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn2): BatchNorm2d(192, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_swish): MemoryEfficientSwish()
)
(12-14): 3 x MBConvBlock(
(_expand_conv): Conv2dStaticSamePadding(
192, 1152, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn0): BatchNorm2d(1152, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_depthwise_conv): Conv2dStaticSamePadding(
1152, 1152, kernel_size=(5, 5), stride=(1, 1), groups=1152, bias=False
(static_padding): ZeroPad2d((2, 2, 2, 2))
)
(_bn1): BatchNorm2d(1152, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_se_reduce): Conv2dStaticSamePadding(
1152, 48, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_se_expand): Conv2dStaticSamePadding(
48, 1152, kernel_size=(1, 1), stride=(1, 1)
30
(static_padding): Identity()
)
(_project_conv): Conv2dStaticSamePadding(
1152, 192, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn2): BatchNorm2d(192, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_swish): MemoryEfficientSwish()
)
(15): MBConvBlock(
(_expand_conv): Conv2dStaticSamePadding(
192, 1152, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn0): BatchNorm2d(1152, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_depthwise_conv): Conv2dStaticSamePadding(
1152, 1152, kernel_size=(3, 3), stride=[1, 1], groups=1152, bias=False
(static_padding): ZeroPad2d((1, 1, 1, 1))
)
(_bn1): BatchNorm2d(1152, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_se_reduce): Conv2dStaticSamePadding(
1152, 48, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_se_expand): Conv2dStaticSamePadding(
48, 1152, kernel_size=(1, 1), stride=(1, 1)
(static_padding): Identity()
)
(_project_conv): Conv2dStaticSamePadding(
1152, 320, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn2): BatchNorm2d(320, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_swish): MemoryEfficientSwish()
)
)
(_conv_head): Conv2dStaticSamePadding(
320, 1280, kernel_size=(1, 1), stride=(1, 1), bias=False
(static_padding): Identity()
)
(_bn1): BatchNorm2d(1280, eps=0.001, momentum=0.010000000000000009,
affine=True, track_running_stats=True)
(_avg_pooling): AdaptiveAvgPool2d(output_size=1)
31
(_dropout): Dropout(p=0.2, inplace=False)
(_fc): Linear(in_features=1280, out_features=200, bias=True)
(_swish): MemoryEfficientSwish()
)
[ ]:
train_losses = []
train_accuracy = []
optimizer.zero_grad()
outputs = model(inputs)
loss = criterion(outputs, labels)
loss.backward()
optimizer.step()
running_loss += loss.item()
_, predicted = torch.max(outputs, 1)
total += labels.size(0)
correct += (predicted == labels).sum().item()
32
# Train the model
train_losses_e, train_accuracy_e = train_efficient(efficientnet, train_loader,␣
↪criterion, optimizer)
plt.subplot(1, 2, 2)
plt.plot(train_accuracy_e, label='Training Accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy (%)')
plt.title('Training Accuracy Curve')
plt.legend()
plt.show()
33
0.3.4 5. Evaluate the Model
[72]: # Evaluate the model on the test set
def evaluate_efficient(model, test_loader):
model.eval()
correct = 0
total = 0
with torch.no_grad():
for inputs, labels in test_loader:
inputs, labels = inputs.to(device), labels.to(device)
outputs = model(inputs)
_, predicted = torch.max(outputs, 1)
total += labels.size(0)
correct += (predicted == labels).sum().item()
34
[ ]:
0.4 Resnet
[ ]:
# Load dataset
train_dataset = datasets.ImageFolder('train', transform=transform)
test_dataset = datasets.ImageFolder('test', transform=transform)
# Modify the fully connected layer to match the number of classes in your␣
↪dataset
num_classes = len(train_dataset.classes)
model_resnet.fc = nn.Linear(model_resnet.fc.in_features, num_classes)
35
0.4.2 3. Define the Training Loop and also 5. Evaluating on the Go
[85]: # Training function
def train_resnet(model, train_loader, criterion, optimizer, num_epochs=10):
train_losses_resnet = []
train_accuracies_resnet = []
test_losses_resnet = []
test_accuracies_resnet = []
running_loss += loss.item()
_, predicted = torch.max(outputs, 1)
total += labels.size(0)
correct += (predicted == labels).sum().item()
test_loss /= len(test_loader)
test_accuracy = correct / total
36
test_losses_resnet.append(test_loss)
test_accuracies_resnet.append(test_accuracy)
↪criterion, optimizer)
Epoch 1/10, Train Loss: 3.8045, Train Acc: 0.1775, Test Loss: 2.9566, Test Acc:
0.2639
Epoch 2/10, Train Loss: 1.9243, Train Acc: 0.4973, Test Loss: 2.4500, Test Acc:
0.3650
Epoch 3/10, Train Loss: 1.1237, Train Acc: 0.6862, Test Loss: 2.0689, Test Acc:
0.4693
Epoch 4/10, Train Loss: 0.5782, Train Acc: 0.8465, Test Loss: 1.8525, Test Acc:
0.5133
Epoch 5/10, Train Loss: 0.2601, Train Acc: 0.9451, Test Loss: 1.6606, Test Acc:
0.5773
Epoch 6/10, Train Loss: 0.0960, Train Acc: 0.9823, Test Loss: 1.5652, Test Acc:
0.6044
Epoch 7/10, Train Loss: 0.0349, Train Acc: 0.9970, Test Loss: 1.3196, Test Acc:
0.6624
Epoch 8/10, Train Loss: 0.0117, Train Acc: 0.9995, Test Loss: 1.2459, Test Acc:
0.6707
Epoch 9/10, Train Loss: 0.0047, Train Acc: 0.9998, Test Loss: 1.1885, Test Acc:
0.6907
Epoch 10/10, Train Loss: 0.0029, Train Acc: 1.0000, Test Loss: 1.1718, Test Acc:
0.6919
37
plt.title('Training and Test Loss')
plt.legend()
plt.show()
plt.figure(figsize=(10, 5))
plt.plot(train_accuracies_resnet, label='Train Accuracy')
plt.plot(test_accuracies_resnet, label='Test Accuracy')
plt.xlabel('Epochs')
plt.ylabel('Accuracy')
plt.title('Training and Test Accuracy')
plt.legend()
plt.show()
38
[121]: import torch
import torchvision.models as models
from torchsummary import summary
from graphviz import Digraph
39
dot.node(layer_name, label=f"{layer_name}\n{input_shape} ->␣
↪{output_shape}\nParams: {params}")
if 'Conv' in layer_name:
dot.attr('node', shape='rectangle')
return dot
----------------------------------------------------------------
Layer (type) Output Shape Param #
================================================================
ZeroPad2d-1 [-1, 3, 225, 225] 0
Conv2dStaticSamePadding-2 [-1, 32, 112, 112] 864
BatchNorm2d-3 [-1, 32, 112, 112] 64
MemoryEfficientSwish-4 [-1, 32, 112, 112] 0
ZeroPad2d-5 [-1, 32, 114, 114] 0
Conv2dStaticSamePadding-6 [-1, 32, 112, 112] 288
BatchNorm2d-7 [-1, 32, 112, 112] 64
MemoryEfficientSwish-8 [-1, 32, 112, 112] 0
Identity-9 [-1, 32, 1, 1] 0
Conv2dStaticSamePadding-10 [-1, 8, 1, 1] 264
MemoryEfficientSwish-11 [-1, 8, 1, 1] 0
Identity-12 [-1, 8, 1, 1] 0
Conv2dStaticSamePadding-13 [-1, 32, 1, 1] 288
Identity-14 [-1, 32, 112, 112] 0
Conv2dStaticSamePadding-15 [-1, 16, 112, 112] 512
BatchNorm2d-16 [-1, 16, 112, 112] 32
MBConvBlock-17 [-1, 16, 112, 112] 0
Identity-18 [-1, 16, 112, 112] 0
Conv2dStaticSamePadding-19 [-1, 96, 112, 112] 1,536
BatchNorm2d-20 [-1, 96, 112, 112] 192
MemoryEfficientSwish-21 [-1, 96, 112, 112] 0
ZeroPad2d-22 [-1, 96, 113, 113] 0
Conv2dStaticSamePadding-23 [-1, 96, 56, 56] 864
BatchNorm2d-24 [-1, 96, 56, 56] 192
MemoryEfficientSwish-25 [-1, 96, 56, 56] 0
Identity-26 [-1, 96, 1, 1] 0
Conv2dStaticSamePadding-27 [-1, 4, 1, 1] 388
MemoryEfficientSwish-28 [-1, 4, 1, 1] 0
40
Identity-29 [-1, 4, 1, 1] 0
Conv2dStaticSamePadding-30 [-1, 96, 1, 1] 480
Identity-31 [-1, 96, 56, 56] 0
Conv2dStaticSamePadding-32 [-1, 24, 56, 56] 2,304
BatchNorm2d-33 [-1, 24, 56, 56] 48
MBConvBlock-34 [-1, 24, 56, 56] 0
Identity-35 [-1, 24, 56, 56] 0
Conv2dStaticSamePadding-36 [-1, 144, 56, 56] 3,456
BatchNorm2d-37 [-1, 144, 56, 56] 288
MemoryEfficientSwish-38 [-1, 144, 56, 56] 0
ZeroPad2d-39 [-1, 144, 58, 58] 0
Conv2dStaticSamePadding-40 [-1, 144, 56, 56] 1,296
BatchNorm2d-41 [-1, 144, 56, 56] 288
MemoryEfficientSwish-42 [-1, 144, 56, 56] 0
Identity-43 [-1, 144, 1, 1] 0
Conv2dStaticSamePadding-44 [-1, 6, 1, 1] 870
MemoryEfficientSwish-45 [-1, 6, 1, 1] 0
Identity-46 [-1, 6, 1, 1] 0
Conv2dStaticSamePadding-47 [-1, 144, 1, 1] 1,008
Identity-48 [-1, 144, 56, 56] 0
Conv2dStaticSamePadding-49 [-1, 24, 56, 56] 3,456
BatchNorm2d-50 [-1, 24, 56, 56] 48
MBConvBlock-51 [-1, 24, 56, 56] 0
Identity-52 [-1, 24, 56, 56] 0
Conv2dStaticSamePadding-53 [-1, 144, 56, 56] 3,456
BatchNorm2d-54 [-1, 144, 56, 56] 288
MemoryEfficientSwish-55 [-1, 144, 56, 56] 0
ZeroPad2d-56 [-1, 144, 59, 59] 0
Conv2dStaticSamePadding-57 [-1, 144, 28, 28] 3,600
BatchNorm2d-58 [-1, 144, 28, 28] 288
MemoryEfficientSwish-59 [-1, 144, 28, 28] 0
Identity-60 [-1, 144, 1, 1] 0
Conv2dStaticSamePadding-61 [-1, 6, 1, 1] 870
MemoryEfficientSwish-62 [-1, 6, 1, 1] 0
Identity-63 [-1, 6, 1, 1] 0
Conv2dStaticSamePadding-64 [-1, 144, 1, 1] 1,008
Identity-65 [-1, 144, 28, 28] 0
Conv2dStaticSamePadding-66 [-1, 40, 28, 28] 5,760
BatchNorm2d-67 [-1, 40, 28, 28] 80
MBConvBlock-68 [-1, 40, 28, 28] 0
Identity-69 [-1, 40, 28, 28] 0
Conv2dStaticSamePadding-70 [-1, 240, 28, 28] 9,600
BatchNorm2d-71 [-1, 240, 28, 28] 480
MemoryEfficientSwish-72 [-1, 240, 28, 28] 0
ZeroPad2d-73 [-1, 240, 32, 32] 0
Conv2dStaticSamePadding-74 [-1, 240, 28, 28] 6,000
BatchNorm2d-75 [-1, 240, 28, 28] 480
MemoryEfficientSwish-76 [-1, 240, 28, 28] 0
41
Identity-77 [-1, 240, 1, 1] 0
Conv2dStaticSamePadding-78 [-1, 10, 1, 1] 2,410
MemoryEfficientSwish-79 [-1, 10, 1, 1] 0
Identity-80 [-1, 10, 1, 1] 0
Conv2dStaticSamePadding-81 [-1, 240, 1, 1] 2,640
Identity-82 [-1, 240, 28, 28] 0
Conv2dStaticSamePadding-83 [-1, 40, 28, 28] 9,600
BatchNorm2d-84 [-1, 40, 28, 28] 80
MBConvBlock-85 [-1, 40, 28, 28] 0
Identity-86 [-1, 40, 28, 28] 0
Conv2dStaticSamePadding-87 [-1, 240, 28, 28] 9,600
BatchNorm2d-88 [-1, 240, 28, 28] 480
MemoryEfficientSwish-89 [-1, 240, 28, 28] 0
ZeroPad2d-90 [-1, 240, 29, 29] 0
Conv2dStaticSamePadding-91 [-1, 240, 14, 14] 2,160
BatchNorm2d-92 [-1, 240, 14, 14] 480
MemoryEfficientSwish-93 [-1, 240, 14, 14] 0
Identity-94 [-1, 240, 1, 1] 0
Conv2dStaticSamePadding-95 [-1, 10, 1, 1] 2,410
MemoryEfficientSwish-96 [-1, 10, 1, 1] 0
Identity-97 [-1, 10, 1, 1] 0
Conv2dStaticSamePadding-98 [-1, 240, 1, 1] 2,640
Identity-99 [-1, 240, 14, 14] 0
Conv2dStaticSamePadding-100 [-1, 80, 14, 14] 19,200
BatchNorm2d-101 [-1, 80, 14, 14] 160
MBConvBlock-102 [-1, 80, 14, 14] 0
Identity-103 [-1, 80, 14, 14] 0
Conv2dStaticSamePadding-104 [-1, 480, 14, 14] 38,400
BatchNorm2d-105 [-1, 480, 14, 14] 960
MemoryEfficientSwish-106 [-1, 480, 14, 14] 0
ZeroPad2d-107 [-1, 480, 16, 16] 0
Conv2dStaticSamePadding-108 [-1, 480, 14, 14] 4,320
BatchNorm2d-109 [-1, 480, 14, 14] 960
MemoryEfficientSwish-110 [-1, 480, 14, 14] 0
Identity-111 [-1, 480, 1, 1] 0
Conv2dStaticSamePadding-112 [-1, 20, 1, 1] 9,620
MemoryEfficientSwish-113 [-1, 20, 1, 1] 0
Identity-114 [-1, 20, 1, 1] 0
Conv2dStaticSamePadding-115 [-1, 480, 1, 1] 10,080
Identity-116 [-1, 480, 14, 14] 0
Conv2dStaticSamePadding-117 [-1, 80, 14, 14] 38,400
BatchNorm2d-118 [-1, 80, 14, 14] 160
MBConvBlock-119 [-1, 80, 14, 14] 0
Identity-120 [-1, 80, 14, 14] 0
Conv2dStaticSamePadding-121 [-1, 480, 14, 14] 38,400
BatchNorm2d-122 [-1, 480, 14, 14] 960
MemoryEfficientSwish-123 [-1, 480, 14, 14] 0
ZeroPad2d-124 [-1, 480, 16, 16] 0
42
Conv2dStaticSamePadding-125 [-1, 480, 14, 14] 4,320
BatchNorm2d-126 [-1, 480, 14, 14] 960
MemoryEfficientSwish-127 [-1, 480, 14, 14] 0
Identity-128 [-1, 480, 1, 1] 0
Conv2dStaticSamePadding-129 [-1, 20, 1, 1] 9,620
MemoryEfficientSwish-130 [-1, 20, 1, 1] 0
Identity-131 [-1, 20, 1, 1] 0
Conv2dStaticSamePadding-132 [-1, 480, 1, 1] 10,080
Identity-133 [-1, 480, 14, 14] 0
Conv2dStaticSamePadding-134 [-1, 80, 14, 14] 38,400
BatchNorm2d-135 [-1, 80, 14, 14] 160
MBConvBlock-136 [-1, 80, 14, 14] 0
Identity-137 [-1, 80, 14, 14] 0
Conv2dStaticSamePadding-138 [-1, 480, 14, 14] 38,400
BatchNorm2d-139 [-1, 480, 14, 14] 960
MemoryEfficientSwish-140 [-1, 480, 14, 14] 0
ZeroPad2d-141 [-1, 480, 18, 18] 0
Conv2dStaticSamePadding-142 [-1, 480, 14, 14] 12,000
BatchNorm2d-143 [-1, 480, 14, 14] 960
MemoryEfficientSwish-144 [-1, 480, 14, 14] 0
Identity-145 [-1, 480, 1, 1] 0
Conv2dStaticSamePadding-146 [-1, 20, 1, 1] 9,620
MemoryEfficientSwish-147 [-1, 20, 1, 1] 0
Identity-148 [-1, 20, 1, 1] 0
Conv2dStaticSamePadding-149 [-1, 480, 1, 1] 10,080
Identity-150 [-1, 480, 14, 14] 0
Conv2dStaticSamePadding-151 [-1, 112, 14, 14] 53,760
BatchNorm2d-152 [-1, 112, 14, 14] 224
MBConvBlock-153 [-1, 112, 14, 14] 0
Identity-154 [-1, 112, 14, 14] 0
Conv2dStaticSamePadding-155 [-1, 672, 14, 14] 75,264
BatchNorm2d-156 [-1, 672, 14, 14] 1,344
MemoryEfficientSwish-157 [-1, 672, 14, 14] 0
ZeroPad2d-158 [-1, 672, 18, 18] 0
Conv2dStaticSamePadding-159 [-1, 672, 14, 14] 16,800
BatchNorm2d-160 [-1, 672, 14, 14] 1,344
MemoryEfficientSwish-161 [-1, 672, 14, 14] 0
Identity-162 [-1, 672, 1, 1] 0
Conv2dStaticSamePadding-163 [-1, 28, 1, 1] 18,844
MemoryEfficientSwish-164 [-1, 28, 1, 1] 0
Identity-165 [-1, 28, 1, 1] 0
Conv2dStaticSamePadding-166 [-1, 672, 1, 1] 19,488
Identity-167 [-1, 672, 14, 14] 0
Conv2dStaticSamePadding-168 [-1, 112, 14, 14] 75,264
BatchNorm2d-169 [-1, 112, 14, 14] 224
MBConvBlock-170 [-1, 112, 14, 14] 0
Identity-171 [-1, 112, 14, 14] 0
Conv2dStaticSamePadding-172 [-1, 672, 14, 14] 75,264
43
BatchNorm2d-173 [-1, 672, 14, 14] 1,344
MemoryEfficientSwish-174 [-1, 672, 14, 14] 0
ZeroPad2d-175 [-1, 672, 18, 18] 0
Conv2dStaticSamePadding-176 [-1, 672, 14, 14] 16,800
BatchNorm2d-177 [-1, 672, 14, 14] 1,344
MemoryEfficientSwish-178 [-1, 672, 14, 14] 0
Identity-179 [-1, 672, 1, 1] 0
Conv2dStaticSamePadding-180 [-1, 28, 1, 1] 18,844
MemoryEfficientSwish-181 [-1, 28, 1, 1] 0
Identity-182 [-1, 28, 1, 1] 0
Conv2dStaticSamePadding-183 [-1, 672, 1, 1] 19,488
Identity-184 [-1, 672, 14, 14] 0
Conv2dStaticSamePadding-185 [-1, 112, 14, 14] 75,264
BatchNorm2d-186 [-1, 112, 14, 14] 224
MBConvBlock-187 [-1, 112, 14, 14] 0
Identity-188 [-1, 112, 14, 14] 0
Conv2dStaticSamePadding-189 [-1, 672, 14, 14] 75,264
BatchNorm2d-190 [-1, 672, 14, 14] 1,344
MemoryEfficientSwish-191 [-1, 672, 14, 14] 0
ZeroPad2d-192 [-1, 672, 17, 17] 0
Conv2dStaticSamePadding-193 [-1, 672, 7, 7] 16,800
BatchNorm2d-194 [-1, 672, 7, 7] 1,344
MemoryEfficientSwish-195 [-1, 672, 7, 7] 0
Identity-196 [-1, 672, 1, 1] 0
Conv2dStaticSamePadding-197 [-1, 28, 1, 1] 18,844
MemoryEfficientSwish-198 [-1, 28, 1, 1] 0
Identity-199 [-1, 28, 1, 1] 0
Conv2dStaticSamePadding-200 [-1, 672, 1, 1] 19,488
Identity-201 [-1, 672, 7, 7] 0
Conv2dStaticSamePadding-202 [-1, 192, 7, 7] 129,024
BatchNorm2d-203 [-1, 192, 7, 7] 384
MBConvBlock-204 [-1, 192, 7, 7] 0
Identity-205 [-1, 192, 7, 7] 0
Conv2dStaticSamePadding-206 [-1, 1152, 7, 7] 221,184
BatchNorm2d-207 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-208 [-1, 1152, 7, 7] 0
ZeroPad2d-209 [-1, 1152, 11, 11] 0
Conv2dStaticSamePadding-210 [-1, 1152, 7, 7] 28,800
BatchNorm2d-211 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-212 [-1, 1152, 7, 7] 0
Identity-213 [-1, 1152, 1, 1] 0
Conv2dStaticSamePadding-214 [-1, 48, 1, 1] 55,344
MemoryEfficientSwish-215 [-1, 48, 1, 1] 0
Identity-216 [-1, 48, 1, 1] 0
Conv2dStaticSamePadding-217 [-1, 1152, 1, 1] 56,448
Identity-218 [-1, 1152, 7, 7] 0
Conv2dStaticSamePadding-219 [-1, 192, 7, 7] 221,184
BatchNorm2d-220 [-1, 192, 7, 7] 384
44
MBConvBlock-221 [-1, 192, 7, 7] 0
Identity-222 [-1, 192, 7, 7] 0
Conv2dStaticSamePadding-223 [-1, 1152, 7, 7] 221,184
BatchNorm2d-224 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-225 [-1, 1152, 7, 7] 0
ZeroPad2d-226 [-1, 1152, 11, 11] 0
Conv2dStaticSamePadding-227 [-1, 1152, 7, 7] 28,800
BatchNorm2d-228 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-229 [-1, 1152, 7, 7] 0
Identity-230 [-1, 1152, 1, 1] 0
Conv2dStaticSamePadding-231 [-1, 48, 1, 1] 55,344
MemoryEfficientSwish-232 [-1, 48, 1, 1] 0
Identity-233 [-1, 48, 1, 1] 0
Conv2dStaticSamePadding-234 [-1, 1152, 1, 1] 56,448
Identity-235 [-1, 1152, 7, 7] 0
Conv2dStaticSamePadding-236 [-1, 192, 7, 7] 221,184
BatchNorm2d-237 [-1, 192, 7, 7] 384
MBConvBlock-238 [-1, 192, 7, 7] 0
Identity-239 [-1, 192, 7, 7] 0
Conv2dStaticSamePadding-240 [-1, 1152, 7, 7] 221,184
BatchNorm2d-241 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-242 [-1, 1152, 7, 7] 0
ZeroPad2d-243 [-1, 1152, 11, 11] 0
Conv2dStaticSamePadding-244 [-1, 1152, 7, 7] 28,800
BatchNorm2d-245 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-246 [-1, 1152, 7, 7] 0
Identity-247 [-1, 1152, 1, 1] 0
Conv2dStaticSamePadding-248 [-1, 48, 1, 1] 55,344
MemoryEfficientSwish-249 [-1, 48, 1, 1] 0
Identity-250 [-1, 48, 1, 1] 0
Conv2dStaticSamePadding-251 [-1, 1152, 1, 1] 56,448
Identity-252 [-1, 1152, 7, 7] 0
Conv2dStaticSamePadding-253 [-1, 192, 7, 7] 221,184
BatchNorm2d-254 [-1, 192, 7, 7] 384
MBConvBlock-255 [-1, 192, 7, 7] 0
Identity-256 [-1, 192, 7, 7] 0
Conv2dStaticSamePadding-257 [-1, 1152, 7, 7] 221,184
BatchNorm2d-258 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-259 [-1, 1152, 7, 7] 0
ZeroPad2d-260 [-1, 1152, 9, 9] 0
Conv2dStaticSamePadding-261 [-1, 1152, 7, 7] 10,368
BatchNorm2d-262 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-263 [-1, 1152, 7, 7] 0
Identity-264 [-1, 1152, 1, 1] 0
Conv2dStaticSamePadding-265 [-1, 48, 1, 1] 55,344
MemoryEfficientSwish-266 [-1, 48, 1, 1] 0
Identity-267 [-1, 48, 1, 1] 0
Conv2dStaticSamePadding-268 [-1, 1152, 1, 1] 56,448
45
Identity-269 [-1, 1152, 7, 7] 0
Conv2dStaticSamePadding-270 [-1, 320, 7, 7] 368,640
BatchNorm2d-271 [-1, 320, 7, 7] 640
MBConvBlock-272 [-1, 320, 7, 7] 0
Identity-273 [-1, 320, 7, 7] 0
Conv2dStaticSamePadding-274 [-1, 1280, 7, 7] 409,600
BatchNorm2d-275 [-1, 1280, 7, 7] 2,560
MemoryEfficientSwish-276 [-1, 1280, 7, 7] 0
AdaptiveAvgPool2d-277 [-1, 1280, 1, 1] 0
Dropout-278 [-1, 1280] 0
Linear-279 [-1, 200] 256,200
================================================================
Total params: 4,263,748
Trainable params: 4,263,748
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 0.57
Forward/backward pass size (MB): 212.79
Params size (MB): 16.26
Estimated Total Size (MB): 229.63
----------------------------------------------------------------
----------------------------------------------------------------
Layer (type) Output Shape Param #
================================================================
ZeroPad2d-1 [-1, 3, 225, 225] 0
Conv2dStaticSamePadding-2 [-1, 32, 112, 112] 864
BatchNorm2d-3 [-1, 32, 112, 112] 64
MemoryEfficientSwish-4 [-1, 32, 112, 112] 0
ZeroPad2d-5 [-1, 32, 114, 114] 0
Conv2dStaticSamePadding-6 [-1, 32, 112, 112] 288
BatchNorm2d-7 [-1, 32, 112, 112] 64
MemoryEfficientSwish-8 [-1, 32, 112, 112] 0
Identity-9 [-1, 32, 1, 1] 0
Conv2dStaticSamePadding-10 [-1, 8, 1, 1] 264
MemoryEfficientSwish-11 [-1, 8, 1, 1] 0
Identity-12 [-1, 8, 1, 1] 0
Conv2dStaticSamePadding-13 [-1, 32, 1, 1] 288
Identity-14 [-1, 32, 112, 112] 0
Conv2dStaticSamePadding-15 [-1, 16, 112, 112] 512
BatchNorm2d-16 [-1, 16, 112, 112] 32
MBConvBlock-17 [-1, 16, 112, 112] 0
Identity-18 [-1, 16, 112, 112] 0
Conv2dStaticSamePadding-19 [-1, 96, 112, 112] 1,536
BatchNorm2d-20 [-1, 96, 112, 112] 192
MemoryEfficientSwish-21 [-1, 96, 112, 112] 0
ZeroPad2d-22 [-1, 96, 113, 113] 0
Conv2dStaticSamePadding-23 [-1, 96, 56, 56] 864
BatchNorm2d-24 [-1, 96, 56, 56] 192
46
MemoryEfficientSwish-25 [-1, 96, 56, 56] 0
Identity-26 [-1, 96, 1, 1] 0
Conv2dStaticSamePadding-27 [-1, 4, 1, 1] 388
MemoryEfficientSwish-28 [-1, 4, 1, 1] 0
Identity-29 [-1, 4, 1, 1] 0
Conv2dStaticSamePadding-30 [-1, 96, 1, 1] 480
Identity-31 [-1, 96, 56, 56] 0
Conv2dStaticSamePadding-32 [-1, 24, 56, 56] 2,304
BatchNorm2d-33 [-1, 24, 56, 56] 48
MBConvBlock-34 [-1, 24, 56, 56] 0
Identity-35 [-1, 24, 56, 56] 0
Conv2dStaticSamePadding-36 [-1, 144, 56, 56] 3,456
BatchNorm2d-37 [-1, 144, 56, 56] 288
MemoryEfficientSwish-38 [-1, 144, 56, 56] 0
ZeroPad2d-39 [-1, 144, 58, 58] 0
Conv2dStaticSamePadding-40 [-1, 144, 56, 56] 1,296
BatchNorm2d-41 [-1, 144, 56, 56] 288
MemoryEfficientSwish-42 [-1, 144, 56, 56] 0
Identity-43 [-1, 144, 1, 1] 0
Conv2dStaticSamePadding-44 [-1, 6, 1, 1] 870
MemoryEfficientSwish-45 [-1, 6, 1, 1] 0
Identity-46 [-1, 6, 1, 1] 0
Conv2dStaticSamePadding-47 [-1, 144, 1, 1] 1,008
Identity-48 [-1, 144, 56, 56] 0
Conv2dStaticSamePadding-49 [-1, 24, 56, 56] 3,456
BatchNorm2d-50 [-1, 24, 56, 56] 48
MBConvBlock-51 [-1, 24, 56, 56] 0
Identity-52 [-1, 24, 56, 56] 0
Conv2dStaticSamePadding-53 [-1, 144, 56, 56] 3,456
BatchNorm2d-54 [-1, 144, 56, 56] 288
MemoryEfficientSwish-55 [-1, 144, 56, 56] 0
ZeroPad2d-56 [-1, 144, 59, 59] 0
Conv2dStaticSamePadding-57 [-1, 144, 28, 28] 3,600
BatchNorm2d-58 [-1, 144, 28, 28] 288
MemoryEfficientSwish-59 [-1, 144, 28, 28] 0
Identity-60 [-1, 144, 1, 1] 0
Conv2dStaticSamePadding-61 [-1, 6, 1, 1] 870
MemoryEfficientSwish-62 [-1, 6, 1, 1] 0
Identity-63 [-1, 6, 1, 1] 0
Conv2dStaticSamePadding-64 [-1, 144, 1, 1] 1,008
Identity-65 [-1, 144, 28, 28] 0
Conv2dStaticSamePadding-66 [-1, 40, 28, 28] 5,760
BatchNorm2d-67 [-1, 40, 28, 28] 80
MBConvBlock-68 [-1, 40, 28, 28] 0
Identity-69 [-1, 40, 28, 28] 0
Conv2dStaticSamePadding-70 [-1, 240, 28, 28] 9,600
BatchNorm2d-71 [-1, 240, 28, 28] 480
MemoryEfficientSwish-72 [-1, 240, 28, 28] 0
47
ZeroPad2d-73 [-1, 240, 32, 32] 0
Conv2dStaticSamePadding-74 [-1, 240, 28, 28] 6,000
BatchNorm2d-75 [-1, 240, 28, 28] 480
MemoryEfficientSwish-76 [-1, 240, 28, 28] 0
Identity-77 [-1, 240, 1, 1] 0
Conv2dStaticSamePadding-78 [-1, 10, 1, 1] 2,410
MemoryEfficientSwish-79 [-1, 10, 1, 1] 0
Identity-80 [-1, 10, 1, 1] 0
Conv2dStaticSamePadding-81 [-1, 240, 1, 1] 2,640
Identity-82 [-1, 240, 28, 28] 0
Conv2dStaticSamePadding-83 [-1, 40, 28, 28] 9,600
BatchNorm2d-84 [-1, 40, 28, 28] 80
MBConvBlock-85 [-1, 40, 28, 28] 0
Identity-86 [-1, 40, 28, 28] 0
Conv2dStaticSamePadding-87 [-1, 240, 28, 28] 9,600
BatchNorm2d-88 [-1, 240, 28, 28] 480
MemoryEfficientSwish-89 [-1, 240, 28, 28] 0
ZeroPad2d-90 [-1, 240, 29, 29] 0
Conv2dStaticSamePadding-91 [-1, 240, 14, 14] 2,160
BatchNorm2d-92 [-1, 240, 14, 14] 480
MemoryEfficientSwish-93 [-1, 240, 14, 14] 0
Identity-94 [-1, 240, 1, 1] 0
Conv2dStaticSamePadding-95 [-1, 10, 1, 1] 2,410
MemoryEfficientSwish-96 [-1, 10, 1, 1] 0
Identity-97 [-1, 10, 1, 1] 0
Conv2dStaticSamePadding-98 [-1, 240, 1, 1] 2,640
Identity-99 [-1, 240, 14, 14] 0
Conv2dStaticSamePadding-100 [-1, 80, 14, 14] 19,200
BatchNorm2d-101 [-1, 80, 14, 14] 160
MBConvBlock-102 [-1, 80, 14, 14] 0
Identity-103 [-1, 80, 14, 14] 0
Conv2dStaticSamePadding-104 [-1, 480, 14, 14] 38,400
BatchNorm2d-105 [-1, 480, 14, 14] 960
MemoryEfficientSwish-106 [-1, 480, 14, 14] 0
ZeroPad2d-107 [-1, 480, 16, 16] 0
Conv2dStaticSamePadding-108 [-1, 480, 14, 14] 4,320
BatchNorm2d-109 [-1, 480, 14, 14] 960
MemoryEfficientSwish-110 [-1, 480, 14, 14] 0
Identity-111 [-1, 480, 1, 1] 0
Conv2dStaticSamePadding-112 [-1, 20, 1, 1] 9,620
MemoryEfficientSwish-113 [-1, 20, 1, 1] 0
Identity-114 [-1, 20, 1, 1] 0
Conv2dStaticSamePadding-115 [-1, 480, 1, 1] 10,080
Identity-116 [-1, 480, 14, 14] 0
Conv2dStaticSamePadding-117 [-1, 80, 14, 14] 38,400
BatchNorm2d-118 [-1, 80, 14, 14] 160
MBConvBlock-119 [-1, 80, 14, 14] 0
Identity-120 [-1, 80, 14, 14] 0
48
Conv2dStaticSamePadding-121 [-1, 480, 14, 14] 38,400
BatchNorm2d-122 [-1, 480, 14, 14] 960
MemoryEfficientSwish-123 [-1, 480, 14, 14] 0
ZeroPad2d-124 [-1, 480, 16, 16] 0
Conv2dStaticSamePadding-125 [-1, 480, 14, 14] 4,320
BatchNorm2d-126 [-1, 480, 14, 14] 960
MemoryEfficientSwish-127 [-1, 480, 14, 14] 0
Identity-128 [-1, 480, 1, 1] 0
Conv2dStaticSamePadding-129 [-1, 20, 1, 1] 9,620
MemoryEfficientSwish-130 [-1, 20, 1, 1] 0
Identity-131 [-1, 20, 1, 1] 0
Conv2dStaticSamePadding-132 [-1, 480, 1, 1] 10,080
Identity-133 [-1, 480, 14, 14] 0
Conv2dStaticSamePadding-134 [-1, 80, 14, 14] 38,400
BatchNorm2d-135 [-1, 80, 14, 14] 160
MBConvBlock-136 [-1, 80, 14, 14] 0
Identity-137 [-1, 80, 14, 14] 0
Conv2dStaticSamePadding-138 [-1, 480, 14, 14] 38,400
BatchNorm2d-139 [-1, 480, 14, 14] 960
MemoryEfficientSwish-140 [-1, 480, 14, 14] 0
ZeroPad2d-141 [-1, 480, 18, 18] 0
Conv2dStaticSamePadding-142 [-1, 480, 14, 14] 12,000
BatchNorm2d-143 [-1, 480, 14, 14] 960
MemoryEfficientSwish-144 [-1, 480, 14, 14] 0
Identity-145 [-1, 480, 1, 1] 0
Conv2dStaticSamePadding-146 [-1, 20, 1, 1] 9,620
MemoryEfficientSwish-147 [-1, 20, 1, 1] 0
Identity-148 [-1, 20, 1, 1] 0
Conv2dStaticSamePadding-149 [-1, 480, 1, 1] 10,080
Identity-150 [-1, 480, 14, 14] 0
Conv2dStaticSamePadding-151 [-1, 112, 14, 14] 53,760
BatchNorm2d-152 [-1, 112, 14, 14] 224
MBConvBlock-153 [-1, 112, 14, 14] 0
Identity-154 [-1, 112, 14, 14] 0
Conv2dStaticSamePadding-155 [-1, 672, 14, 14] 75,264
BatchNorm2d-156 [-1, 672, 14, 14] 1,344
MemoryEfficientSwish-157 [-1, 672, 14, 14] 0
ZeroPad2d-158 [-1, 672, 18, 18] 0
Conv2dStaticSamePadding-159 [-1, 672, 14, 14] 16,800
BatchNorm2d-160 [-1, 672, 14, 14] 1,344
MemoryEfficientSwish-161 [-1, 672, 14, 14] 0
Identity-162 [-1, 672, 1, 1] 0
Conv2dStaticSamePadding-163 [-1, 28, 1, 1] 18,844
MemoryEfficientSwish-164 [-1, 28, 1, 1] 0
Identity-165 [-1, 28, 1, 1] 0
Conv2dStaticSamePadding-166 [-1, 672, 1, 1] 19,488
Identity-167 [-1, 672, 14, 14] 0
Conv2dStaticSamePadding-168 [-1, 112, 14, 14] 75,264
49
BatchNorm2d-169 [-1, 112, 14, 14] 224
MBConvBlock-170 [-1, 112, 14, 14] 0
Identity-171 [-1, 112, 14, 14] 0
Conv2dStaticSamePadding-172 [-1, 672, 14, 14] 75,264
BatchNorm2d-173 [-1, 672, 14, 14] 1,344
MemoryEfficientSwish-174 [-1, 672, 14, 14] 0
ZeroPad2d-175 [-1, 672, 18, 18] 0
Conv2dStaticSamePadding-176 [-1, 672, 14, 14] 16,800
BatchNorm2d-177 [-1, 672, 14, 14] 1,344
MemoryEfficientSwish-178 [-1, 672, 14, 14] 0
Identity-179 [-1, 672, 1, 1] 0
Conv2dStaticSamePadding-180 [-1, 28, 1, 1] 18,844
MemoryEfficientSwish-181 [-1, 28, 1, 1] 0
Identity-182 [-1, 28, 1, 1] 0
Conv2dStaticSamePadding-183 [-1, 672, 1, 1] 19,488
Identity-184 [-1, 672, 14, 14] 0
Conv2dStaticSamePadding-185 [-1, 112, 14, 14] 75,264
BatchNorm2d-186 [-1, 112, 14, 14] 224
MBConvBlock-187 [-1, 112, 14, 14] 0
Identity-188 [-1, 112, 14, 14] 0
Conv2dStaticSamePadding-189 [-1, 672, 14, 14] 75,264
BatchNorm2d-190 [-1, 672, 14, 14] 1,344
MemoryEfficientSwish-191 [-1, 672, 14, 14] 0
ZeroPad2d-192 [-1, 672, 17, 17] 0
Conv2dStaticSamePadding-193 [-1, 672, 7, 7] 16,800
BatchNorm2d-194 [-1, 672, 7, 7] 1,344
MemoryEfficientSwish-195 [-1, 672, 7, 7] 0
Identity-196 [-1, 672, 1, 1] 0
Conv2dStaticSamePadding-197 [-1, 28, 1, 1] 18,844
MemoryEfficientSwish-198 [-1, 28, 1, 1] 0
Identity-199 [-1, 28, 1, 1] 0
Conv2dStaticSamePadding-200 [-1, 672, 1, 1] 19,488
Identity-201 [-1, 672, 7, 7] 0
Conv2dStaticSamePadding-202 [-1, 192, 7, 7] 129,024
BatchNorm2d-203 [-1, 192, 7, 7] 384
MBConvBlock-204 [-1, 192, 7, 7] 0
Identity-205 [-1, 192, 7, 7] 0
Conv2dStaticSamePadding-206 [-1, 1152, 7, 7] 221,184
BatchNorm2d-207 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-208 [-1, 1152, 7, 7] 0
ZeroPad2d-209 [-1, 1152, 11, 11] 0
Conv2dStaticSamePadding-210 [-1, 1152, 7, 7] 28,800
BatchNorm2d-211 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-212 [-1, 1152, 7, 7] 0
Identity-213 [-1, 1152, 1, 1] 0
Conv2dStaticSamePadding-214 [-1, 48, 1, 1] 55,344
MemoryEfficientSwish-215 [-1, 48, 1, 1] 0
Identity-216 [-1, 48, 1, 1] 0
50
Conv2dStaticSamePadding-217 [-1, 1152, 1, 1] 56,448
Identity-218 [-1, 1152, 7, 7] 0
Conv2dStaticSamePadding-219 [-1, 192, 7, 7] 221,184
BatchNorm2d-220 [-1, 192, 7, 7] 384
MBConvBlock-221 [-1, 192, 7, 7] 0
Identity-222 [-1, 192, 7, 7] 0
Conv2dStaticSamePadding-223 [-1, 1152, 7, 7] 221,184
BatchNorm2d-224 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-225 [-1, 1152, 7, 7] 0
ZeroPad2d-226 [-1, 1152, 11, 11] 0
Conv2dStaticSamePadding-227 [-1, 1152, 7, 7] 28,800
BatchNorm2d-228 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-229 [-1, 1152, 7, 7] 0
Identity-230 [-1, 1152, 1, 1] 0
Conv2dStaticSamePadding-231 [-1, 48, 1, 1] 55,344
MemoryEfficientSwish-232 [-1, 48, 1, 1] 0
Identity-233 [-1, 48, 1, 1] 0
Conv2dStaticSamePadding-234 [-1, 1152, 1, 1] 56,448
Identity-235 [-1, 1152, 7, 7] 0
Conv2dStaticSamePadding-236 [-1, 192, 7, 7] 221,184
BatchNorm2d-237 [-1, 192, 7, 7] 384
MBConvBlock-238 [-1, 192, 7, 7] 0
Identity-239 [-1, 192, 7, 7] 0
Conv2dStaticSamePadding-240 [-1, 1152, 7, 7] 221,184
BatchNorm2d-241 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-242 [-1, 1152, 7, 7] 0
ZeroPad2d-243 [-1, 1152, 11, 11] 0
Conv2dStaticSamePadding-244 [-1, 1152, 7, 7] 28,800
BatchNorm2d-245 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-246 [-1, 1152, 7, 7] 0
Identity-247 [-1, 1152, 1, 1] 0
Conv2dStaticSamePadding-248 [-1, 48, 1, 1] 55,344
MemoryEfficientSwish-249 [-1, 48, 1, 1] 0
Identity-250 [-1, 48, 1, 1] 0
Conv2dStaticSamePadding-251 [-1, 1152, 1, 1] 56,448
Identity-252 [-1, 1152, 7, 7] 0
Conv2dStaticSamePadding-253 [-1, 192, 7, 7] 221,184
BatchNorm2d-254 [-1, 192, 7, 7] 384
MBConvBlock-255 [-1, 192, 7, 7] 0
Identity-256 [-1, 192, 7, 7] 0
Conv2dStaticSamePadding-257 [-1, 1152, 7, 7] 221,184
BatchNorm2d-258 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-259 [-1, 1152, 7, 7] 0
ZeroPad2d-260 [-1, 1152, 9, 9] 0
Conv2dStaticSamePadding-261 [-1, 1152, 7, 7] 10,368
BatchNorm2d-262 [-1, 1152, 7, 7] 2,304
MemoryEfficientSwish-263 [-1, 1152, 7, 7] 0
Identity-264 [-1, 1152, 1, 1] 0
51
Conv2dStaticSamePadding-265 [-1, 48, 1, 1] 55,344
MemoryEfficientSwish-266 [-1, 48, 1, 1] 0
Identity-267 [-1, 48, 1, 1] 0
Conv2dStaticSamePadding-268 [-1, 1152, 1, 1] 56,448
Identity-269 [-1, 1152, 7, 7] 0
Conv2dStaticSamePadding-270 [-1, 320, 7, 7] 368,640
BatchNorm2d-271 [-1, 320, 7, 7] 640
MBConvBlock-272 [-1, 320, 7, 7] 0
Identity-273 [-1, 320, 7, 7] 0
Conv2dStaticSamePadding-274 [-1, 1280, 7, 7] 409,600
BatchNorm2d-275 [-1, 1280, 7, 7] 2,560
MemoryEfficientSwish-276 [-1, 1280, 7, 7] 0
AdaptiveAvgPool2d-277 [-1, 1280, 1, 1] 0
Dropout-278 [-1, 1280] 0
Linear-279 [-1, 200] 256,200
================================================================
Total params: 4,263,748
Trainable params: 4,263,748
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 0.57
Forward/backward pass size (MB): 212.79
Params size (MB): 16.26
Estimated Total Size (MB): 229.63
----------------------------------------------------------------
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
File ~\anaconda3\lib\site-packages\graphviz\backend\execute.py:81, in␣
↪run_check(cmd, input_lines, encoding, quiet, **kwargs)
80 else:
---> 81 proc = subprocess.run(cmd, **kwargs)
82 except OSError as e:
52
952 pass_fds, cwd, env,
953 startupinfo, creationflags, shell,
954 p2cread, p2cwrite,
955 c2pread, c2pwrite,
956 errread, errwrite,
957 restore_signals,
958 gid, gids, uid, umask,
959 start_new_session)
960 except:
961 # Cleanup if the child failed starting.
1419 try:
-> 1420 hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
1421 # no special security
1422 None, None,
1423 int(not close_fds),
1424 creationflags,
1425 env,
1426 cwd,
1427 startupinfo)
1428 finally:
1429 # Child is launched. Close the parent's copy of those pipe
1430 # handles that only the child should have open. You need
(…)
1433 # pipe will not close when the child process exits and the
1434 # ReadFile will hang.
The above exception was the direct cause of the following exception:
53
166 f' {list(supported)}: pass {wanted}'
167 ' as keyword arg(s)',
168 stacklevel=stacklevel,
169 category=category)
--> 171 return func(*args, **kwargs)
82 except OSError as e:
83 if e.errno == errno.ENOENT:
---> 84 raise ExecutableNotFound(cmd) from e
85 raise
87 if not quiet and proc.stderr:
54
ExecutableNotFound: failed to execute WindowsPath('dot'), make sure the Graphviz␣
↪executables are on your systems' PATH
[118]: ResNet(
(conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3),
bias=False)
(bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(relu): ReLU(inplace=True)
(maxpool): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1,
ceil_mode=False)
(layer1): Sequential(
(0): BasicBlock(
(conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1),
bias=False)
(bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(relu): ReLU(inplace=True)
(conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1),
bias=False)
(bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
(1): BasicBlock(
(conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1),
bias=False)
(bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(relu): ReLU(inplace=True)
(conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1),
bias=False)
(bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(layer2): Sequential(
(0): BasicBlock(
(conv1): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1,
1), bias=False)
(bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(relu): ReLU(inplace=True)
(conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1,
55
1), bias=False)
(bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(downsample): Sequential(
(0): Conv2d(64, 128, kernel_size=(1, 1), stride=(2, 2), bias=False)
(1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(1): BasicBlock(
(conv1): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), bias=False)
(bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(relu): ReLU(inplace=True)
(conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), bias=False)
(bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(layer3): Sequential(
(0): BasicBlock(
(conv1): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1,
1), bias=False)
(bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(relu): ReLU(inplace=True)
(conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), bias=False)
(bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(downsample): Sequential(
(0): Conv2d(128, 256, kernel_size=(1, 1), stride=(2, 2), bias=False)
(1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(1): BasicBlock(
(conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), bias=False)
(bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(relu): ReLU(inplace=True)
(conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), bias=False)
(bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True,
56
track_running_stats=True)
)
)
(layer4): Sequential(
(0): BasicBlock(
(conv1): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1,
1), bias=False)
(bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(relu): ReLU(inplace=True)
(conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), bias=False)
(bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(downsample): Sequential(
(0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False)
(1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(1): BasicBlock(
(conv1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), bias=False)
(bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
(relu): ReLU(inplace=True)
(conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1,
1), bias=False)
(bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True)
)
)
(avgpool): AdaptiveAvgPool2d(output_size=(1, 1))
(fc): Linear(in_features=512, out_features=200, bias=True)
)
[ ]:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Input In [109], in <cell line: 2>()
1 # Print the summary of the model
----> 2 summary(model_resnet, (3, 224, 224))
57
File ~\anaconda3\lib\site-packages\torchsummary\torchsummary.py:72, in␣
↪summary(model, input_size, batch_size, device)
68 model.apply(register_hook)
70 # make a forward pass
71 # print(x.shape)
---> 72 model(*x)
74 # remove these hooks
75 for h in hooks:
1517 else:
-> 1518 return self._call_impl(*args, **kwargs)
1522 # If we don't have any hooks, we want to skip the rest of the logic in
1523 # this function, and just call forward.
1524 if not (self._backward_hooks or self._backward_pre_hooks or self.
↪_forward_hooks or self._forward_pre_hooks
1517 else:
-> 1518 return self._call_impl(*args, **kwargs)
58
File ~\anaconda3\lib\site-packages\torch\nn\modules\module.py:1568, in Module.
↪_call_impl(self, *args, **kwargs)
59
total_params = sum(p.numel() for p in efficientnet.parameters())
print("Total number of parameters:", total_params)
Collecting graphviz
Downloading graphviz-0.20.1-py3-none-any.whl.metadata (12 kB)
Downloading graphviz-0.20.1-py3-none-any.whl (47 kB)
---------------------------------------- 47.0/47.0 kB 2.3 MB/s eta 0:00:00
Installing collected packages: graphviz
Successfully installed graphviz-0.20.1
[ ]:
60