Lesson6 Pets More
colabdev_nbsmachine-learninggpudeep-learningnotebooksPythonfastaipytorchcourse
Export
[ ]
Lesson 6: pets revisited
[ ]
[ ]
[ ]
Data augmentation
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
batch=True means we pick the same random augmentation for all the images in the batch.
[ ]
[ ]
Train a model
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
Convolution kernel
[ ]
[ ]
[ ]
[ ]
[ ]
tensor([[[[ 0.0000, -0.2778, 0.1667], , [-0.2778, -0.2778, 0.1667], , [ 0.1667, 0.1667, 0.1667]], , , [[ 0.0000, -0.2778, 0.1667], , [-0.2778, -0.2778, 0.1667], , [ 0.1667, 0.1667, 0.1667]], , , [[ 0.0000, -0.2778, 0.1667], , [-0.2778, -0.2778, 0.1667], , [ 0.1667, 0.1667, 0.1667]]]])
[ ]
torch.Size([1, 3, 3, 3])
[ ]
torch.Size([3, 233, 300])
[ ]
torch.Size([1, 3, 233, 300])
[ ]
[ ]
[ ]
37
[ ]
Sequential( , (0): Sequential( , (0): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False) , (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) , (2): ReLU(inplace=True) , (3): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False) , (4): 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) , ) , (2): 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) , ) , ) , (5): 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, 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) , ) , (2): 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) , ) , (3): 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) , ) , ) , (6): 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, track_running_stats=True) , ) , (2): 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, track_running_stats=True) , ) , (3): 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, track_running_stats=True) , ) , (4): 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, track_running_stats=True) , ) , (5): 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, track_running_stats=True) , ) , ) , (7): 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) , ) , (2): 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) , ) , ) , ) , (1): Sequential( , (0): AdaptiveConcatPool2d( , (ap): AdaptiveAvgPool2d(output_size=1) , (mp): AdaptiveMaxPool2d(output_size=1) , ) , (1): Flatten() , (2): BatchNorm1d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) , (3): Dropout(p=0.25, inplace=False) , (4): Linear(in_features=1024, out_features=512, bias=False) , (5): ReLU(inplace=True) , (6): BatchNorm1d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) , (7): Dropout(p=0.5, inplace=False) , (8): Linear(in_features=512, out_features=37, bias=False) , (9): BatchNorm1d(37, eps=1e-05, momentum=0.01, affine=True, track_running_stats=True) , ) ,)
[ ]
Sequential (Input shape: 16 x 3 x 352 x 352) ================================================================ Layer (type) Output Shape Param # Trainable ================================================================ Conv2d 16 x 64 x 176 x 176 9,408 False ________________________________________________________________ BatchNorm2d 16 x 64 x 176 x 176 128 True ________________________________________________________________ ReLU 16 x 64 x 176 x 176 0 False ________________________________________________________________ MaxPool2d 16 x 64 x 88 x 88 0 False ________________________________________________________________ Conv2d 16 x 64 x 88 x 88 36,864 False ________________________________________________________________ BatchNorm2d 16 x 64 x 88 x 88 128 True ________________________________________________________________ ReLU 16 x 64 x 88 x 88 0 False ________________________________________________________________ Conv2d 16 x 64 x 88 x 88 36,864 False ________________________________________________________________ BatchNorm2d 16 x 64 x 88 x 88 128 True ________________________________________________________________ Conv2d 16 x 64 x 88 x 88 36,864 False ________________________________________________________________ BatchNorm2d 16 x 64 x 88 x 88 128 True ________________________________________________________________ ReLU 16 x 64 x 88 x 88 0 False ________________________________________________________________ Conv2d 16 x 64 x 88 x 88 36,864 False ________________________________________________________________ BatchNorm2d 16 x 64 x 88 x 88 128 True ________________________________________________________________ Conv2d 16 x 64 x 88 x 88 36,864 False ________________________________________________________________ BatchNorm2d 16 x 64 x 88 x 88 128 True ________________________________________________________________ ReLU 16 x 64 x 88 x 88 0 False ________________________________________________________________ Conv2d 16 x 64 x 88 x 88 36,864 False ________________________________________________________________ BatchNorm2d 16 x 64 x 88 x 88 128 True ________________________________________________________________ Conv2d 16 x 128 x 44 x 44 73,728 False ________________________________________________________________ BatchNorm2d 16 x 128 x 44 x 44 256 True ________________________________________________________________ ReLU 16 x 128 x 44 x 44 0 False ________________________________________________________________ Conv2d 16 x 128 x 44 x 44 147,456 False ________________________________________________________________ BatchNorm2d 16 x 128 x 44 x 44 256 True ________________________________________________________________ Conv2d 16 x 128 x 44 x 44 8,192 False ________________________________________________________________ BatchNorm2d 16 x 128 x 44 x 44 256 True ________________________________________________________________ Conv2d 16 x 128 x 44 x 44 147,456 False ________________________________________________________________ BatchNorm2d 16 x 128 x 44 x 44 256 True ________________________________________________________________ ReLU 16 x 128 x 44 x 44 0 False ________________________________________________________________ Conv2d 16 x 128 x 44 x 44 147,456 False ________________________________________________________________ BatchNorm2d 16 x 128 x 44 x 44 256 True ________________________________________________________________ Conv2d 16 x 128 x 44 x 44 147,456 False ________________________________________________________________ BatchNorm2d 16 x 128 x 44 x 44 256 True ________________________________________________________________ ReLU 16 x 128 x 44 x 44 0 False ________________________________________________________________ Conv2d 16 x 128 x 44 x 44 147,456 False ________________________________________________________________ BatchNorm2d 16 x 128 x 44 x 44 256 True ________________________________________________________________ Conv2d 16 x 128 x 44 x 44 147,456 False ________________________________________________________________ BatchNorm2d 16 x 128 x 44 x 44 256 True ________________________________________________________________ ReLU 16 x 128 x 44 x 44 0 False ________________________________________________________________ Conv2d 16 x 128 x 44 x 44 147,456 False ________________________________________________________________ BatchNorm2d 16 x 128 x 44 x 44 256 True ________________________________________________________________ Conv2d 16 x 256 x 22 x 22 294,912 False ________________________________________________________________ BatchNorm2d 16 x 256 x 22 x 22 512 True ________________________________________________________________ ReLU 16 x 256 x 22 x 22 0 False ________________________________________________________________ Conv2d 16 x 256 x 22 x 22 589,824 False ________________________________________________________________ BatchNorm2d 16 x 256 x 22 x 22 512 True ________________________________________________________________ Conv2d 16 x 256 x 22 x 22 32,768 False ________________________________________________________________ BatchNorm2d 16 x 256 x 22 x 22 512 True ________________________________________________________________ Conv2d 16 x 256 x 22 x 22 589,824 False ________________________________________________________________ BatchNorm2d 16 x 256 x 22 x 22 512 True ________________________________________________________________ ReLU 16 x 256 x 22 x 22 0 False ________________________________________________________________ Conv2d 16 x 256 x 22 x 22 589,824 False ________________________________________________________________ BatchNorm2d 16 x 256 x 22 x 22 512 True ________________________________________________________________ Conv2d 16 x 256 x 22 x 22 589,824 False ________________________________________________________________ BatchNorm2d 16 x 256 x 22 x 22 512 True ________________________________________________________________ ReLU 16 x 256 x 22 x 22 0 False ________________________________________________________________ Conv2d 16 x 256 x 22 x 22 589,824 False ________________________________________________________________ BatchNorm2d 16 x 256 x 22 x 22 512 True ________________________________________________________________ Conv2d 16 x 256 x 22 x 22 589,824 False ________________________________________________________________ BatchNorm2d 16 x 256 x 22 x 22 512 True ________________________________________________________________ ReLU 16 x 256 x 22 x 22 0 False ________________________________________________________________ Conv2d 16 x 256 x 22 x 22 589,824 False ________________________________________________________________ BatchNorm2d 16 x 256 x 22 x 22 512 True ________________________________________________________________ Conv2d 16 x 256 x 22 x 22 589,824 False ________________________________________________________________ BatchNorm2d 16 x 256 x 22 x 22 512 True ________________________________________________________________ ReLU 16 x 256 x 22 x 22 0 False ________________________________________________________________ Conv2d 16 x 256 x 22 x 22 589,824 False ________________________________________________________________ BatchNorm2d 16 x 256 x 22 x 22 512 True ________________________________________________________________ Conv2d 16 x 256 x 22 x 22 589,824 False ________________________________________________________________ BatchNorm2d 16 x 256 x 22 x 22 512 True ________________________________________________________________ ReLU 16 x 256 x 22 x 22 0 False ________________________________________________________________ Conv2d 16 x 256 x 22 x 22 589,824 False ________________________________________________________________ BatchNorm2d 16 x 256 x 22 x 22 512 True ________________________________________________________________ Conv2d 16 x 512 x 11 x 11 1,179,648 False ________________________________________________________________ BatchNorm2d 16 x 512 x 11 x 11 1,024 True ________________________________________________________________ ReLU 16 x 512 x 11 x 11 0 False ________________________________________________________________ Conv2d 16 x 512 x 11 x 11 2,359,296 False ________________________________________________________________ BatchNorm2d 16 x 512 x 11 x 11 1,024 True ________________________________________________________________ Conv2d 16 x 512 x 11 x 11 131,072 False ________________________________________________________________ BatchNorm2d 16 x 512 x 11 x 11 1,024 True ________________________________________________________________ Conv2d 16 x 512 x 11 x 11 2,359,296 False ________________________________________________________________ BatchNorm2d 16 x 512 x 11 x 11 1,024 True ________________________________________________________________ ReLU 16 x 512 x 11 x 11 0 False ________________________________________________________________ Conv2d 16 x 512 x 11 x 11 2,359,296 False ________________________________________________________________ BatchNorm2d 16 x 512 x 11 x 11 1,024 True ________________________________________________________________ Conv2d 16 x 512 x 11 x 11 2,359,296 False ________________________________________________________________ BatchNorm2d 16 x 512 x 11 x 11 1,024 True ________________________________________________________________ ReLU 16 x 512 x 11 x 11 0 False ________________________________________________________________ Conv2d 16 x 512 x 11 x 11 2,359,296 False ________________________________________________________________ BatchNorm2d 16 x 512 x 11 x 11 1,024 True ________________________________________________________________ AdaptiveAvgPool2d 16 x 512 x 1 x 1 0 False ________________________________________________________________ AdaptiveMaxPool2d 16 x 512 x 1 x 1 0 False ________________________________________________________________ Flatten 16 x 1024 0 False ________________________________________________________________ BatchNorm1d 16 x 1024 2,048 True ________________________________________________________________ Dropout 16 x 1024 0 False ________________________________________________________________ Linear 16 x 512 524,288 True ________________________________________________________________ ReLU 16 x 512 0 False ________________________________________________________________ BatchNorm1d 16 x 512 1,024 True ________________________________________________________________ Dropout 16 x 512 0 False ________________________________________________________________ Linear 16 x 37 18,944 True ________________________________________________________________ BatchNorm1d 16 x 37 74 True ________________________________________________________________ Total params: 21,831,050 Total trainable params: 563,402 Total non-trainable params: 21,267,648 Optimizer used: <function Adam at 0x7f7778f8b440> Loss function: FlattenedLoss of CrossEntropyLoss() Model frozen up to parameter group number 2 Callbacks: - TrainEvalCallback - Recorder - ProgressCallback
Heatmap
[ ]
[ ]
[ ]
[ ]
[ ]
torch.Size([512, 11, 11])
[ ]
torch.Size([11, 11])
[ ]
[ ]
Grad-CAM
[ ]
(torch.Size([512, 11, 11]), torch.Size([512]))
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
'Abyssinian'
[ ]
[ ]
[ ]
fin
[ ]