Last active
December 26, 2019 01:33
-
-
Save mpdroid/1fe417aa5168a8d88318681f7ee13078 to your computer and use it in GitHub Desktop.
benchmark.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "benchmark.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"accelerator": "GPU" | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/mpdroid/1fe417aa5168a8d88318681f7ee13078/benchmark.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "HXJNifgNQ2yD", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# Original at https://github.com/fastai/course-v3/blob/master/nbs/dl1/lesson7-resnet-mnist.ipynb\n", | |
"\n", | |
"RUN_LOC = \"COLAB\"\n", | |
"# LOCAL, COLAB or KAGGLE\n", | |
"# Additional installs needed for Colab and Kaggle\n", | |
"\n", | |
"WANDB_ID = \"__use_your_own__\"\n", | |
"\n", | |
"from fastai.vision import *\n", | |
"import os\n", | |
"if RUN_LOC == \"COLAB\" or RUN_LOC == \"KAGGLE\" :\n", | |
" os.system('pip install --upgrade wandb')\n", | |
"\n", | |
"import wandb\n", | |
"from wandb.fastai import WandbCallback\n", | |
"import subprocess\n", | |
"os.system('wandb login ' + WANDB_ID)\n", | |
"wandb.init(project=\"benchmarks\")\n", | |
"\n", | |
"##############################\n", | |
"# Print system configuration\n", | |
"##############################\n", | |
"import fastai.utils.collect_env\n", | |
"fastai.utils.collect_env.show_install(1)\n", | |
"\n", | |
"import subprocess\n", | |
"\n", | |
"def run(command):\n", | |
" process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)\n", | |
" out, err = process.communicate()\n", | |
" print(out.decode('utf-8').strip())\n", | |
"\n", | |
"print('# CPU')\n", | |
"run('cat /proc/cpuinfo | egrep -m 1 \"^model name\"')\n", | |
"run('cat /proc/cpuinfo | egrep -m 1 \"^cpu MHz\"')\n", | |
"run('cat /proc/cpuinfo | egrep -m 1 \"^cpu cores\"')\n", | |
"\n", | |
"print('# RAM')\n", | |
"run('cat /proc/meminfo | egrep \"^MemTotal\"')\n", | |
"\n", | |
"\n", | |
"##############\n", | |
"# MODEL\n", | |
"##############\n", | |
"def conv2(ni,nf): return conv_layer(ni,nf,stride=2)\n", | |
"\n", | |
"def conv_and_res(ni,nf): return nn.Sequential(conv2(ni, nf), res_block(nf))\n", | |
"\n", | |
"model = nn.Sequential(\n", | |
" conv_and_res(1, 8),\n", | |
" conv_and_res(8, 16),\n", | |
" conv_and_res(16, 32),\n", | |
" conv_and_res(32, 16),\n", | |
" conv2(16, 10),\n", | |
" Flatten()\n", | |
")\n", | |
"\n", | |
"##############\n", | |
"# TRAINING\n", | |
"##############\n", | |
"path = untar_data(URLs.MNIST)\n", | |
"image_list = ImageList.from_folder(path, convert_mode='L')\n", | |
"defaults.cmap='binary'\n", | |
"sample_data = image_list.split_by_folder(train='training', valid='testing')\n", | |
"label_list = sample_data.label_from_folder()\n", | |
"x,y = label_list.train[0]\n", | |
"xforms = ([*rand_pad(padding=3, size=28, mode='zeros')], [])\n", | |
"label_list = label_list.transform(xforms)\n", | |
"batch_size = 128\n", | |
"data = label_list.databunch(bs=batch_size).normalize()\n", | |
"\n", | |
"learn = Learner(data, model, loss_func=nn.CrossEntropyLoss(), metrics=accuracy, callback_fns=WandbCallback)\n", | |
"print(learn.summary())\n", | |
"\n", | |
"# learn.lr_find(end_lr=100)\n", | |
"# learn.recorder.plot()\n", | |
"\n", | |
"learn.fit_one_cycle(12, max_lr=0.05)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment