Skip to content

Instantly share code, notes, and snippets.

@noklam
Last active March 14, 2019 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noklam/bdb4e6e3a73f89c7cbbbef7d42140a0b to your computer and use it in GitHub Desktop.
Save noklam/bdb4e6e3a73f89c7cbbbef7d42140a0b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import fastai\n",
"from fastai import * # Quick access to most common functionality\n",
"from fastai.vision import * # Quick access to computer vision functionality"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"path = untar_data(URLs.MNIST_TINY)\n",
"data = ImageDataBunch.from_folder(path, ds_tfms=([], []), bs=2)\n",
"learn = create_cnn(data, models.resnet18, metrics=accuracy)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"======================================================================\n",
"Layer (type) Output Shape Param # Trainable \n",
"======================================================================\n",
"Conv2d [2, 64, 14, 14] 9408 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 64, 14, 14] 128 True \n",
"______________________________________________________________________\n",
"ReLU [2, 64, 14, 14] 0 False \n",
"______________________________________________________________________\n",
"MaxPool2d [2, 64, 7, 7] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 64, 7, 7] 36864 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 64, 7, 7] 128 True \n",
"______________________________________________________________________\n",
"ReLU [2, 64, 7, 7] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 64, 7, 7] 36864 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 64, 7, 7] 128 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 64, 7, 7] 36864 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 64, 7, 7] 128 True \n",
"______________________________________________________________________\n",
"ReLU [2, 64, 7, 7] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 64, 7, 7] 36864 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 64, 7, 7] 128 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 128, 4, 4] 73728 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 128, 4, 4] 256 True \n",
"______________________________________________________________________\n",
"ReLU [2, 128, 4, 4] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 128, 4, 4] 147456 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 128, 4, 4] 256 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 128, 4, 4] 8192 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 128, 4, 4] 256 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 128, 4, 4] 147456 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 128, 4, 4] 256 True \n",
"______________________________________________________________________\n",
"ReLU [2, 128, 4, 4] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 128, 4, 4] 147456 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 128, 4, 4] 256 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 256, 2, 2] 294912 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 256, 2, 2] 512 True \n",
"______________________________________________________________________\n",
"ReLU [2, 256, 2, 2] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 256, 2, 2] 589824 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 256, 2, 2] 512 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 256, 2, 2] 32768 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 256, 2, 2] 512 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 256, 2, 2] 589824 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 256, 2, 2] 512 True \n",
"______________________________________________________________________\n",
"ReLU [2, 256, 2, 2] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 256, 2, 2] 589824 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 256, 2, 2] 512 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 512, 1, 1] 1179648 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 512, 1, 1] 1024 True \n",
"______________________________________________________________________\n",
"ReLU [2, 512, 1, 1] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 512, 1, 1] 2359296 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 512, 1, 1] 1024 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 512, 1, 1] 131072 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 512, 1, 1] 1024 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 512, 1, 1] 2359296 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 512, 1, 1] 1024 True \n",
"______________________________________________________________________\n",
"ReLU [2, 512, 1, 1] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 512, 1, 1] 2359296 False \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 512, 1, 1] 1024 True \n",
"______________________________________________________________________\n",
"AdaptiveAvgPool2d [2, 512, 1, 1] 0 False \n",
"______________________________________________________________________\n",
"AdaptiveMaxPool2d [2, 512, 1, 1] 0 False \n",
"______________________________________________________________________\n",
"Lambda [2, 1024] 0 False \n",
"______________________________________________________________________\n",
"BatchNorm1d [2, 1024] 2048 True \n",
"______________________________________________________________________\n",
"Dropout [2, 1024] 0 False \n",
"______________________________________________________________________\n",
"Linear [2, 512] 524800 True \n",
"______________________________________________________________________\n",
"ReLU [2, 512] 0 False \n",
"______________________________________________________________________\n",
"BatchNorm1d [2, 512] 1024 True \n",
"______________________________________________________________________\n",
"Dropout [2, 512] 0 False \n",
"______________________________________________________________________\n",
"Linear [2, 2] 1026 True \n",
"______________________________________________________________________\n",
"Total params: 11705410\n",
"Total trainable params: 538498\n",
"Total non-trainable params: 11166912\n"
]
}
],
"source": [
"learn.summary()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Unfreeze, make all layer trainable"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"learn.unfreeze()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"======================================================================\n",
"Layer (type) Output Shape Param # Trainable \n",
"======================================================================\n",
"Conv2d [2, 64, 14, 14] 9408 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 64, 14, 14] 128 True \n",
"______________________________________________________________________\n",
"ReLU [2, 64, 14, 14] 0 False \n",
"______________________________________________________________________\n",
"MaxPool2d [2, 64, 7, 7] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 64, 7, 7] 36864 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 64, 7, 7] 128 True \n",
"______________________________________________________________________\n",
"ReLU [2, 64, 7, 7] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 64, 7, 7] 36864 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 64, 7, 7] 128 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 64, 7, 7] 36864 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 64, 7, 7] 128 True \n",
"______________________________________________________________________\n",
"ReLU [2, 64, 7, 7] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 64, 7, 7] 36864 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 64, 7, 7] 128 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 128, 4, 4] 73728 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 128, 4, 4] 256 True \n",
"______________________________________________________________________\n",
"ReLU [2, 128, 4, 4] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 128, 4, 4] 147456 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 128, 4, 4] 256 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 128, 4, 4] 8192 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 128, 4, 4] 256 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 128, 4, 4] 147456 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 128, 4, 4] 256 True \n",
"______________________________________________________________________\n",
"ReLU [2, 128, 4, 4] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 128, 4, 4] 147456 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 128, 4, 4] 256 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 256, 2, 2] 294912 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 256, 2, 2] 512 True \n",
"______________________________________________________________________\n",
"ReLU [2, 256, 2, 2] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 256, 2, 2] 589824 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 256, 2, 2] 512 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 256, 2, 2] 32768 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 256, 2, 2] 512 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 256, 2, 2] 589824 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 256, 2, 2] 512 True \n",
"______________________________________________________________________\n",
"ReLU [2, 256, 2, 2] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 256, 2, 2] 589824 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 256, 2, 2] 512 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 512, 1, 1] 1179648 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 512, 1, 1] 1024 True \n",
"______________________________________________________________________\n",
"ReLU [2, 512, 1, 1] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 512, 1, 1] 2359296 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 512, 1, 1] 1024 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 512, 1, 1] 131072 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 512, 1, 1] 1024 True \n",
"______________________________________________________________________\n",
"Conv2d [2, 512, 1, 1] 2359296 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 512, 1, 1] 1024 True \n",
"______________________________________________________________________\n",
"ReLU [2, 512, 1, 1] 0 False \n",
"______________________________________________________________________\n",
"Conv2d [2, 512, 1, 1] 2359296 True \n",
"______________________________________________________________________\n",
"BatchNorm2d [2, 512, 1, 1] 1024 True \n",
"______________________________________________________________________\n",
"AdaptiveAvgPool2d [2, 512, 1, 1] 0 False \n",
"______________________________________________________________________\n",
"AdaptiveMaxPool2d [2, 512, 1, 1] 0 False \n",
"______________________________________________________________________\n",
"Lambda [2, 1024] 0 False \n",
"______________________________________________________________________\n",
"BatchNorm1d [2, 1024] 2048 True \n",
"______________________________________________________________________\n",
"Dropout [2, 1024] 0 False \n",
"______________________________________________________________________\n",
"Linear [2, 512] 524800 True \n",
"______________________________________________________________________\n",
"ReLU [2, 512] 0 False \n",
"______________________________________________________________________\n",
"BatchNorm1d [2, 512] 1024 True \n",
"______________________________________________________________________\n",
"Dropout [2, 512] 0 False \n",
"______________________________________________________________________\n",
"Linear [2, 2] 1026 True \n",
"______________________________________________________________________\n",
"Total params: 11705410\n",
"Total trainable params: 11705410\n",
"Total non-trainable params: 0\n"
]
}
],
"source": [
"learn.summary()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment