{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## CIFAR 10" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "%reload_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from fastai.conv_learner import *\n", "from fastai.models.cifar10.wideresnet import wrn_22\n", "torch.backends.cudnn.benchmark = True\n", "PATH = Path(\"data/cifar10/\")\n", "os.makedirs(PATH,exist_ok=True)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "classes = ('plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck')\n", "stats = (np.array([ 0.4914 , 0.48216, 0.44653]), np.array([ 0.24703, 0.24349, 0.26159]))\n", "\n", "bs=512\n", "sz=32" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "tfms = tfms_from_stats(stats, sz, aug_tfms=[RandomCrop(sz), RandomFlip()], pad=sz//8)\n", "data = ImageClassifierData.from_paths(PATH, val_name='test', tfms=tfms, bs=bs)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "m = wrn_22()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "learn = ConvLearner.from_model_data(m, data)\n", "learn.crit = nn.CrossEntropyLoss()\n", "learn.metrics = [accuracy]\n", "wd=1e-4\n", "lr=1.5" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "0f6fa780bc0b4b1e978fb7572e718ce0", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(IntProgress(value=0, description='Epoch', max=30), HTML(value='')))" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "epoch trn_loss val_loss accuracy \n", " 0 1.456755 1.499619 0.5062 \n", " 1 1.057333 1.157792 0.6116 \n", " 2 0.829041 0.783326 0.723 \n", " 3 0.66619 0.808943 0.7358 \n", " 4 0.570876 0.748631 0.7361 \n", " 5 0.495598 1.038086 0.6717 \n", " 6 0.448354 0.533581 0.8181 \n", " 7 0.415957 0.546836 0.816 \n", " 8 0.390528 0.61025 0.7827 \n", " 9 0.36144 0.751214 0.764 \n", " 10 0.351138 0.756213 0.7769 \n", " 11 0.33065 0.872244 0.7549 \n", " 12 0.323868 0.530568 0.8215 \n", " 13 0.301522 0.633277 0.8 \n", " 14 0.281426 0.609825 0.8141 \n", " 15 0.261843 0.792786 0.7706 \n", " 16 0.243936 0.727103 0.797 \n", " 17 0.233351 0.481732 0.8525 \n", " 18 0.219056 0.522896 0.8375 \n", " 19 0.196971 0.350686 0.8835 \n", " 20 0.180855 0.389286 0.8754 \n", " 21 0.150032 0.372619 0.883 \n", " 22 0.118364 0.255543 0.9182 \n", " 23 0.080524 0.22061 0.9311 \n", " 24 0.051989 0.207242 0.9347 \n", " 25 0.03802 0.21347 0.9368 \n", " 26 0.030564 0.211374 0.9381 \n", " 27 0.023117 0.214783 0.9398 \n", " 28 0.020133 0.21228 0.9421 \n", " 29 0.017761 0.212101 0.9423 \n", "\n", "CPU times: user 34min 14s, sys: 54min 24s, total: 1h 28min 38s\n", "Wall time: 17min 16s\n" ] }, { "data": { "text/plain": [ "[array([0.2121]), 0.9423000004768372]" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%time learn.fit(lr, 1, wds=wd, cycle_len=30, use_clr_beta=(20,20,0.95,0.85))" ] } ], "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" }, "toc": { "colors": { "hover_highlight": "#DAA520", "navigate_num": "#000000", "navigate_text": "#333333", "running_highlight": "#FF0000", "selected_highlight": "#FFD700", "sidebar_border": "#EEEEEE", "wrapper_background": "#FFFFFF" }, "moveMenuLeft": true, "nav_menu": { "height": "266px", "width": "252px" }, "navigate_menu": true, "number_sections": true, "sideBar": true, "threshold": 4, "toc_cell": false, "toc_section_display": "block", "toc_window_display": false, "widenNotebook": false } }, "nbformat": 4, "nbformat_minor": 2 }