"]},"metadata":{"tags":[]}}]},{"metadata":{"id":"AGnx1_CHuMJM","colab_type":"text"},"cell_type":"markdown","source":["## Downloading from internet"]},{"metadata":{"id":"KU0yBYDPRoHN","colab_type":"code","colab":{}},"cell_type":"code","source":["!apt-get install p7zip-full"],"execution_count":0,"outputs":[]},{"metadata":{"id":"80GJzc3xJb1l","colab_type":"code","colab":{}},"cell_type":"code","source":["!wget https://s3-ap-southeast-1.amazonaws.com/he-public-data/DL%23+Beginner.zip"],"execution_count":0,"outputs":[]},{"metadata":{"id":"5BFwhL49RDJY","colab_type":"code","colab":{}},"cell_type":"code","source":["mv 'DL#+Beginner.zip' 'DLBeginner.zip'"],"execution_count":0,"outputs":[]},{"metadata":{"id":"RE8dgFYdRZ9i","colab_type":"code","outputId":"ef2d7acf-e726-4a09-8f53-d23cd048dd88","executionInfo":{"status":"ok","timestamp":1529481293561,"user_tz":-120,"elapsed":1524,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["rm -r DL#+Beginner.zip.1"],"execution_count":0,"outputs":[{"output_type":"stream","text":["rm: cannot remove 'DL#+Beginner.zip.1': No such file or directory\r\n"],"name":"stdout"}]},{"metadata":{"id":"6ypLfSKdRRqM","colab_type":"code","outputId":"23468ce3-602e-4739-e27e-899e438a9385","executionInfo":{"status":"ok","timestamp":1529481295321,"user_tz":-120,"elapsed":1686,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":102}},"cell_type":"code","source":["ls{'/content/'}"],"execution_count":0,"outputs":[{"output_type":"stream","text":["\u001b[0m\u001b[01;34mclouderizer\u001b[0m/ DLBeginner.zip updatestatus.2\r\n","clouderizer_init.sh install_clouderizer_service.sh updatestatus.3\r\n","clouderizer.jar temp.sh updatestatus.4\r\n","clouderizer.service updatestatus updatestatus.5\r\n","\u001b[01;34mdatalab\u001b[0m/ updatestatus.1 updatestatus.6\r\n"],"name":"stdout"}]},{"metadata":{"id":"LFBy5EcyRuTC","colab_type":"code","colab":{}},"cell_type":"code","source":["!7z x DLBeginner.zip -o/content/clouderizer/fast.ai/data/"],"execution_count":0,"outputs":[]},{"metadata":{"id":"d9uVtqBH6buN","colab_type":"code","outputId":"eff7dbf4-2565-4e7b-8474-c4b47f9e03e5","executionInfo":{"status":"ok","timestamp":1529481349372,"user_tz":-120,"elapsed":1623,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["ls{'/content/clouderizer/fast.ai/data/\"DL# Beginner\"/'}"],"execution_count":0,"outputs":[{"output_type":"stream","text":["meta-data.zip test.zip train.zip\r\n"],"name":"stdout"}]},{"metadata":{"id":"zj866dOOdkV4","colab_type":"code","colab":{}},"cell_type":"code","source":["rm -r /content/DLBeginner.zip"],"execution_count":0,"outputs":[]},{"metadata":{"id":"3yooeypnQkc6","colab_type":"code","colab":{}},"cell_type":"code","source":["!7z x /content/clouderizer/fast.ai/data/\"DL# Beginner\"/train.zip -o/content/clouderizer/fast.ai/data/"],"execution_count":0,"outputs":[]},{"metadata":{"id":"haRmD7iVSBIT","colab_type":"code","colab":{}},"cell_type":"code","source":["!7z x /content/clouderizer/fast.ai/data/\"DL# Beginner\"/test.zip -o/content/clouderizer/fast.ai/data/"],"execution_count":0,"outputs":[]},{"metadata":{"id":"YixWMyYeSGAK","colab_type":"code","colab":{}},"cell_type":"code","source":["!7z x /content/clouderizer/fast.ai/data/\"DL# Beginner\"/meta-data.zip -o/content/clouderizer/fast.ai/data/"],"execution_count":0,"outputs":[]},{"metadata":{"id":"PwJI_pelR6YO","colab_type":"code","outputId":"4fd4ea70-1e59-421d-bf0c-3d1c77ee86a0","executionInfo":{"status":"ok","timestamp":1529481455989,"user_tz":-120,"elapsed":1589,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["ls{'/content/clouderizer/fast.ai/data/'}"],"execution_count":0,"outputs":[{"output_type":"stream","text":["\u001b[0m\u001b[01;34mDL# Beginner\u001b[0m/ \u001b[01;34mmeta-data\u001b[0m/ \u001b[01;34mtest\u001b[0m/ \u001b[01;34mtrain\u001b[0m/\r\n"],"name":"stdout"}]},{"metadata":{"id":"ELqVh-YYSmn2","colab_type":"code","colab":{}},"cell_type":"code","source":["!cp /content/clouderizer/fast.ai/data/meta-data/sample_submission.csv /content/clouderizer/fast.ai/data/\n","!cp /content/clouderizer/fast.ai/data/meta-data/test.csv /content/clouderizer/fast.ai/data/\n","!cp /content/clouderizer/fast.ai/data/meta-data/train.csv /content/clouderizer/fast.ai/data/\n"],"execution_count":0,"outputs":[]},{"metadata":{"id":"mrOxO-huTC6_","colab_type":"code","colab":{}},"cell_type":"code","source":["!rm -r /content/clouderizer/fast.ai/data/\"DL# Beginner\"/\n","!rm -r /content/clouderizer/fast.ai/data/meta-data/"],"execution_count":0,"outputs":[]},{"metadata":{"id":"29u7EGRbTHje","colab_type":"code","outputId":"789e7a83-27a7-4608-fe03-8636485f6e0f","executionInfo":{"status":"ok","timestamp":1529481465495,"user_tz":-120,"elapsed":2096,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["ls{'/content/clouderizer/fast.ai/data/'}"],"execution_count":0,"outputs":[{"output_type":"stream","text":["sample_submission.csv \u001b[0m\u001b[01;34mtest\u001b[0m/ test.csv \u001b[01;34mtrain\u001b[0m/ train.csv\r\n"],"name":"stdout"}]},{"metadata":{"id":"Xpo8v15vfv3p","colab_type":"code","outputId":"85cda69b-84ce-445d-ce54-aca1b7240666","executionInfo":{"status":"ok","timestamp":1529481471155,"user_tz":-120,"elapsed":5527,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":51}},"cell_type":"code","source":["!rm -r /content/clouderizer/fast.ai/data/dogscats.zip\n","!rm -r /content/clouderizer/fast.ai/data/dogscats"],"execution_count":0,"outputs":[{"output_type":"stream","text":["rm: cannot remove '/content/clouderizer/fast.ai/data/dogscats.zip': No such file or directory\n","rm: cannot remove '/content/clouderizer/fast.ai/data/dogscats': No such file or directory\n"],"name":"stdout"}]},{"metadata":{"id":"DG9F6-1IJP8u","colab_type":"code","outputId":"687c4824-6c4a-49d5-c9b9-94cdce06672c","executionInfo":{"status":"ok","timestamp":1529481472936,"user_tz":-120,"elapsed":1717,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["ls{'/content/clouderizer/fast.ai/data/'}"],"execution_count":0,"outputs":[{"output_type":"stream","text":["sample_submission.csv \u001b[0m\u001b[01;34mtest\u001b[0m/ test.csv \u001b[01;34mtrain\u001b[0m/ train.csv\r\n"],"name":"stdout"}]},{"metadata":{"id":"ZxUvWWxzx1dm","colab_type":"text"},"cell_type":"markdown","source":["# Problems & Fix"]},{"metadata":{"id":"vSZ858IC0h6e","colab_type":"text"},"cell_type":"markdown","source":["## Weights\n","\n","* Cannot find resnext_101_64x4d.pth\n","\n","\n"]},{"metadata":{"id":"d2q0YKI404rc","colab_type":"code","outputId":"5a94888e-4203-430d-d856-e3dacb606890","executionInfo":{"status":"ok","timestamp":1529409865275,"user_tz":-120,"elapsed":2546,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["!ls {\"/usr/local/lib/python3.6/dist-packages/fastai/weights/\"}"],"execution_count":0,"outputs":[{"output_type":"stream","text":["resnext_101_64x4d.pth\r\n"],"name":"stdout"}]},{"metadata":{"id":"idq2Q9LC38OQ","colab_type":"code","outputId":"3f292cfe-8eff-4e71-edd1-13a000cde497","executionInfo":{"status":"ok","timestamp":1529244335320,"user_tz":-120,"elapsed":1761,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh4.googleusercontent.com/-saP9k9xgYEs/AAAAAAAAAAI/AAAAAAAAACI/MLe6QIUA344/s50-c-k-no/photo.jpg","userId":"100438054878480961323"}},"colab":{"base_uri":"https://localhost:8080/","height":68}},"cell_type":"code","source":["!ls {\"/content/clouderizer/fast.ai/fastai/courses/dl1/fastai/weights\"}"],"execution_count":0,"outputs":[{"output_type":"stream","text":["inceptionresnetv2-d579a627.pth\tresnext_101_64x4d-Copy1.py wrn_50_2f.pth\r\n","inceptionv4-97ef9c30.pth\tresnext_101_64x4d.pth\r\n","resnext_101_32x4d.pth\t\tresnext_50_32x4d.pth\r\n"],"name":"stdout"}]},{"metadata":{"id":"9LoaTXTs1F3M","colab_type":"code","outputId":"bebaf175-04e7-4861-9f9e-6ea935d52e40","executionInfo":{"status":"ok","timestamp":1529481475836,"user_tz":-120,"elapsed":2821,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["!mkdir -p /usr/local/lib/python3.6/dist-packages/fastai/weights/\n","#!( cd /content/clouderizer/fast.ai/fastai/courses/dl1/fastai/weights && tar cf - . ) | (cd /usr/local/lib/python3.6/dist-packages/fastai/weights/ && tar xvpf - )\n","! cp /content/clouderizer/fast.ai/fastai/courses/dl1/fastai/weights/resnext_101_64x4d.pth /usr/local/lib/python3.6/dist-packages/fastai/weights"],"execution_count":0,"outputs":[{"output_type":"stream","text":["cp: cannot stat '/content/clouderizer/fast.ai/fastai/courses/dl1/fastai/weights/resnext_101_64x4d.pth': No such file or directory\r\n"],"name":"stdout"}]},{"metadata":{"id":"V4C3q-KbqJuU","colab_type":"code","colab":{}},"cell_type":"code","source":["#!mkdir -p /content/clouderizer/fast.ai/fastai/courses/dl1/fastai/weights/"],"execution_count":0,"outputs":[]},{"metadata":{"id":"5_EDbUxV4cuW","colab_type":"code","outputId":"79623206-96ce-4420-88c0-b92670d5dbeb","executionInfo":{"status":"ok","timestamp":1529483359115,"user_tz":-120,"elapsed":47103,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":765}},"cell_type":"code","source":["!wget http://files.fast.ai/models/weights.tgz -d\n","!tar -xf /content/weights.tgz "],"execution_count":0,"outputs":[{"output_type":"stream","text":["DEBUG output created by Wget 1.19.1 on linux-gnu.\r\n","\r\n","Reading HSTS entries from /content/.wget-hsts\r\n","URI encoding = ‘UTF-8’\r\n","Converted file name 'weights.tgz' (UTF-8) -> 'weights.tgz' (UTF-8)\r\n","--2018-06-20 08:28:32-- http://files.fast.ai/models/weights.tgz\r\n","Resolving files.fast.ai (files.fast.ai)... 67.205.15.147\r\n","Caching files.fast.ai => 67.205.15.147\n","Connecting to files.fast.ai (files.fast.ai)|67.205.15.147|:80... connected.\n","Created socket 3.\n","Releasing 0x0000558626764380 (new refcount 1).\n","\n","---request begin---\n","GET /models/weights.tgz HTTP/1.1\n","User-Agent: Wget/1.19.1 (linux-gnu)\n","Accept: */*\n","Accept-Encoding: identity\n","Host: files.fast.ai\n","Connection: Keep-Alive\n","\n","---request end---\n","HTTP request sent, awaiting response... \n","---response begin---\n","HTTP/1.1 200 OK\n","Date: Wed, 20 Jun 2018 08:28:32 GMT\n","Server: Apache\n","Last-Modified: Sat, 04 Nov 2017 13:04:50 GMT\n","ETag: \"47408776-55d27ddd9cac6\"\n","Accept-Ranges: bytes\n","Content-Length: 1195411318\n","Keep-Alive: timeout=2, max=100\n","Connection: Keep-Alive\n","Content-Type: text/plain\n","\n","---response end---\n","200 OK\n","Registered socket 3 for persistent reuse.\n","Length: 1195411318 (1.1G) [text/plain]\n","Saving to: ‘weights.tgz’\n","\n","weights.tgz 59%[==========> ] 672.67M 43.0MB/s eta 12s "],"name":"stdout"},{"output_type":"stream","text":["weights.tgz 100%[===================>] 1.11G 43.0MB/s in 27s \n","\n","2018-06-20 08:28:59 (42.3 MB/s) - ‘weights.tgz’ saved [1195411318/1195411318]\n","\n"],"name":"stdout"}]},{"metadata":{"id":"3vMFY0mBsgw4","colab_type":"code","colab":{}},"cell_type":"code","source":["mv /content/weights/resnext_101_64x4d.pth /usr/local/lib/python3.6/dist-packages/fastai/weights/"],"execution_count":0,"outputs":[]},{"metadata":{"id":"hdlzGUTqsngE","colab_type":"code","outputId":"e8f984d4-f63e-4a5e-aa78-8f8262c5cee6","executionInfo":{"status":"ok","timestamp":1529483365571,"user_tz":-120,"elapsed":1902,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["!ls {\"/usr/local/lib/python3.6/dist-packages/fastai/weights/\"}"],"execution_count":0,"outputs":[{"output_type":"stream","text":["resnext_101_64x4d.pth\r\n"],"name":"stdout"}]},{"metadata":{"id":"1R8tl600x-e8","colab_type":"text"},"cell_type":"markdown","source":["## TTA\n","\n","* AttributeError: ‘bool’ object has no attribute ‘mean’\" error in lesson1 Dogbreed example"]},{"metadata":{"id":"Jx6iJbAPx0mw","colab_type":"code","outputId":"58a5287c-b4e4-4d6c-c9cc-5fc8c606d9ef","executionInfo":{"status":"ok","timestamp":1528473889272,"user_tz":-120,"elapsed":8092,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh4.googleusercontent.com/-saP9k9xgYEs/AAAAAAAAAAI/AAAAAAAAACI/MLe6QIUA344/s50-c-k-no/photo.jpg","userId":"100438054878480961323"}},"colab":{"base_uri":"https://localhost:8080/","height":394}},"cell_type":"code","source":["!rm -r /usr/local/lib/python3.6/dist-packages/fastai/metrics.py\n","#!ls {\"/usr/local/lib/python3.6/dist-packages/fastai/\"}\n","!wget https://github.com/fastai/fastai/blob/f94fe9b08da60cf76b805ce9926a87b91b5eae24/fastai/metrics.py\n","#!ls {\"/content/\"}\n","!mv /content/metrics.py /usr/local/lib/python3.6/dist-packages/fastai/\n","!ls {\"/usr/local/lib/python3.6/dist-packages/fastai/\"}"],"execution_count":0,"outputs":[{"output_type":"stream","text":["--2018-06-08 16:05:06-- https://github.com/fastai/fastai/blob/f94fe9b08da60cf76b805ce9926a87b91b5eae24/fastai/metrics.py\n","Resolving github.com (github.com)... 192.30.253.112, 192.30.253.113\n","Connecting to github.com (github.com)|192.30.253.112|:443... connected.\n","HTTP request sent, awaiting response... 200 OK\n","Length: unspecified [text/html]\n","Saving to: ‘metrics.py’\n","\n","metrics.py [ <=> ] 51.18K 314KB/s in 0.2s \n","\n","2018-06-08 16:05:07 (314 KB/s) - ‘metrics.py’ saved [52409]\n","\n","adaptive_softmax.py initializers.py\t metrics.py\tsgdr.py\n","column_data.py\t __init__.py\t model.py\tstructured.py\n","conv_learner.py io.py\t\t models\tswa.py\n","core.py\t\t layer_optimizer.py nlp.py\ttext.py\n","dataloader.py\t layers.py\t\t plots.py\ttorch_imports.py\n","dataset.py\t learner.py\t\t __pycache__\ttransforms_pil.py\n","executors.py\t lm_rnn.py\t\t rnn_reg.py\ttransforms.py\n","fp16.py\t\t losses.py\t\t rnn_train.py\tutils.py\n","imports.py\t lsuv_initializer.py set_spawn.py\tweights\n"],"name":"stdout"}]},{"metadata":{"id":"5OrQwfgfxbYw","colab_type":"text"},"cell_type":"markdown","source":["# CODE"]},{"metadata":{"id":"bAxPFHOGU9ZG","colab_type":"text"},"cell_type":"markdown","source":["##Pre Training"]},{"metadata":{"id":"5QmH83QDc_e8","colab_type":"code","colab":{}},"cell_type":"code","source":["# Put these at the top of every notebook, to get automatic reloading and inline plotting\n","%reload_ext autoreload\n","%autoreload 2\n","%matplotlib inline"],"execution_count":0,"outputs":[]},{"metadata":{"id":"pvcjwrBqc_fG","colab_type":"code","colab":{}},"cell_type":"code","source":["\n","from fastai.imports import *\n","from fastai.transforms import *\n","from fastai.conv_learner import *\n","from fastai.model import *\n","from fastai.dataset import *\n","from fastai.sgdr import *\n","from fastai.plots import *"],"execution_count":0,"outputs":[]},{"metadata":{"id":"4Y89GZRhc_fQ","colab_type":"code","outputId":"3fbd37bf-17c9-4236-83c3-04e6a21c8a11","executionInfo":{"status":"ok","timestamp":1529496420882,"user_tz":-120,"elapsed":668,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["torch.cuda.is_available()"],"execution_count":0,"outputs":[{"output_type":"execute_result","data":{"text/plain":["True"]},"metadata":{"tags":[]},"execution_count":3}]},{"metadata":{"id":"qm0BvUEHc_fk","colab_type":"code","outputId":"fe9c53ce-5408-4091-a689-5ada3cb530aa","executionInfo":{"status":"ok","timestamp":1529496421600,"user_tz":-120,"elapsed":596,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["torch.backends.cudnn.enabled"],"execution_count":0,"outputs":[{"output_type":"execute_result","data":{"text/plain":["True"]},"metadata":{"tags":[]},"execution_count":4}]},{"metadata":{"id":"BfHQYdSbISkA","colab_type":"code","colab":{}},"cell_type":"code","source":["PATH = \"/content/clouderizer/fast.ai/data/\"\n","arch = resnext101_64"],"execution_count":0,"outputs":[]},{"metadata":{"id":"E6I24tKWc_f-","colab_type":"code","colab":{}},"cell_type":"code","source":["sz=224"],"execution_count":0,"outputs":[]},{"metadata":{"id":"UjKp0FlOV1xE","colab_type":"code","colab":{}},"cell_type":"code","source":["bs=16 #batch size"],"execution_count":0,"outputs":[]},{"metadata":{"id":"bRw-LFyPmENU","colab_type":"code","outputId":"2b1e6c7c-9a0b-4d0a-87fa-1cc267fd4720","executionInfo":{"status":"ok","timestamp":1529523627621,"user_tz":-120,"elapsed":1996,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["!ls {\"/content/clouderizer/fast.ai/data/\"}"],"execution_count":0,"outputs":[{"output_type":"stream","text":["sample_submission.csv test test.csv tmp train train.csv\r\n"],"name":"stdout"}]},{"metadata":{"id":"MpdcaVI5j6YF","colab_type":"code","colab":{}},"cell_type":"code","source":["#!rm -r /content/clouderizer/fast.ai/data/tmp"],"execution_count":0,"outputs":[]},{"metadata":{"id":"-lj7h5HfyU_-","colab_type":"text"},"cell_type":"markdown","source":["###Making validation set"]},{"metadata":{"id":"2s5KgC_Dc_gE","colab_type":"code","colab":{}},"cell_type":"code","source":["label_csv = f'{PATH}train.csv'\n","n = len(list(open(label_csv)))-1 #number of trainig examples = # labels"],"execution_count":0,"outputs":[]},{"metadata":{"id":"HJfCUDInXSSb","colab_type":"code","colab":{}},"cell_type":"code","source":["val_idxs = get_cv_idxs(n) "],"execution_count":0,"outputs":[]},{"metadata":{"id":"4YhtHbCdc_gQ","colab_type":"code","outputId":"29a875a1-ca6d-4ce5-a617-c4a1290194fe","executionInfo":{"status":"ok","timestamp":1529496430132,"user_tz":-120,"elapsed":610,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["n"],"execution_count":0,"outputs":[{"output_type":"execute_result","data":{"text/plain":["13000"]},"metadata":{"tags":[]},"execution_count":11}]},{"metadata":{"id":"EaHTA9AHc_gw","colab_type":"code","outputId":"6ce2d634-36f8-4533-b8f8-d049e18cfd2c","executionInfo":{"status":"ok","timestamp":1529496430930,"user_tz":-120,"elapsed":697,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["len(val_idxs)"],"execution_count":0,"outputs":[{"output_type":"execute_result","data":{"text/plain":["2600"]},"metadata":{"tags":[]},"execution_count":12}]},{"metadata":{"id":"y1aEH43wc_hO","colab_type":"code","outputId":"179c7227-fa43-4e27-b2ed-eba2eaf32718","executionInfo":{"status":"ok","timestamp":1529494390094,"user_tz":-120,"elapsed":576,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["val_idxs"],"execution_count":0,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([3615, 2536, 5397, ..., 7277, 3752, 6292])"]},"metadata":{"tags":[]},"execution_count":13}]},{"metadata":{"id":"20-bDejgz7YM","colab_type":"text"},"cell_type":"markdown","source":["## Looking to the data "]},{"metadata":{"id":"FCr9tD7Dc_hc","colab_type":"code","outputId":"d7e42783-8715-4b81-94ad-7c8a536a7440","executionInfo":{"status":"ok","timestamp":1529317780451,"user_tz":-120,"elapsed":602,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh4.googleusercontent.com/-saP9k9xgYEs/AAAAAAAAAAI/AAAAAAAAACI/MLe6QIUA344/s50-c-k-no/photo.jpg","userId":"100438054878480961323"}},"colab":{"base_uri":"https://localhost:8080/","height":204}},"cell_type":"code","source":["label_df = pd.read_csv(label_csv)\n","label_df.head()"],"execution_count":0,"outputs":[{"output_type":"execute_result","data":{"text/html":["\n","\n","
\n"," \n"," \n"," | \n"," Image_id | \n"," Animal | \n","
\n"," \n"," \n"," \n"," | 0 | \n"," Img-1.jpg | \n"," hippopotamus | \n","
\n"," \n"," | 1 | \n"," Img-2.jpg | \n"," squirrel | \n","
\n"," \n"," | 2 | \n"," Img-3.jpg | \n"," grizzly+bear | \n","
\n"," \n"," | 3 | \n"," Img-4.jpg | \n"," ox | \n","
\n"," \n"," | 4 | \n"," Img-5.jpg | \n"," german+shepherd | \n","
\n"," \n","
\n","
"],"text/plain":[" Image_id Animal\n","0 Img-1.jpg hippopotamus\n","1 Img-2.jpg squirrel\n","2 Img-3.jpg grizzly+bear\n","3 Img-4.jpg ox\n","4 Img-5.jpg german+shepherd"]},"metadata":{"tags":[]},"execution_count":87}]},{"metadata":{"id":"BLLJMR3Kc_hy","colab_type":"code","outputId":"204ca88b-cd8b-4b2e-8c33-bc2ce7359b66","executionInfo":{"status":"ok","timestamp":1529318924462,"user_tz":-120,"elapsed":2138,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh4.googleusercontent.com/-saP9k9xgYEs/AAAAAAAAAAI/AAAAAAAAACI/MLe6QIUA344/s50-c-k-no/photo.jpg","userId":"100438054878480961323"}},"colab":{"base_uri":"https://localhost:8080/","height":1010}},"cell_type":"code","source":["label_df.pivot_table(index='Animal', aggfunc=len).sort_values('Image_id', ascending=False) #group it up"],"execution_count":0,"outputs":[{"output_type":"execute_result","data":{"text/html":["\n","\n","
\n"," \n"," \n"," | \n"," Image_id | \n","
\n"," \n"," | Animal | \n"," | \n","
\n"," \n"," \n"," \n"," | antelope | \n"," 695 | \n","
\n"," \n"," | bat | \n"," 256 | \n","
\n"," \n"," | beaver | \n"," 133 | \n","
\n"," \n"," | bobcat | \n"," 418 | \n","
\n"," \n"," | buffalo | \n"," 606 | \n","
\n"," \n"," | chihuahua | \n"," 386 | \n","
\n"," \n"," | chimpanzee | \n"," 477 | \n","
\n"," \n"," | collie | \n"," 680 | \n","
\n"," \n"," | dalmatian | \n"," 359 | \n","
\n"," \n"," | german+shepherd | \n"," 687 | \n","
\n"," \n"," | grizzly+bear | \n"," 583 | \n","
\n"," \n"," | hippopotamus | \n"," 464 | \n","
\n"," \n"," | horse | \n"," 1111 | \n","
\n"," \n"," | killer+whale | \n"," 193 | \n","
\n"," \n"," | mole | \n"," 60 | \n","
\n"," \n"," | moose | \n"," 476 | \n","
\n"," \n"," | mouse | \n"," 124 | \n","
\n"," \n"," | otter | \n"," 519 | \n","
\n"," \n"," | ox | \n"," 501 | \n","
\n"," \n"," | persian+cat | \n"," 491 | \n","
\n"," \n"," | raccoon | \n"," 346 | \n","
\n"," \n"," | rat | \n"," 220 | \n","
\n"," \n"," | rhinoceros | \n"," 477 | \n","
\n"," \n"," | seal | \n"," 665 | \n","
\n"," \n"," | siamese+cat | \n"," 341 | \n","
\n"," \n"," | spider+monkey | \n"," 189 | \n","
\n"," \n"," | squirrel | \n"," 808 | \n","
\n"," \n"," | walrus | \n"," 148 | \n","
\n"," \n"," | weasel | \n"," 184 | \n","
\n"," \n"," | wolf | \n"," 403 | \n","
\n"," \n","
\n","
"],"text/plain":[" Image_id\n","Animal \n","antelope 695\n","bat 256\n","beaver 133\n","bobcat 418\n","buffalo 606\n","chihuahua 386\n","chimpanzee 477\n","collie 680\n","dalmatian 359\n","german+shepherd 687\n","grizzly+bear 583\n","hippopotamus 464\n","horse 1111\n","killer+whale 193\n","mole 60\n","moose 476\n","mouse 124\n","otter 519\n","ox 501\n","persian+cat 491\n","raccoon 346\n","rat 220\n","rhinoceros 477\n","seal 665\n","siamese+cat 341\n","spider+monkey 189\n","squirrel 808\n","walrus 148\n","weasel 184\n","wolf 403"]},"metadata":{"tags":[]},"execution_count":124}]},{"metadata":{"id":"x6vRad8vc_iA","colab_type":"code","colab":{}},"cell_type":"code","source":["tfms = tfms_from_model(arch, sz, aug_tfms=transforms_side_on, \n"," max_zoom=1.1)\n","\n","data = ImageClassifierData.from_csv(PATH, 'train', \n"," f'{PATH}train.csv', test_name='test', \n"," val_idxs = val_idxs , tfms=tfms, bs=bs)"],"execution_count":0,"outputs":[]},{"metadata":{"id":"qLMOaXaWc_iM","colab_type":"code","outputId":"46d5d568-a2dc-4c84-f255-d88590a3bd2a","executionInfo":{"status":"ok","timestamp":1529188289091,"user_tz":-120,"elapsed":652,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh4.googleusercontent.com/-saP9k9xgYEs/AAAAAAAAAAI/AAAAAAAAACI/MLe6QIUA344/s50-c-k-no/photo.jpg","userId":"100438054878480961323"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["#You can access to training dataset by saying data.trn_ds and trn_ds contains a lot of things including file names (fnames)\n","fn = PATH + data.trn_ds.fnames[1]; fn "],"execution_count":0,"outputs":[{"output_type":"execute_result","data":{"text/plain":["'/content/clouderizer/fast.ai/data/train/Img-3.jpg'"]},"metadata":{"tags":[]},"execution_count":17}]},{"metadata":{"id":"3NGbAfE2c_iS","colab_type":"code","colab":{}},"cell_type":"code","source":["img = PIL.Image.open(fn); img"],"execution_count":0,"outputs":[]},{"metadata":{"id":"j1qsgL10c_ia","colab_type":"code","outputId":"b09f0c51-1c9e-4dbf-cc72-9cb5a435650a","executionInfo":{"status":"ok","timestamp":1529188326258,"user_tz":-120,"elapsed":1167,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh4.googleusercontent.com/-saP9k9xgYEs/AAAAAAAAAAI/AAAAAAAAACI/MLe6QIUA344/s50-c-k-no/photo.jpg","userId":"100438054878480961323"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["img.size"],"execution_count":0,"outputs":[{"output_type":"execute_result","data":{"text/plain":["(1024, 683)"]},"metadata":{"tags":[]},"execution_count":19}]},{"metadata":{"id":"TQTPjt0chHTE","colab_type":"text"},"cell_type":"markdown","source":["### to know all sizes am dealing with"]},{"metadata":{"id":"-UX4RgbKc_iu","colab_type":"code","colab":{}},"cell_type":"code","source":["size_d = {k: PIL.Image.open(PATH+k).size for k in data.trn_ds.fnames} # match name to size "],"execution_count":0,"outputs":[]},{"metadata":{"id":"Kw2hPA6Tc_i-","colab_type":"code","colab":{}},"cell_type":"code","source":["row_sz, col_sz = list(zip(*size_d.values()))"],"execution_count":0,"outputs":[]},{"metadata":{"id":"u4fty6ylc_jG","colab_type":"code","colab":{}},"cell_type":"code","source":["row_sz = np.array(row_sz); col_sz = np.array(col_sz); "],"execution_count":0,"outputs":[]},{"metadata":{"id":"lOs_hRzMc_jM","colab_type":"code","outputId":"e562d030-4bcf-4216-d902-f9988e2b0ed9","executionInfo":{"status":"ok","timestamp":1529188336480,"user_tz":-120,"elapsed":911,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh4.googleusercontent.com/-saP9k9xgYEs/AAAAAAAAAAI/AAAAAAAAACI/MLe6QIUA344/s50-c-k-no/photo.jpg","userId":"100438054878480961323"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["row_sz[:15]"],"execution_count":0,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([1024, 1024, 332, 1024, 1024, 640, 333, 1024, 1024, 1024, 1024, 1024, 500, 1024, 1024])"]},"metadata":{"tags":[]},"execution_count":23}]},{"metadata":{"id":"I-k8-ohVc_jS","colab_type":"code","outputId":"763a9980-149e-4b64-ef24-f4de2f7c2528","executionInfo":{"status":"ok","timestamp":1529188339623,"user_tz":-120,"elapsed":2825,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh4.googleusercontent.com/-saP9k9xgYEs/AAAAAAAAAAI/AAAAAAAAACI/MLe6QIUA344/s50-c-k-no/photo.jpg","userId":"100438054878480961323"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["col_sz[:15]"],"execution_count":0,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([771, 683, 500, 768, 683, 426, 500, 681, 683, 768, 678, 683, 375, 683, 730])"]},"metadata":{"tags":[]},"execution_count":24}]},{"metadata":{"id":"IiPw64R4c_jY","colab_type":"code","colab":{}},"cell_type":"code","source":["plt.hist(row_sz);"],"execution_count":0,"outputs":[]},{"metadata":{"id":"bUzCl5eoc_je","colab_type":"code","colab":{}},"cell_type":"code","source":["plt.hist(col_sz);"],"execution_count":0,"outputs":[]},{"metadata":{"id":"ZWe-CDA8c_ji","colab_type":"code","colab":{}},"cell_type":"code","source":["plt.hist(row_sz[row_sz<1000])"],"execution_count":0,"outputs":[]},{"metadata":{"id":"WHOZHGOq0GtW","colab_type":"text"},"cell_type":"markdown","source":["## Training"]},{"metadata":{"id":"Ul0pcMQuc_jm","colab_type":"code","colab":{}},"cell_type":"code","source":["def get_data(sz, bs):\n"," tfms = tfms_from_model(arch, sz, aug_tfms=transforms_side_on,\n"," max_zoom=1.1)\n"," data = ImageClassifierData.from_csv(PATH, 'train', \n"," f'{PATH}train.csv', test_name='test', num_workers=4,\n"," val_idxs = val_idxs ,tfms=tfms, bs=bs)\n","\n"," return data if sz>300 else data.resize(340, 'tmp')"],"execution_count":0,"outputs":[]},{"metadata":{"id":"cEiLCYCpc_kM","colab_type":"code","colab":{}},"cell_type":"code","source":["data = get_data(224, 64)\n","\n","learn = ConvLearner.pretrained(arch, data, precompute=True)\n","\n","#learn.fit(1e-2, 5)\n","#learn.fit(0.01,4)"],"execution_count":0,"outputs":[]},{"metadata":{"id":"nN4FgKoHqa9c","colab_type":"text"},"cell_type":"markdown","source":["###choosing learning rate"]},{"metadata":{"id":"BZ6Rh-Ns8RYS","colab_type":"code","outputId":"16e58a1f-8a2e-4489-b6b1-a78e676387c4","executionInfo":{"status":"ok","timestamp":1529245803385,"user_tz":-120,"elapsed":7993,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh4.googleusercontent.com/-saP9k9xgYEs/AAAAAAAAAAI/AAAAAAAAACI/MLe6QIUA344/s50-c-k-no/photo.jpg","userId":"100438054878480961323"}},"colab":{"base_uri":"https://localhost:8080/","height":51}},"cell_type":"code","source":["#choosing learning rate\n","lrf=learn.lr_find()"],"execution_count":0,"outputs":[{"output_type":"display_data","data":{"application/vnd.jupyter.widget-view+json":{"model_id":"f6d90297ebf644c791c0baa3c9f6a459","version_minor":0,"version_major":2},"text/plain":["HBox(children=(IntProgress(value=0, description='Epoch', max=1), HTML(value='')))"]},"metadata":{"tags":[]}},{"output_type":"stream","text":[" 66%|██████▌ | 426/650 [00:07<00:03, 57.73it/s, loss=0.23] \n"],"name":"stdout"}]},{"metadata":{"id":"qj0mOAaI8dPd","colab_type":"code","colab":{}},"cell_type":"code","source":["learn.sched.plot_lr()"],"execution_count":0,"outputs":[]},{"metadata":{"id":"fOZOP8oC8WBV","colab_type":"code","colab":{}},"cell_type":"code","source":["learn.sched.plot()"],"execution_count":0,"outputs":[]},{"metadata":{"id":"R0NS5jLeqgwx","colab_type":"text"},"cell_type":"markdown","source":["### Continue Training "]},{"metadata":{"id":"8Yrto0ZSmCX0","colab_type":"code","colab":{}},"cell_type":"code","source":["bs=64 #batch size"],"execution_count":0,"outputs":[]},{"metadata":{"id":"7A8sGufvRW54","colab_type":"code","colab":{}},"cell_type":"code","source":["learn.precompute = False"],"execution_count":0,"outputs":[]},{"metadata":{"id":"QInZdoMIRZI8","colab_type":"code","outputId":"2925af91-226f-4199-bb29-ea9fd497ddcb","executionInfo":{"status":"ok","timestamp":1529496361840,"user_tz":-120,"elapsed":835558,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":119}},"cell_type":"code","source":["learn.fit(1e-2, 2, cycle_len=1)"],"execution_count":0,"outputs":[{"output_type":"display_data","data":{"application/vnd.jupyter.widget-view+json":{"model_id":"6f62898679ad415bae9886cc91045735","version_minor":0,"version_major":2},"text/plain":["HBox(children=(IntProgress(value=0, description='Epoch', max=2), HTML(value='')))"]},"metadata":{"tags":[]}},{"output_type":"stream","text":["epoch trn_loss val_loss accuracy \n"," 0 0.141684 0.142369 0.956538 \n"," 1 0.128146 0.14134 0.957692 \n","\n"],"name":"stdout"},{"output_type":"execute_result","data":{"text/plain":["[array([0.14134]), 0.9576923076923077]"]},"metadata":{"tags":[]},"execution_count":18}]},{"metadata":{"id":"OkeTophrRc38","colab_type":"code","colab":{}},"cell_type":"code","source":["learn.save('224_pre')\n","learn.load('224_pre')"],"execution_count":0,"outputs":[]},{"metadata":{"id":"wLkRcU6NRczY","colab_type":"code","colab":{}},"cell_type":"code","source":["lr = 0.01"],"execution_count":0,"outputs":[]},{"metadata":{"id":"1q2bXEClRcrp","colab_type":"code","colab":{}},"cell_type":"code","source":["lrs=np.array([1e-4,1e-3,1e-2])"],"execution_count":0,"outputs":[]},{"metadata":{"id":"HwLvwsqZRcnP","colab_type":"code","outputId":"6c5c6558-acb1-4bd9-b571-4c3de7748cd0","executionInfo":{"status":"ok","timestamp":1529500176329,"user_tz":-120,"elapsed":3675122,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":170}},"cell_type":"code","source":["learn.set_data(get_data(224, 16))\n","learn.unfreeze()\n","learn.fit(lrs, 2, cycle_len=1, cycle_mult=2)"],"execution_count":0,"outputs":[{"output_type":"display_data","data":{"application/vnd.jupyter.widget-view+json":{"model_id":"acb012d72b824166b96107d685657bd6","version_minor":0,"version_major":2},"text/plain":["HBox(children=(IntProgress(value=0, max=6), HTML(value='')))"]},"metadata":{"tags":[]}},{"output_type":"stream","text":["\n"],"name":"stdout"},{"output_type":"display_data","data":{"application/vnd.jupyter.widget-view+json":{"model_id":"31db39f255394d028e43c84f6801db3e","version_minor":0,"version_major":2},"text/plain":["HBox(children=(IntProgress(value=0, description='Epoch', max=3), HTML(value='')))"]},"metadata":{"tags":[]}},{"output_type":"stream","text":["epoch trn_loss val_loss accuracy \n"," 0 0.296852 0.157923 0.953462 \n"," 11%|█ | 69/650 [02:02<17:11, 1.77s/it, loss=0.267]"],"name":"stdout"},{"output_type":"stream","text":[" 1 0.310218 0.168865 0.95 \n"," 22%|██▏ | 140/650 [04:05<14:52, 1.75s/it, loss=0.148]"],"name":"stdout"},{"output_type":"stream","text":[" 2 0.136627 0.142401 0.956538 \n","\n"],"name":"stdout"},{"output_type":"execute_result","data":{"text/plain":["[array([0.1424]), 0.9565384615384616]"]},"metadata":{"tags":[]},"execution_count":20}]},{"metadata":{"id":"UsXsdVx-RclT","colab_type":"code","colab":{}},"cell_type":"code","source":["learn.save('224_unf')\n","learn.load('224_unf')"],"execution_count":0,"outputs":[]},{"metadata":{"id":"utAxQJFTRcez","colab_type":"code","outputId":"dc2088a3-7ad2-4625-cf11-8bfdff42cb7d","executionInfo":{"status":"ok","timestamp":1529505651147,"user_tz":-120,"elapsed":5342605,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":238}},"cell_type":"code","source":["learn.set_data(get_data(299, 64))\n","learn.freeze()\n","learn.fit(lr, 3, cycle_len=1, cycle_mult=2)"],"execution_count":0,"outputs":[{"output_type":"display_data","data":{"application/vnd.jupyter.widget-view+json":{"model_id":"ce03197161564b59a3139ffcd98c7943","version_minor":0,"version_major":2},"text/plain":["HBox(children=(IntProgress(value=0, max=6), HTML(value='')))"]},"metadata":{"tags":[]}},{"output_type":"stream","text":["\n"],"name":"stdout"},{"output_type":"display_data","data":{"application/vnd.jupyter.widget-view+json":{"model_id":"ddd823787a5d4c07a8d2974886212820","version_minor":0,"version_major":2},"text/plain":["HBox(children=(IntProgress(value=0, description='Epoch', max=7), HTML(value='')))"]},"metadata":{"tags":[]}},{"output_type":"stream","text":["epoch trn_loss val_loss accuracy \n"," 0 0.058037 0.117189 0.963846 \n"," 1 0.053475 0.115467 0.963462 \n"," 48%|████▊ | 78/163 [04:52<05:19, 3.76s/it, loss=0.0493]"],"name":"stdout"},{"output_type":"stream","text":[" 2 0.044146 0.115534 0.963846 \n"," 3 0.040821 0.114715 0.964231 \n"," 4 0.038928 0.11441 0.963846 \n"," 9%|▊ | 14/163 [00:58<10:23, 4.18s/it, loss=0.0377]"],"name":"stdout"},{"output_type":"stream","text":[" 5 0.038991 0.114662 0.963462 \n"," 6 0.035684 0.114365 0.963077 \n","\n"],"name":"stdout"},{"output_type":"execute_result","data":{"text/plain":["[array([0.11436]), 0.9630769227101252]"]},"metadata":{"tags":[]},"execution_count":22}]},{"metadata":{"id":"VFKQFInzRyGh","colab_type":"code","colab":{}},"cell_type":"code","source":["learn.save('229_pre')\n","learn.load('229_pre')"],"execution_count":0,"outputs":[]},{"metadata":{"id":"XGBtQE-FRyCN","colab_type":"code","colab":{}},"cell_type":"code","source":["learn.set_data(get_data(360, 64))"],"execution_count":0,"outputs":[]},{"metadata":{"id":"kiSow-v7Rx_e","colab_type":"code","outputId":"55aeed42-0617-4bb0-d7fa-5f9e71274595","executionInfo":{"status":"ok","timestamp":1529509200007,"user_tz":-120,"elapsed":3342972,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":136}},"cell_type":"code","source":["learn.fit(lr, 2, cycle_len=1, cycle_mult=2)"],"execution_count":0,"outputs":[{"output_type":"display_data","data":{"application/vnd.jupyter.widget-view+json":{"model_id":"4ecc25e81b6a43798e5a96ac0bb033d2","version_minor":0,"version_major":2},"text/plain":["HBox(children=(IntProgress(value=0, description='Epoch', max=3), HTML(value='')))"]},"metadata":{"tags":[]}},{"output_type":"stream","text":["epoch trn_loss val_loss accuracy \n"," 0 0.053009 0.109806 0.970385 \n"," 1 0.05007 0.107951 0.971538 \n"," 48%|████▊ | 78/163 [07:07<07:45, 5.47s/it, loss=0.0422]"],"name":"stdout"},{"output_type":"stream","text":[" 2 0.048411 0.107882 0.97 \n","\n"],"name":"stdout"},{"output_type":"execute_result","data":{"text/plain":["[array([0.10788]), 0.9699999996332022]"]},"metadata":{"tags":[]},"execution_count":25}]},{"metadata":{"id":"oJOtpEG3Rx6t","colab_type":"code","colab":{}},"cell_type":"code","source":["learn.save('360_pre')\n","learn.load('360_pre')"],"execution_count":0,"outputs":[]},{"metadata":{"id":"Ey-ENf7cx7y6","colab_type":"code","outputId":"942c700e-dc41-4086-b3de-83b0966602c6","executionInfo":{"status":"ok","timestamp":1529510314455,"user_tz":-120,"elapsed":1111581,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["log_preds, y = learn.TTA()\n","probs = np.mean(np.exp(log_preds),0)\n","accuracy_np(probs,y) ,metrics.log_loss(y, probs)"],"execution_count":0,"outputs":[{"output_type":"stream","text":[""],"name":"stdout"},{"output_type":"execute_result","data":{"text/plain":["(0.9730769230769231, 0.09717620105283725)"]},"metadata":{"tags":[]},"execution_count":27}]},{"metadata":{"id":"P7dOH9aAxkVp","colab_type":"code","colab":{}},"cell_type":"code","source":["learn.set_data(get_data(420, 16))"],"execution_count":0,"outputs":[]},{"metadata":{"id":"euujKNIlRx1D","colab_type":"code","outputId":"6d85022c-6c89-445f-b349-44538ec58470","executionInfo":{"status":"ok","timestamp":1529511869118,"user_tz":-120,"elapsed":1553789,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":102}},"cell_type":"code","source":["learn.fit(lr, 1 )"],"execution_count":0,"outputs":[{"output_type":"display_data","data":{"application/vnd.jupyter.widget-view+json":{"model_id":"2a3f3e3fae8e4219b022858032f45833","version_minor":0,"version_major":2},"text/plain":["HBox(children=(IntProgress(value=0, description='Epoch', max=1), HTML(value='')))"]},"metadata":{"tags":[]}},{"output_type":"stream","text":["epoch trn_loss val_loss accuracy \n"," 0 0.091034 0.118893 0.964615 \n","\n"],"name":"stdout"},{"output_type":"execute_result","data":{"text/plain":["[array([0.11889]), 0.9646153846153847]"]},"metadata":{"tags":[]},"execution_count":29}]},{"metadata":{"id":"3cUXgeVSKkRt","colab_type":"code","outputId":"1fd7871c-544e-492e-e524-675a7e0c3f74","executionInfo":{"status":"ok","timestamp":1529517544458,"user_tz":-120,"elapsed":3069227,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":119}},"cell_type":"code","source":["learn.fit(lr, 2 )"],"execution_count":0,"outputs":[{"output_type":"display_data","data":{"application/vnd.jupyter.widget-view+json":{"model_id":"94f6a67391bb44f188765e4885e18460","version_minor":0,"version_major":2},"text/plain":["HBox(children=(IntProgress(value=0, description='Epoch', max=2), HTML(value='')))"]},"metadata":{"tags":[]}},{"output_type":"stream","text":["epoch trn_loss val_loss accuracy \n"," 0 0.047891 0.109113 0.969231 \n"," 1 0.047826 0.10787 0.97 \n","\n"],"name":"stdout"},{"output_type":"execute_result","data":{"text/plain":["[array([0.10787]), 0.9699999996332022]"]},"metadata":{"tags":[]},"execution_count":32}]},{"metadata":{"id":"7W1D2LUGziCJ","colab_type":"code","colab":{}},"cell_type":"code","source":["learn.save('420_pre')\n","learn.load('420_pre')"],"execution_count":0,"outputs":[]},{"metadata":{"id":"8kAfMelYznbu","colab_type":"code","outputId":"2d7c5d31-8d72-42f5-fc54-6ae0c267a081","executionInfo":{"status":"ok","timestamp":1529519760633,"user_tz":-120,"elapsed":1531314,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["learn.set_data(get_data(420, 64))\n","log_preds, y = learn.TTA()\n","probs = np.mean(np.exp(log_preds),0)\n","accuracy_np(probs,y) ,metrics.log_loss(y, probs)"],"execution_count":0,"outputs":[{"output_type":"stream","text":[""],"name":"stdout"},{"output_type":"execute_result","data":{"text/plain":["(0.9742307692307692, 0.09447401728880171)"]},"metadata":{"tags":[]},"execution_count":34}]},{"metadata":{"id":"45UZP-1ofGUw","colab_type":"code","outputId":"28bcf0d3-fdf8-4540-8d7e-df8400dea8bb","executionInfo":{"status":"ok","timestamp":1529521429653,"user_tz":-120,"elapsed":1524167,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":102}},"cell_type":"code","source":["learn.fit(lr, 1)"],"execution_count":0,"outputs":[{"output_type":"display_data","data":{"application/vnd.jupyter.widget-view+json":{"model_id":"bee04a13ad4d467f93b6e7b8dfa1ce5c","version_minor":0,"version_major":2},"text/plain":["HBox(children=(IntProgress(value=0, description='Epoch', max=1), HTML(value='')))"]},"metadata":{"tags":[]}},{"output_type":"stream","text":["epoch trn_loss val_loss accuracy \n"," 0 0.037042 0.106252 0.970385 \n","\n"],"name":"stdout"},{"output_type":"execute_result","data":{"text/plain":["[array([0.10625]), 0.9703846155680143]"]},"metadata":{"tags":[]},"execution_count":35}]},{"metadata":{"id":"U3UJG77Tj66r","colab_type":"code","outputId":"24a416ee-7b3d-44c4-be30-5a880b3b9a68","executionInfo":{"status":"ok","timestamp":1529522982618,"user_tz":-120,"elapsed":1552906,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh5.googleusercontent.com/-3czhhckiTHc/AAAAAAAAAAI/AAAAAAAAAHs/N2Y9B2a8wE4/s50-c-k-no/photo.jpg","userId":"108555561654119603722"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["learn.set_data(get_data(420, 128))\n","log_preds, y = learn.TTA()\n","probs = np.mean(np.exp(log_preds),0)\n","accuracy_np(probs,y) ,metrics.log_loss(y, probs)"],"execution_count":0,"outputs":[{"output_type":"stream","text":[""],"name":"stdout"},{"output_type":"execute_result","data":{"text/plain":["(0.975, 0.09650832684605656)"]},"metadata":{"tags":[]},"execution_count":36}]},{"metadata":{"id":"vvBQrNEgsAKs","colab_type":"code","colab":{}},"cell_type":"code","source":["learn.save('420_pree')\n","learn.load('420_pree')"],"execution_count":0,"outputs":[]},{"metadata":{"id":"Fq8rVpVES4Nw","colab_type":"text"},"cell_type":"markdown","source":["#After Training"]},{"metadata":{"id":"5NHaPMDJWN2q","colab_type":"text"},"cell_type":"markdown","source":["##Getting data to submit"]},{"metadata":{"id":"qGR6-EguquW6","colab_type":"code","colab":{}},"cell_type":"code","source":["log_preds, y = learn.TTA(is_test=True)"],"execution_count":0,"outputs":[]},{"metadata":{"id":"2f8XosBtrDXQ","colab_type":"code","colab":{}},"cell_type":"code","source":["probs = np.mean(np.exp(log_preds),0)"],"execution_count":0,"outputs":[]},{"metadata":{"id":"BhTXTdLctj7i","colab_type":"code","outputId":"5aa64151-e459-40f4-98e6-ca7be37e0ab9","executionInfo":{"status":"ok","timestamp":1529008208531,"user_tz":-120,"elapsed":606,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh4.googleusercontent.com/-saP9k9xgYEs/AAAAAAAAAAI/AAAAAAAAACI/MLe6QIUA344/s50-c-k-no/photo.jpg","userId":"100438054878480961323"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["probs.shape"],"execution_count":0,"outputs":[{"output_type":"execute_result","data":{"text/plain":["(6000, 30)"]},"metadata":{"tags":[]},"execution_count":90}]},{"metadata":{"id":"_Q52VLhttjmm","colab_type":"code","colab":{}},"cell_type":"code","source":["df = pd.DataFrame(probs)\n","df.columns = data.classes"],"execution_count":0,"outputs":[]},{"metadata":{"id":"2M8eM-3_ufGg","colab_type":"code","colab":{}},"cell_type":"code","source":["df.insert(0, 'image_id', [o[5:-4] for o in data.test_ds.fnames])"],"execution_count":0,"outputs":[]},{"metadata":{"id":"LCqR969Nui3S","colab_type":"code","outputId":"a7e61092-2c37-4fcc-b51f-23bf761e6b01","executionInfo":{"status":"ok","timestamp":1529008371823,"user_tz":-120,"elapsed":2322,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh4.googleusercontent.com/-saP9k9xgYEs/AAAAAAAAAAI/AAAAAAAAACI/MLe6QIUA344/s50-c-k-no/photo.jpg","userId":"100438054878480961323"}},"colab":{"base_uri":"https://localhost:8080/","height":338}},"cell_type":"code","source":["df.head()"],"execution_count":0,"outputs":[{"output_type":"execute_result","data":{"text/html":["\n","\n","
\n"," \n"," \n"," | \n"," image_id | \n"," antelope | \n"," bat | \n"," beaver | \n"," bobcat | \n"," buffalo | \n"," chihuahua | \n"," chimpanzee | \n"," collie | \n"," dalmatian | \n"," ... | \n"," raccoon | \n"," rat | \n"," rhinoceros | \n"," seal | \n"," siamese+cat | \n"," spider+monkey | \n"," squirrel | \n"," walrus | \n"," weasel | \n"," wolf | \n","
\n"," \n"," \n"," \n"," | 0 | \n"," Img-345 | \n"," 2.290621e-08 | \n"," 5.397823e-08 | \n"," 9.216159e-07 | \n"," 0.000001 | \n"," 1.009505e-07 | \n"," 2.179231e-07 | \n"," 6.606081e-08 | \n"," 1.927896e-04 | \n"," 3.451408e-07 | \n"," ... | \n"," 3.039962e-07 | \n"," 2.646936e-08 | \n"," 1.138957e-07 | \n"," 2.144957e-08 | \n"," 7.391552e-07 | \n"," 6.125757e-08 | \n"," 1.621851e-06 | \n"," 0.000002 | \n"," 2.338239e-06 | \n"," 0.000019 | \n","
\n"," \n"," | 1 | \n"," Img-4435 | \n"," 1.714287e-03 | \n"," 5.230980e-07 | \n"," 1.888318e-06 | \n"," 0.000004 | \n"," 1.981154e-05 | \n"," 4.183834e-07 | \n"," 1.010958e-06 | \n"," 3.067886e-07 | \n"," 3.624005e-06 | \n"," ... | \n"," 1.470643e-05 | \n"," 3.828263e-06 | \n"," 9.975151e-01 | \n"," 8.201774e-06 | \n"," 8.520691e-07 | \n"," 2.560058e-06 | \n"," 8.819440e-07 | \n"," 0.000001 | \n"," 1.416625e-07 | \n"," 0.000001 | \n","
\n"," \n"," | 2 | \n"," Img-3265 | \n"," 1.669903e-05 | \n"," 2.376876e-05 | \n"," 5.170976e-05 | \n"," 0.000016 | \n"," 9.971881e-01 | \n"," 1.246746e-06 | \n"," 1.222767e-05 | \n"," 1.217500e-06 | \n"," 2.189813e-06 | \n"," ... | \n"," 7.326244e-06 | \n"," 3.169375e-06 | \n"," 1.315738e-04 | \n"," 1.736059e-05 | \n"," 8.714651e-06 | \n"," 2.145174e-05 | \n"," 1.025993e-05 | \n"," 0.000019 | \n"," 5.097419e-06 | \n"," 0.000002 | \n","
\n"," \n"," | 3 | \n"," Img-2502 | \n"," 3.286192e-04 | \n"," 1.710425e-03 | \n"," 9.071530e-06 | \n"," 0.000017 | \n"," 1.314390e-04 | \n"," 5.754872e-06 | \n"," 2.080876e-06 | \n"," 8.450975e-07 | \n"," 3.728858e-06 | \n"," ... | \n"," 2.356798e-06 | \n"," 2.367558e-05 | \n"," 9.970737e-01 | \n"," 8.674498e-06 | \n"," 5.989785e-06 | \n"," 5.226643e-06 | \n"," 1.977831e-05 | \n"," 0.000051 | \n"," 8.205399e-07 | \n"," 0.000002 | \n","
\n"," \n"," | 4 | \n"," Img-5845 | \n"," 7.917402e-05 | \n"," 1.728868e-05 | \n"," 1.186067e-04 | \n"," 0.000031 | \n"," 1.716332e-05 | \n"," 7.321220e-06 | \n"," 6.668857e-06 | \n"," 1.710979e-05 | \n"," 4.577196e-05 | \n"," ... | \n"," 2.145957e-06 | \n"," 7.412130e-04 | \n"," 3.152601e-06 | \n"," 9.907900e-01 | \n"," 1.174130e-04 | \n"," 1.349383e-05 | \n"," 3.716028e-04 | \n"," 0.003146 | \n"," 3.120525e-05 | \n"," 0.000007 | \n","
\n"," \n","
\n","
5 rows × 31 columns
\n","
"],"text/plain":[" image_id antelope bat beaver bobcat buffalo \\\n","0 Img-345 2.290621e-08 5.397823e-08 9.216159e-07 0.000001 1.009505e-07 \n","1 Img-4435 1.714287e-03 5.230980e-07 1.888318e-06 0.000004 1.981154e-05 \n","2 Img-3265 1.669903e-05 2.376876e-05 5.170976e-05 0.000016 9.971881e-01 \n","3 Img-2502 3.286192e-04 1.710425e-03 9.071530e-06 0.000017 1.314390e-04 \n","4 Img-5845 7.917402e-05 1.728868e-05 1.186067e-04 0.000031 1.716332e-05 \n","\n"," chihuahua chimpanzee collie dalmatian ... \\\n","0 2.179231e-07 6.606081e-08 1.927896e-04 3.451408e-07 ... \n","1 4.183834e-07 1.010958e-06 3.067886e-07 3.624005e-06 ... \n","2 1.246746e-06 1.222767e-05 1.217500e-06 2.189813e-06 ... \n","3 5.754872e-06 2.080876e-06 8.450975e-07 3.728858e-06 ... \n","4 7.321220e-06 6.668857e-06 1.710979e-05 4.577196e-05 ... \n","\n"," raccoon rat rhinoceros seal siamese+cat \\\n","0 3.039962e-07 2.646936e-08 1.138957e-07 2.144957e-08 7.391552e-07 \n","1 1.470643e-05 3.828263e-06 9.975151e-01 8.201774e-06 8.520691e-07 \n","2 7.326244e-06 3.169375e-06 1.315738e-04 1.736059e-05 8.714651e-06 \n","3 2.356798e-06 2.367558e-05 9.970737e-01 8.674498e-06 5.989785e-06 \n","4 2.145957e-06 7.412130e-04 3.152601e-06 9.907900e-01 1.174130e-04 \n","\n"," spider+monkey squirrel walrus weasel wolf \n","0 6.125757e-08 1.621851e-06 0.000002 2.338239e-06 0.000019 \n","1 2.560058e-06 8.819440e-07 0.000001 1.416625e-07 0.000001 \n","2 2.145174e-05 1.025993e-05 0.000019 5.097419e-06 0.000002 \n","3 5.226643e-06 1.977831e-05 0.000051 8.205399e-07 0.000002 \n","4 1.349383e-05 3.716028e-04 0.003146 3.120525e-05 0.000007 \n","\n","[5 rows x 31 columns]"]},"metadata":{"tags":[]},"execution_count":102}]},{"metadata":{"id":"edxN3ZZjus8e","colab_type":"code","colab":{}},"cell_type":"code","source":["#make csv and zip it \n","SUBM = f'{PATH}sub/' \n","os.makedirs(SUBM, exist_ok=True) \n","df.to_csv(f'{SUBM}subm4.gz', compression='gzip', index=False)"],"execution_count":0,"outputs":[]},{"metadata":{"id":"hDm3r8dQvZJO","colab_type":"code","outputId":"95a6a9ec-954a-4f25-a9fc-596f577c270b","executionInfo":{"status":"ok","timestamp":1529008391072,"user_tz":-120,"elapsed":2131,"user":{"displayName":"Ahmed Mohamed","photoUrl":"//lh4.googleusercontent.com/-saP9k9xgYEs/AAAAAAAAAAI/AAAAAAAAACI/MLe6QIUA344/s50-c-k-no/photo.jpg","userId":"100438054878480961323"}},"colab":{"base_uri":"https://localhost:8080/","height":34}},"cell_type":"code","source":["FileLink(f'{SUBM}subm4.gz') # download file"],"execution_count":0,"outputs":[{"output_type":"execute_result","data":{"text/html":["/content/clouderizer/fast.ai/data/sub/subm.gz
"],"text/plain":["/content/clouderizer/fast.ai/data/sub/subm.gz"]},"metadata":{"tags":[]},"execution_count":104}]},{"metadata":{"id":"zpE5v4C3jNSC","colab_type":"text"},"cell_type":"markdown","source":["## Download data to pc "]},{"metadata":{"id":"LyGVEg3-rBJ2","colab_type":"code","colab":{}},"cell_type":"code","source":["from google.colab import files\n","files.download(\"/content/clouderizer/fast.ai/data/sub/subm10.gz\")"],"execution_count":0,"outputs":[]}]}
--------------------------------------------------------------------------------
/Identify_the_Animal_novalid_colab.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "Identify the Animal_novalid_colab_GitHub.ipynb",
7 | "version": "0.3.2",
8 | "provenance": [],
9 | "collapsed_sections": [
10 | "Txu04YOgvh6i",
11 | "U4qraUZlsXyW",
12 | "ENgzcUSmsuZ4",
13 | "gTgv7aadt6Qq",
14 | "AGnx1_CHuMJM",
15 | "ZxUvWWxzx1dm",
16 | "vSZ858IC0h6e",
17 | "1R8tl600x-e8",
18 | "bAxPFHOGU9ZG",
19 | "20-bDejgz7YM",
20 | "TQTPjt0chHTE",
21 | "WHOZHGOq0GtW",
22 | "nN4FgKoHqa9c",
23 | "5NHaPMDJWN2q",
24 | "T6_Z5fgYFSoA",
25 | "9xJ-UIy8DxeS"
26 | ]
27 | },
28 | "kernelspec": {
29 | "display_name": "Python 3",
30 | "language": "python",
31 | "name": "python3"
32 | },
33 | "accelerator": "GPU"
34 | },
35 | "cells": [
36 | {
37 | "metadata": {
38 | "id": "Txu04YOgvh6i",
39 | "colab_type": "text"
40 | },
41 | "cell_type": "markdown",
42 | "source": [
43 | "# Prepareing notebook"
44 | ]
45 | },
46 | {
47 | "metadata": {
48 | "id": "U4qraUZlsXyW",
49 | "colab_type": "text"
50 | },
51 | "cell_type": "markdown",
52 | "source": [
53 | "## Installing Fast.ai through clouderizer "
54 | ]
55 | },
56 | {
57 | "metadata": {
58 | "id": "3UpopmdXdPuu",
59 | "colab_type": "code",
60 | "colab": {}
61 | },
62 | "cell_type": "code",
63 | "source": [
64 | "!wget -NS --content-disposition \"https://console.clouderizer.com/givemeinitsh/hR1mde3W\" && bash ./clouderizer_init.sh"
65 | ],
66 | "execution_count": 0,
67 | "outputs": []
68 | },
69 | {
70 | "metadata": {
71 | "id": "ENgzcUSmsuZ4",
72 | "colab_type": "text"
73 | },
74 | "cell_type": "markdown",
75 | "source": [
76 | "## instaling libraries for plotting images "
77 | ]
78 | },
79 | {
80 | "metadata": {
81 | "id": "KNQ3KOaptanG",
82 | "colab_type": "code",
83 | "colab": {}
84 | },
85 | "cell_type": "code",
86 | "source": [
87 | "!pip install Pillow==4.0.0\n",
88 | "!pip install PIL\n",
89 | "!pip install image"
90 | ],
91 | "execution_count": 0,
92 | "outputs": []
93 | },
94 | {
95 | "metadata": {
96 | "id": "gTgv7aadt6Qq",
97 | "colab_type": "text"
98 | },
99 | "cell_type": "markdown",
100 | "source": [
101 | "#Getting the data "
102 | ]
103 | },
104 | {
105 | "metadata": {
106 | "id": "AGnx1_CHuMJM",
107 | "colab_type": "text"
108 | },
109 | "cell_type": "markdown",
110 | "source": [
111 | "## Downloading from internet"
112 | ]
113 | },
114 | {
115 | "metadata": {
116 | "id": "KU0yBYDPRoHN",
117 | "colab_type": "code",
118 | "colab": {}
119 | },
120 | "cell_type": "code",
121 | "source": [
122 | "!apt-get install p7zip-full"
123 | ],
124 | "execution_count": 0,
125 | "outputs": []
126 | },
127 | {
128 | "metadata": {
129 | "id": "80GJzc3xJb1l",
130 | "colab_type": "code",
131 | "colab": {}
132 | },
133 | "cell_type": "code",
134 | "source": [
135 | "!wget https://s3-ap-southeast-1.amazonaws.com/he-public-data/DL%23+Beginner.zip"
136 | ],
137 | "execution_count": 0,
138 | "outputs": []
139 | },
140 | {
141 | "metadata": {
142 | "id": "5BFwhL49RDJY",
143 | "colab_type": "code",
144 | "colab": {}
145 | },
146 | "cell_type": "code",
147 | "source": [
148 | "mv 'DL#+Beginner.zip' 'DLBeginner.zip'"
149 | ],
150 | "execution_count": 0,
151 | "outputs": []
152 | },
153 | {
154 | "metadata": {
155 | "id": "RE8dgFYdRZ9i",
156 | "colab_type": "code",
157 | "outputId": "28519ab9-c88a-48c1-857d-d8930f752e7c",
158 | "colab": {
159 | "base_uri": "https://localhost:8080/",
160 | "height": 34
161 | }
162 | },
163 | "cell_type": "code",
164 | "source": [
165 | "rm -r DL#+Beginner.zip.1"
166 | ],
167 | "execution_count": 0,
168 | "outputs": [
169 | {
170 | "output_type": "stream",
171 | "text": [
172 | "rm: cannot remove 'DL#+Beginner.zip.1': No such file or directory\r\n"
173 | ],
174 | "name": "stdout"
175 | }
176 | ]
177 | },
178 | {
179 | "metadata": {
180 | "id": "6ypLfSKdRRqM",
181 | "colab_type": "code",
182 | "outputId": "91d67115-e96b-4d59-e139-9a62a1ef7e78",
183 | "colab": {
184 | "base_uri": "https://localhost:8080/",
185 | "height": 102
186 | }
187 | },
188 | "cell_type": "code",
189 | "source": [
190 | "ls{'/content/'}"
191 | ],
192 | "execution_count": 0,
193 | "outputs": [
194 | {
195 | "output_type": "stream",
196 | "text": [
197 | "\u001b[0m\u001b[01;34mclouderizer\u001b[0m/ DLBeginner.zip updatestatus.2\r\n",
198 | "clouderizer_init.sh install_clouderizer_service.sh updatestatus.3\r\n",
199 | "clouderizer.jar temp.sh updatestatus.4\r\n",
200 | "clouderizer.service updatestatus updatestatus.5\r\n",
201 | "\u001b[01;34mdatalab\u001b[0m/ updatestatus.1 updatestatus.6\r\n"
202 | ],
203 | "name": "stdout"
204 | }
205 | ]
206 | },
207 | {
208 | "metadata": {
209 | "id": "LFBy5EcyRuTC",
210 | "colab_type": "code",
211 | "colab": {}
212 | },
213 | "cell_type": "code",
214 | "source": [
215 | "!7z x DLBeginner.zip -o/content/clouderizer/fast.ai/data/"
216 | ],
217 | "execution_count": 0,
218 | "outputs": []
219 | },
220 | {
221 | "metadata": {
222 | "id": "d9uVtqBH6buN",
223 | "colab_type": "code",
224 | "outputId": "95b31cc4-ab51-449e-b03a-fe4e8153bbd8",
225 | "colab": {
226 | "base_uri": "https://localhost:8080/",
227 | "height": 34
228 | }
229 | },
230 | "cell_type": "code",
231 | "source": [
232 | "ls{'/content/clouderizer/fast.ai/data/\"DL# Beginner\"/'}"
233 | ],
234 | "execution_count": 0,
235 | "outputs": [
236 | {
237 | "output_type": "stream",
238 | "text": [
239 | "meta-data.zip test.zip train.zip\r\n"
240 | ],
241 | "name": "stdout"
242 | }
243 | ]
244 | },
245 | {
246 | "metadata": {
247 | "id": "zj866dOOdkV4",
248 | "colab_type": "code",
249 | "colab": {}
250 | },
251 | "cell_type": "code",
252 | "source": [
253 | "rm -r /content/DLBeginner.zip"
254 | ],
255 | "execution_count": 0,
256 | "outputs": []
257 | },
258 | {
259 | "metadata": {
260 | "id": "3yooeypnQkc6",
261 | "colab_type": "code",
262 | "colab": {}
263 | },
264 | "cell_type": "code",
265 | "source": [
266 | "!7z x /content/clouderizer/fast.ai/data/\"DL# Beginner\"/train.zip -o/content/clouderizer/fast.ai/data/"
267 | ],
268 | "execution_count": 0,
269 | "outputs": []
270 | },
271 | {
272 | "metadata": {
273 | "id": "haRmD7iVSBIT",
274 | "colab_type": "code",
275 | "colab": {}
276 | },
277 | "cell_type": "code",
278 | "source": [
279 | "!7z x /content/clouderizer/fast.ai/data/\"DL# Beginner\"/test.zip -o/content/clouderizer/fast.ai/data/"
280 | ],
281 | "execution_count": 0,
282 | "outputs": []
283 | },
284 | {
285 | "metadata": {
286 | "id": "YixWMyYeSGAK",
287 | "colab_type": "code",
288 | "colab": {}
289 | },
290 | "cell_type": "code",
291 | "source": [
292 | "!7z x /content/clouderizer/fast.ai/data/\"DL# Beginner\"/meta-data.zip -o/content/clouderizer/fast.ai/data/"
293 | ],
294 | "execution_count": 0,
295 | "outputs": []
296 | },
297 | {
298 | "metadata": {
299 | "id": "PwJI_pelR6YO",
300 | "colab_type": "code",
301 | "outputId": "4716bb3b-dc2c-4c06-9860-f6aac2cdf456",
302 | "colab": {
303 | "base_uri": "https://localhost:8080/",
304 | "height": 34
305 | }
306 | },
307 | "cell_type": "code",
308 | "source": [
309 | "ls{'/content/clouderizer/fast.ai/data/'}"
310 | ],
311 | "execution_count": 0,
312 | "outputs": [
313 | {
314 | "output_type": "stream",
315 | "text": [
316 | "\u001b[0m\u001b[01;34mDL# Beginner\u001b[0m/ dogscats.zip \u001b[01;34mmeta-data\u001b[0m/ \u001b[01;34mtest\u001b[0m/ \u001b[01;34mtrain\u001b[0m/\r\n"
317 | ],
318 | "name": "stdout"
319 | }
320 | ]
321 | },
322 | {
323 | "metadata": {
324 | "id": "ELqVh-YYSmn2",
325 | "colab_type": "code",
326 | "colab": {}
327 | },
328 | "cell_type": "code",
329 | "source": [
330 | "!cp /content/clouderizer/fast.ai/data/meta-data/sample_submission.csv /content/clouderizer/fast.ai/data/\n",
331 | "!cp /content/clouderizer/fast.ai/data/meta-data/test.csv /content/clouderizer/fast.ai/data/\n",
332 | "!cp /content/clouderizer/fast.ai/data/meta-data/train.csv /content/clouderizer/fast.ai/data/\n"
333 | ],
334 | "execution_count": 0,
335 | "outputs": []
336 | },
337 | {
338 | "metadata": {
339 | "id": "mrOxO-huTC6_",
340 | "colab_type": "code",
341 | "colab": {}
342 | },
343 | "cell_type": "code",
344 | "source": [
345 | "!rm -r /content/clouderizer/fast.ai/data/\"DL# Beginner\"/\n",
346 | "!rm -r /content/clouderizer/fast.ai/data/meta-data/"
347 | ],
348 | "execution_count": 0,
349 | "outputs": []
350 | },
351 | {
352 | "metadata": {
353 | "id": "29u7EGRbTHje",
354 | "colab_type": "code",
355 | "outputId": "582caff5-6207-4951-d428-deb66487664b",
356 | "colab": {
357 | "base_uri": "https://localhost:8080/",
358 | "height": 34
359 | }
360 | },
361 | "cell_type": "code",
362 | "source": [
363 | "ls{'/content/clouderizer/fast.ai/data/'}"
364 | ],
365 | "execution_count": 0,
366 | "outputs": [
367 | {
368 | "output_type": "stream",
369 | "text": [
370 | "dogscats.zip sample_submission.csv \u001b[0m\u001b[01;34mtest\u001b[0m/ test.csv \u001b[01;34mtrain\u001b[0m/ train.csv\r\n"
371 | ],
372 | "name": "stdout"
373 | }
374 | ]
375 | },
376 | {
377 | "metadata": {
378 | "id": "Xpo8v15vfv3p",
379 | "colab_type": "code",
380 | "outputId": "b7c336e0-2383-4ead-c63e-b698568f4d9c",
381 | "colab": {
382 | "base_uri": "https://localhost:8080/",
383 | "height": 34
384 | }
385 | },
386 | "cell_type": "code",
387 | "source": [
388 | "!rm -r /content/clouderizer/fast.ai/data/dogscats.zip\n",
389 | "!rm -r /content/clouderizer/fast.ai/data/dogscats"
390 | ],
391 | "execution_count": 0,
392 | "outputs": [
393 | {
394 | "output_type": "stream",
395 | "text": [
396 | "rm: cannot remove '/content/clouderizer/fast.ai/data/dogscats': No such file or directory\r\n"
397 | ],
398 | "name": "stdout"
399 | }
400 | ]
401 | },
402 | {
403 | "metadata": {
404 | "id": "DG9F6-1IJP8u",
405 | "colab_type": "code",
406 | "outputId": "21c049ad-56c9-4123-a9a8-9f583f75ecda",
407 | "colab": {
408 | "base_uri": "https://localhost:8080/",
409 | "height": 34
410 | }
411 | },
412 | "cell_type": "code",
413 | "source": [
414 | "ls{'/content/clouderizer/fast.ai/data/'}"
415 | ],
416 | "execution_count": 0,
417 | "outputs": [
418 | {
419 | "output_type": "stream",
420 | "text": [
421 | "sample_submission.csv \u001b[0m\u001b[01;34mtest\u001b[0m/ test.csv \u001b[01;34mtrain\u001b[0m/ train.csv\r\n"
422 | ],
423 | "name": "stdout"
424 | }
425 | ]
426 | },
427 | {
428 | "metadata": {
429 | "id": "ZxUvWWxzx1dm",
430 | "colab_type": "text"
431 | },
432 | "cell_type": "markdown",
433 | "source": [
434 | "# Problems & Fix"
435 | ]
436 | },
437 | {
438 | "metadata": {
439 | "id": "vSZ858IC0h6e",
440 | "colab_type": "text"
441 | },
442 | "cell_type": "markdown",
443 | "source": [
444 | "## Weights\n",
445 | "\n",
446 | "* Cannot find resnext_101_64x4d.pth\n",
447 | "\n",
448 | "\n"
449 | ]
450 | },
451 | {
452 | "metadata": {
453 | "id": "d2q0YKI404rc",
454 | "colab_type": "code",
455 | "outputId": "1c4fa158-df40-45ab-810a-0295c5362589",
456 | "colab": {
457 | "base_uri": "https://localhost:8080/",
458 | "height": 34
459 | }
460 | },
461 | "cell_type": "code",
462 | "source": [
463 | "!ls {\"/usr/local/lib/python3.6/dist-packages/fastai/weights/\"}"
464 | ],
465 | "execution_count": 0,
466 | "outputs": [
467 | {
468 | "output_type": "stream",
469 | "text": [
470 | "resnext_101_64x4d.pth\r\n"
471 | ],
472 | "name": "stdout"
473 | }
474 | ]
475 | },
476 | {
477 | "metadata": {
478 | "id": "idq2Q9LC38OQ",
479 | "colab_type": "code",
480 | "outputId": "3f292cfe-8eff-4e71-edd1-13a000cde497",
481 | "colab": {
482 | "base_uri": "https://localhost:8080/",
483 | "height": 68
484 | }
485 | },
486 | "cell_type": "code",
487 | "source": [
488 | "!ls {\"/content/clouderizer/fast.ai/fastai/courses/dl1/fastai/weights\"}"
489 | ],
490 | "execution_count": 0,
491 | "outputs": [
492 | {
493 | "output_type": "stream",
494 | "text": [
495 | "inceptionresnetv2-d579a627.pth\tresnext_101_64x4d-Copy1.py wrn_50_2f.pth\r\n",
496 | "inceptionv4-97ef9c30.pth\tresnext_101_64x4d.pth\r\n",
497 | "resnext_101_32x4d.pth\t\tresnext_50_32x4d.pth\r\n"
498 | ],
499 | "name": "stdout"
500 | }
501 | ]
502 | },
503 | {
504 | "metadata": {
505 | "id": "9LoaTXTs1F3M",
506 | "colab_type": "code",
507 | "colab": {}
508 | },
509 | "cell_type": "code",
510 | "source": [
511 | "!mkdir -p /usr/local/lib/python3.6/dist-packages/fastai/weights/\n",
512 | "#!( cd /content/clouderizer/fast.ai/fastai/courses/dl1/fastai/weights && tar cf - . ) | (cd /usr/local/lib/python3.6/dist-packages/fastai/weights/ && tar xvpf - )\n",
513 | "! cp /content/clouderizer/fast.ai/fastai/courses/dl1/fastai/weights/resnext_101_64x4d.pth /usr/local/lib/python3.6/dist-packages/fastai/weights"
514 | ],
515 | "execution_count": 0,
516 | "outputs": []
517 | },
518 | {
519 | "metadata": {
520 | "id": "V4C3q-KbqJuU",
521 | "colab_type": "code",
522 | "colab": {}
523 | },
524 | "cell_type": "code",
525 | "source": [
526 | "#!mkdir -p /content/clouderizer/fast.ai/fastai/courses/dl1/fastai/weights/"
527 | ],
528 | "execution_count": 0,
529 | "outputs": []
530 | },
531 | {
532 | "metadata": {
533 | "id": "5_EDbUxV4cuW",
534 | "colab_type": "code",
535 | "outputId": "79623206-96ce-4420-88c0-b92670d5dbeb",
536 | "colab": {
537 | "base_uri": "https://localhost:8080/",
538 | "height": 765
539 | }
540 | },
541 | "cell_type": "code",
542 | "source": [
543 | "!wget http://files.fast.ai/models/weights.tgz -d\n",
544 | "!tar -xf /content/weights.tgz "
545 | ],
546 | "execution_count": 0,
547 | "outputs": [
548 | {
549 | "output_type": "stream",
550 | "text": [
551 | "DEBUG output created by Wget 1.19.1 on linux-gnu.\r\n",
552 | "\r\n",
553 | "Reading HSTS entries from /content/.wget-hsts\r\n",
554 | "URI encoding = ‘UTF-8’\r\n",
555 | "Converted file name 'weights.tgz' (UTF-8) -> 'weights.tgz' (UTF-8)\r\n",
556 | "--2018-06-20 08:28:32-- http://files.fast.ai/models/weights.tgz\r\n",
557 | "Resolving files.fast.ai (files.fast.ai)... 67.205.15.147\r\n",
558 | "Caching files.fast.ai => 67.205.15.147\n",
559 | "Connecting to files.fast.ai (files.fast.ai)|67.205.15.147|:80... connected.\n",
560 | "Created socket 3.\n",
561 | "Releasing 0x0000558626764380 (new refcount 1).\n",
562 | "\n",
563 | "---request begin---\n",
564 | "GET /models/weights.tgz HTTP/1.1\n",
565 | "User-Agent: Wget/1.19.1 (linux-gnu)\n",
566 | "Accept: */*\n",
567 | "Accept-Encoding: identity\n",
568 | "Host: files.fast.ai\n",
569 | "Connection: Keep-Alive\n",
570 | "\n",
571 | "---request end---\n",
572 | "HTTP request sent, awaiting response... \n",
573 | "---response begin---\n",
574 | "HTTP/1.1 200 OK\n",
575 | "Date: Wed, 20 Jun 2018 08:28:32 GMT\n",
576 | "Server: Apache\n",
577 | "Last-Modified: Sat, 04 Nov 2017 13:04:50 GMT\n",
578 | "ETag: \"47408776-55d27ddd9cac6\"\n",
579 | "Accept-Ranges: bytes\n",
580 | "Content-Length: 1195411318\n",
581 | "Keep-Alive: timeout=2, max=100\n",
582 | "Connection: Keep-Alive\n",
583 | "Content-Type: text/plain\n",
584 | "\n",
585 | "---response end---\n",
586 | "200 OK\n",
587 | "Registered socket 3 for persistent reuse.\n",
588 | "Length: 1195411318 (1.1G) [text/plain]\n",
589 | "Saving to: ‘weights.tgz’\n",
590 | "\n",
591 | "weights.tgz 59%[==========> ] 672.67M 43.0MB/s eta 12s "
592 | ],
593 | "name": "stdout"
594 | },
595 | {
596 | "output_type": "stream",
597 | "text": [
598 | "weights.tgz 100%[===================>] 1.11G 43.0MB/s in 27s \n",
599 | "\n",
600 | "2018-06-20 08:28:59 (42.3 MB/s) - ‘weights.tgz’ saved [1195411318/1195411318]\n",
601 | "\n"
602 | ],
603 | "name": "stdout"
604 | }
605 | ]
606 | },
607 | {
608 | "metadata": {
609 | "id": "3vMFY0mBsgw4",
610 | "colab_type": "code",
611 | "colab": {}
612 | },
613 | "cell_type": "code",
614 | "source": [
615 | "mv /content/weights/resnext_101_64x4d.pth /usr/local/lib/python3.6/dist-packages/fastai/weights/"
616 | ],
617 | "execution_count": 0,
618 | "outputs": []
619 | },
620 | {
621 | "metadata": {
622 | "id": "hdlzGUTqsngE",
623 | "colab_type": "code",
624 | "outputId": "e8f984d4-f63e-4a5e-aa78-8f8262c5cee6",
625 | "colab": {
626 | "base_uri": "https://localhost:8080/",
627 | "height": 34
628 | }
629 | },
630 | "cell_type": "code",
631 | "source": [
632 | "!ls {\"/usr/local/lib/python3.6/dist-packages/fastai/weights/\"}"
633 | ],
634 | "execution_count": 0,
635 | "outputs": [
636 | {
637 | "output_type": "stream",
638 | "text": [
639 | "resnext_101_64x4d.pth\r\n"
640 | ],
641 | "name": "stdout"
642 | }
643 | ]
644 | },
645 | {
646 | "metadata": {
647 | "id": "1R8tl600x-e8",
648 | "colab_type": "text"
649 | },
650 | "cell_type": "markdown",
651 | "source": [
652 | "## TTA\n",
653 | "\n",
654 | "* AttributeError: ‘bool’ object has no attribute ‘mean’\" error in lesson1 Dogbreed example"
655 | ]
656 | },
657 | {
658 | "metadata": {
659 | "id": "Jx6iJbAPx0mw",
660 | "colab_type": "code",
661 | "outputId": "58a5287c-b4e4-4d6c-c9cc-5fc8c606d9ef",
662 | "colab": {
663 | "base_uri": "https://localhost:8080/",
664 | "height": 394
665 | }
666 | },
667 | "cell_type": "code",
668 | "source": [
669 | "!rm -r /usr/local/lib/python3.6/dist-packages/fastai/metrics.py\n",
670 | "#!ls {\"/usr/local/lib/python3.6/dist-packages/fastai/\"}\n",
671 | "!wget https://github.com/fastai/fastai/blob/f94fe9b08da60cf76b805ce9926a87b91b5eae24/fastai/metrics.py\n",
672 | "#!ls {\"/content/\"}\n",
673 | "!mv /content/metrics.py /usr/local/lib/python3.6/dist-packages/fastai/\n",
674 | "!ls {\"/usr/local/lib/python3.6/dist-packages/fastai/\"}"
675 | ],
676 | "execution_count": 0,
677 | "outputs": [
678 | {
679 | "output_type": "stream",
680 | "text": [
681 | "--2018-06-08 16:05:06-- https://github.com/fastai/fastai/blob/f94fe9b08da60cf76b805ce9926a87b91b5eae24/fastai/metrics.py\n",
682 | "Resolving github.com (github.com)... 192.30.253.112, 192.30.253.113\n",
683 | "Connecting to github.com (github.com)|192.30.253.112|:443... connected.\n",
684 | "HTTP request sent, awaiting response... 200 OK\n",
685 | "Length: unspecified [text/html]\n",
686 | "Saving to: ‘metrics.py’\n",
687 | "\n",
688 | "metrics.py [ <=> ] 51.18K 314KB/s in 0.2s \n",
689 | "\n",
690 | "2018-06-08 16:05:07 (314 KB/s) - ‘metrics.py’ saved [52409]\n",
691 | "\n",
692 | "adaptive_softmax.py initializers.py\t metrics.py\tsgdr.py\n",
693 | "column_data.py\t __init__.py\t model.py\tstructured.py\n",
694 | "conv_learner.py io.py\t\t models\tswa.py\n",
695 | "core.py\t\t layer_optimizer.py nlp.py\ttext.py\n",
696 | "dataloader.py\t layers.py\t\t plots.py\ttorch_imports.py\n",
697 | "dataset.py\t learner.py\t\t __pycache__\ttransforms_pil.py\n",
698 | "executors.py\t lm_rnn.py\t\t rnn_reg.py\ttransforms.py\n",
699 | "fp16.py\t\t losses.py\t\t rnn_train.py\tutils.py\n",
700 | "imports.py\t lsuv_initializer.py set_spawn.py\tweights\n"
701 | ],
702 | "name": "stdout"
703 | }
704 | ]
705 | },
706 | {
707 | "metadata": {
708 | "id": "5OrQwfgfxbYw",
709 | "colab_type": "text"
710 | },
711 | "cell_type": "markdown",
712 | "source": [
713 | "# CODE"
714 | ]
715 | },
716 | {
717 | "metadata": {
718 | "id": "bAxPFHOGU9ZG",
719 | "colab_type": "text"
720 | },
721 | "cell_type": "markdown",
722 | "source": [
723 | "##Pre Training"
724 | ]
725 | },
726 | {
727 | "metadata": {
728 | "id": "5QmH83QDc_e8",
729 | "colab_type": "code",
730 | "colab": {}
731 | },
732 | "cell_type": "code",
733 | "source": [
734 | "# Put these at the top of every notebook, to get automatic reloading and inline plotting\n",
735 | "%reload_ext autoreload\n",
736 | "%autoreload 2\n",
737 | "%matplotlib inline"
738 | ],
739 | "execution_count": 0,
740 | "outputs": []
741 | },
742 | {
743 | "metadata": {
744 | "id": "pvcjwrBqc_fG",
745 | "colab_type": "code",
746 | "colab": {}
747 | },
748 | "cell_type": "code",
749 | "source": [
750 | "\n",
751 | "from fastai.imports import *\n",
752 | "from fastai.transforms import *\n",
753 | "from fastai.conv_learner import *\n",
754 | "from fastai.model import *\n",
755 | "from fastai.dataset import *\n",
756 | "from fastai.sgdr import *\n",
757 | "from fastai.plots import *"
758 | ],
759 | "execution_count": 0,
760 | "outputs": []
761 | },
762 | {
763 | "metadata": {
764 | "id": "4Y89GZRhc_fQ",
765 | "colab_type": "code",
766 | "outputId": "20cb0201-506e-4cb5-815e-fee22065fb8e",
767 | "colab": {
768 | "base_uri": "https://localhost:8080/",
769 | "height": 34
770 | }
771 | },
772 | "cell_type": "code",
773 | "source": [
774 | "torch.cuda.is_available()"
775 | ],
776 | "execution_count": 0,
777 | "outputs": [
778 | {
779 | "output_type": "execute_result",
780 | "data": {
781 | "text/plain": [
782 | "True"
783 | ]
784 | },
785 | "metadata": {
786 | "tags": []
787 | },
788 | "execution_count": 3
789 | }
790 | ]
791 | },
792 | {
793 | "metadata": {
794 | "id": "qm0BvUEHc_fk",
795 | "colab_type": "code",
796 | "outputId": "8a9d2a9c-d63c-4037-95e8-c23398aa2418",
797 | "colab": {
798 | "base_uri": "https://localhost:8080/",
799 | "height": 34
800 | }
801 | },
802 | "cell_type": "code",
803 | "source": [
804 | "torch.backends.cudnn.enabled"
805 | ],
806 | "execution_count": 0,
807 | "outputs": [
808 | {
809 | "output_type": "execute_result",
810 | "data": {
811 | "text/plain": [
812 | "True"
813 | ]
814 | },
815 | "metadata": {
816 | "tags": []
817 | },
818 | "execution_count": 4
819 | }
820 | ]
821 | },
822 | {
823 | "metadata": {
824 | "id": "BfHQYdSbISkA",
825 | "colab_type": "code",
826 | "colab": {}
827 | },
828 | "cell_type": "code",
829 | "source": [
830 | "PATH = \"/content/clouderizer/fast.ai/data/\"\n",
831 | "arch = resnext101_64"
832 | ],
833 | "execution_count": 0,
834 | "outputs": []
835 | },
836 | {
837 | "metadata": {
838 | "id": "E6I24tKWc_f-",
839 | "colab_type": "code",
840 | "colab": {}
841 | },
842 | "cell_type": "code",
843 | "source": [
844 | "sz=224"
845 | ],
846 | "execution_count": 0,
847 | "outputs": []
848 | },
849 | {
850 | "metadata": {
851 | "id": "UjKp0FlOV1xE",
852 | "colab_type": "code",
853 | "colab": {}
854 | },
855 | "cell_type": "code",
856 | "source": [
857 | "bs=16 #batch size"
858 | ],
859 | "execution_count": 0,
860 | "outputs": []
861 | },
862 | {
863 | "metadata": {
864 | "id": "bRw-LFyPmENU",
865 | "colab_type": "code",
866 | "outputId": "97793c8b-758f-410a-d974-6d01c0a4ae31",
867 | "colab": {
868 | "base_uri": "https://localhost:8080/",
869 | "height": 34
870 | }
871 | },
872 | "cell_type": "code",
873 | "source": [
874 | "!ls {\"/content/clouderizer/fast.ai/data/\"}"
875 | ],
876 | "execution_count": 0,
877 | "outputs": [
878 | {
879 | "output_type": "stream",
880 | "text": [
881 | "sample_submission.csv test test.csv train train.csv\r\n"
882 | ],
883 | "name": "stdout"
884 | }
885 | ]
886 | },
887 | {
888 | "metadata": {
889 | "id": "MpdcaVI5j6YF",
890 | "colab_type": "code",
891 | "colab": {}
892 | },
893 | "cell_type": "code",
894 | "source": [
895 | "#!rm -r /content/clouderizer/fast.ai/data/tmp"
896 | ],
897 | "execution_count": 0,
898 | "outputs": []
899 | },
900 | {
901 | "metadata": {
902 | "id": "-lj7h5HfyU_-",
903 | "colab_type": "text"
904 | },
905 | "cell_type": "markdown",
906 | "source": [
907 | "###Making validation set"
908 | ]
909 | },
910 | {
911 | "metadata": {
912 | "id": "2s5KgC_Dc_gE",
913 | "colab_type": "code",
914 | "colab": {}
915 | },
916 | "cell_type": "code",
917 | "source": [
918 | "label_csv = f'{PATH}train.csv'\n",
919 | "n = len(list(open(label_csv)))-1 #number of trainig examples = # labels"
920 | ],
921 | "execution_count": 0,
922 | "outputs": []
923 | },
924 | {
925 | "metadata": {
926 | "id": "HJfCUDInXSSb",
927 | "colab_type": "code",
928 | "colab": {}
929 | },
930 | "cell_type": "code",
931 | "source": [
932 | "val_idxs = get_cv_idxs(n , val_pct=1e-4)"
933 | ],
934 | "execution_count": 0,
935 | "outputs": []
936 | },
937 | {
938 | "metadata": {
939 | "id": "4YhtHbCdc_gQ",
940 | "colab_type": "code",
941 | "outputId": "d98332ef-0385-47b9-8110-bbe3786df4f2",
942 | "colab": {
943 | "base_uri": "https://localhost:8080/",
944 | "height": 34
945 | }
946 | },
947 | "cell_type": "code",
948 | "source": [
949 | "n"
950 | ],
951 | "execution_count": 0,
952 | "outputs": [
953 | {
954 | "output_type": "execute_result",
955 | "data": {
956 | "text/plain": [
957 | "13000"
958 | ]
959 | },
960 | "metadata": {
961 | "tags": []
962 | },
963 | "execution_count": 12
964 | }
965 | ]
966 | },
967 | {
968 | "metadata": {
969 | "id": "EaHTA9AHc_gw",
970 | "colab_type": "code",
971 | "outputId": "efec3a56-3a1e-44fc-c49c-7e9f2ddc3a0a",
972 | "colab": {
973 | "base_uri": "https://localhost:8080/",
974 | "height": 34
975 | }
976 | },
977 | "cell_type": "code",
978 | "source": [
979 | "len(val_idxs)"
980 | ],
981 | "execution_count": 0,
982 | "outputs": [
983 | {
984 | "output_type": "execute_result",
985 | "data": {
986 | "text/plain": [
987 | "1"
988 | ]
989 | },
990 | "metadata": {
991 | "tags": []
992 | },
993 | "execution_count": 13
994 | }
995 | ]
996 | },
997 | {
998 | "metadata": {
999 | "id": "y1aEH43wc_hO",
1000 | "colab_type": "code",
1001 | "outputId": "6886567e-2bdd-474b-8ed0-87bfce2c3fcb",
1002 | "colab": {
1003 | "base_uri": "https://localhost:8080/",
1004 | "height": 34
1005 | }
1006 | },
1007 | "cell_type": "code",
1008 | "source": [
1009 | "val_idxs"
1010 | ],
1011 | "execution_count": 0,
1012 | "outputs": [
1013 | {
1014 | "output_type": "execute_result",
1015 | "data": {
1016 | "text/plain": [
1017 | "array([3615])"
1018 | ]
1019 | },
1020 | "metadata": {
1021 | "tags": []
1022 | },
1023 | "execution_count": 14
1024 | }
1025 | ]
1026 | },
1027 | {
1028 | "metadata": {
1029 | "id": "20-bDejgz7YM",
1030 | "colab_type": "text"
1031 | },
1032 | "cell_type": "markdown",
1033 | "source": [
1034 | "## Looking to the data "
1035 | ]
1036 | },
1037 | {
1038 | "metadata": {
1039 | "id": "FCr9tD7Dc_hc",
1040 | "colab_type": "code",
1041 | "outputId": "d7e42783-8715-4b81-94ad-7c8a536a7440",
1042 | "colab": {
1043 | "base_uri": "https://localhost:8080/",
1044 | "height": 204
1045 | }
1046 | },
1047 | "cell_type": "code",
1048 | "source": [
1049 | "label_df = pd.read_csv(label_csv)\n",
1050 | "label_df.head()"
1051 | ],
1052 | "execution_count": 0,
1053 | "outputs": [
1054 | {
1055 | "output_type": "execute_result",
1056 | "data": {
1057 | "text/html": [
1058 | "\n",
1059 | "\n",
1072 | "
\n",
1073 | " \n",
1074 | " \n",
1075 | " | \n",
1076 | " Image_id | \n",
1077 | " Animal | \n",
1078 | "
\n",
1079 | " \n",
1080 | " \n",
1081 | " \n",
1082 | " | 0 | \n",
1083 | " Img-1.jpg | \n",
1084 | " hippopotamus | \n",
1085 | "
\n",
1086 | " \n",
1087 | " | 1 | \n",
1088 | " Img-2.jpg | \n",
1089 | " squirrel | \n",
1090 | "
\n",
1091 | " \n",
1092 | " | 2 | \n",
1093 | " Img-3.jpg | \n",
1094 | " grizzly+bear | \n",
1095 | "
\n",
1096 | " \n",
1097 | " | 3 | \n",
1098 | " Img-4.jpg | \n",
1099 | " ox | \n",
1100 | "
\n",
1101 | " \n",
1102 | " | 4 | \n",
1103 | " Img-5.jpg | \n",
1104 | " german+shepherd | \n",
1105 | "
\n",
1106 | " \n",
1107 | "
\n",
1108 | "
"
1109 | ],
1110 | "text/plain": [
1111 | " Image_id Animal\n",
1112 | "0 Img-1.jpg hippopotamus\n",
1113 | "1 Img-2.jpg squirrel\n",
1114 | "2 Img-3.jpg grizzly+bear\n",
1115 | "3 Img-4.jpg ox\n",
1116 | "4 Img-5.jpg german+shepherd"
1117 | ]
1118 | },
1119 | "metadata": {
1120 | "tags": []
1121 | },
1122 | "execution_count": 87
1123 | }
1124 | ]
1125 | },
1126 | {
1127 | "metadata": {
1128 | "id": "BLLJMR3Kc_hy",
1129 | "colab_type": "code",
1130 | "outputId": "204ca88b-cd8b-4b2e-8c33-bc2ce7359b66",
1131 | "colab": {
1132 | "base_uri": "https://localhost:8080/",
1133 | "height": 1010
1134 | }
1135 | },
1136 | "cell_type": "code",
1137 | "source": [
1138 | "label_df.pivot_table(index='Animal', aggfunc=len).sort_values('Image_id', ascending=False) #group it up"
1139 | ],
1140 | "execution_count": 0,
1141 | "outputs": [
1142 | {
1143 | "output_type": "execute_result",
1144 | "data": {
1145 | "text/html": [
1146 | "\n",
1147 | "\n",
1160 | "
\n",
1161 | " \n",
1162 | " \n",
1163 | " | \n",
1164 | " Image_id | \n",
1165 | "
\n",
1166 | " \n",
1167 | " | Animal | \n",
1168 | " | \n",
1169 | "
\n",
1170 | " \n",
1171 | " \n",
1172 | " \n",
1173 | " | antelope | \n",
1174 | " 695 | \n",
1175 | "
\n",
1176 | " \n",
1177 | " | bat | \n",
1178 | " 256 | \n",
1179 | "
\n",
1180 | " \n",
1181 | " | beaver | \n",
1182 | " 133 | \n",
1183 | "
\n",
1184 | " \n",
1185 | " | bobcat | \n",
1186 | " 418 | \n",
1187 | "
\n",
1188 | " \n",
1189 | " | buffalo | \n",
1190 | " 606 | \n",
1191 | "
\n",
1192 | " \n",
1193 | " | chihuahua | \n",
1194 | " 386 | \n",
1195 | "
\n",
1196 | " \n",
1197 | " | chimpanzee | \n",
1198 | " 477 | \n",
1199 | "
\n",
1200 | " \n",
1201 | " | collie | \n",
1202 | " 680 | \n",
1203 | "
\n",
1204 | " \n",
1205 | " | dalmatian | \n",
1206 | " 359 | \n",
1207 | "
\n",
1208 | " \n",
1209 | " | german+shepherd | \n",
1210 | " 687 | \n",
1211 | "
\n",
1212 | " \n",
1213 | " | grizzly+bear | \n",
1214 | " 583 | \n",
1215 | "
\n",
1216 | " \n",
1217 | " | hippopotamus | \n",
1218 | " 464 | \n",
1219 | "
\n",
1220 | " \n",
1221 | " | horse | \n",
1222 | " 1111 | \n",
1223 | "
\n",
1224 | " \n",
1225 | " | killer+whale | \n",
1226 | " 193 | \n",
1227 | "
\n",
1228 | " \n",
1229 | " | mole | \n",
1230 | " 60 | \n",
1231 | "
\n",
1232 | " \n",
1233 | " | moose | \n",
1234 | " 476 | \n",
1235 | "
\n",
1236 | " \n",
1237 | " | mouse | \n",
1238 | " 124 | \n",
1239 | "
\n",
1240 | " \n",
1241 | " | otter | \n",
1242 | " 519 | \n",
1243 | "
\n",
1244 | " \n",
1245 | " | ox | \n",
1246 | " 501 | \n",
1247 | "
\n",
1248 | " \n",
1249 | " | persian+cat | \n",
1250 | " 491 | \n",
1251 | "
\n",
1252 | " \n",
1253 | " | raccoon | \n",
1254 | " 346 | \n",
1255 | "
\n",
1256 | " \n",
1257 | " | rat | \n",
1258 | " 220 | \n",
1259 | "
\n",
1260 | " \n",
1261 | " | rhinoceros | \n",
1262 | " 477 | \n",
1263 | "
\n",
1264 | " \n",
1265 | " | seal | \n",
1266 | " 665 | \n",
1267 | "
\n",
1268 | " \n",
1269 | " | siamese+cat | \n",
1270 | " 341 | \n",
1271 | "
\n",
1272 | " \n",
1273 | " | spider+monkey | \n",
1274 | " 189 | \n",
1275 | "
\n",
1276 | " \n",
1277 | " | squirrel | \n",
1278 | " 808 | \n",
1279 | "
\n",
1280 | " \n",
1281 | " | walrus | \n",
1282 | " 148 | \n",
1283 | "
\n",
1284 | " \n",
1285 | " | weasel | \n",
1286 | " 184 | \n",
1287 | "
\n",
1288 | " \n",
1289 | " | wolf | \n",
1290 | " 403 | \n",
1291 | "
\n",
1292 | " \n",
1293 | "
\n",
1294 | "
"
1295 | ],
1296 | "text/plain": [
1297 | " Image_id\n",
1298 | "Animal \n",
1299 | "antelope 695\n",
1300 | "bat 256\n",
1301 | "beaver 133\n",
1302 | "bobcat 418\n",
1303 | "buffalo 606\n",
1304 | "chihuahua 386\n",
1305 | "chimpanzee 477\n",
1306 | "collie 680\n",
1307 | "dalmatian 359\n",
1308 | "german+shepherd 687\n",
1309 | "grizzly+bear 583\n",
1310 | "hippopotamus 464\n",
1311 | "horse 1111\n",
1312 | "killer+whale 193\n",
1313 | "mole 60\n",
1314 | "moose 476\n",
1315 | "mouse 124\n",
1316 | "otter 519\n",
1317 | "ox 501\n",
1318 | "persian+cat 491\n",
1319 | "raccoon 346\n",
1320 | "rat 220\n",
1321 | "rhinoceros 477\n",
1322 | "seal 665\n",
1323 | "siamese+cat 341\n",
1324 | "spider+monkey 189\n",
1325 | "squirrel 808\n",
1326 | "walrus 148\n",
1327 | "weasel 184\n",
1328 | "wolf 403"
1329 | ]
1330 | },
1331 | "metadata": {
1332 | "tags": []
1333 | },
1334 | "execution_count": 124
1335 | }
1336 | ]
1337 | },
1338 | {
1339 | "metadata": {
1340 | "id": "x6vRad8vc_iA",
1341 | "colab_type": "code",
1342 | "colab": {}
1343 | },
1344 | "cell_type": "code",
1345 | "source": [
1346 | "tfms = tfms_from_model(arch, sz, aug_tfms=transforms_side_on, \n",
1347 | " max_zoom=1.1)\n",
1348 | "\n",
1349 | "data = ImageClassifierData.from_csv(PATH, 'train', \n",
1350 | " f'{PATH}train.csv', test_name='test', \n",
1351 | " val_idxs = val_idxs , tfms=tfms, bs=bs)"
1352 | ],
1353 | "execution_count": 0,
1354 | "outputs": []
1355 | },
1356 | {
1357 | "metadata": {
1358 | "id": "qLMOaXaWc_iM",
1359 | "colab_type": "code",
1360 | "outputId": "46d5d568-a2dc-4c84-f255-d88590a3bd2a",
1361 | "colab": {
1362 | "base_uri": "https://localhost:8080/",
1363 | "height": 34
1364 | }
1365 | },
1366 | "cell_type": "code",
1367 | "source": [
1368 | "#You can access to training dataset by saying data.trn_ds and trn_ds contains a lot of things including file names (fnames)\n",
1369 | "fn = PATH + data.trn_ds.fnames[1]; fn "
1370 | ],
1371 | "execution_count": 0,
1372 | "outputs": [
1373 | {
1374 | "output_type": "execute_result",
1375 | "data": {
1376 | "text/plain": [
1377 | "'/content/clouderizer/fast.ai/data/train/Img-3.jpg'"
1378 | ]
1379 | },
1380 | "metadata": {
1381 | "tags": []
1382 | },
1383 | "execution_count": 17
1384 | }
1385 | ]
1386 | },
1387 | {
1388 | "metadata": {
1389 | "id": "3NGbAfE2c_iS",
1390 | "colab_type": "code",
1391 | "colab": {}
1392 | },
1393 | "cell_type": "code",
1394 | "source": [
1395 | "img = PIL.Image.open('fn'); img"
1396 | ],
1397 | "execution_count": 0,
1398 | "outputs": []
1399 | },
1400 | {
1401 | "metadata": {
1402 | "id": "j1qsgL10c_ia",
1403 | "colab_type": "code",
1404 | "outputId": "b09f0c51-1c9e-4dbf-cc72-9cb5a435650a",
1405 | "colab": {
1406 | "base_uri": "https://localhost:8080/",
1407 | "height": 34
1408 | }
1409 | },
1410 | "cell_type": "code",
1411 | "source": [
1412 | "img.size"
1413 | ],
1414 | "execution_count": 0,
1415 | "outputs": [
1416 | {
1417 | "output_type": "execute_result",
1418 | "data": {
1419 | "text/plain": [
1420 | "(1024, 683)"
1421 | ]
1422 | },
1423 | "metadata": {
1424 | "tags": []
1425 | },
1426 | "execution_count": 19
1427 | }
1428 | ]
1429 | },
1430 | {
1431 | "metadata": {
1432 | "id": "TQTPjt0chHTE",
1433 | "colab_type": "text"
1434 | },
1435 | "cell_type": "markdown",
1436 | "source": [
1437 | "### to know all sizes am dealing with"
1438 | ]
1439 | },
1440 | {
1441 | "metadata": {
1442 | "id": "-UX4RgbKc_iu",
1443 | "colab_type": "code",
1444 | "colab": {}
1445 | },
1446 | "cell_type": "code",
1447 | "source": [
1448 | "size_d = {k: PIL.Image.open(PATH+k).size for k in data.trn_ds.fnames} # match name to size "
1449 | ],
1450 | "execution_count": 0,
1451 | "outputs": []
1452 | },
1453 | {
1454 | "metadata": {
1455 | "id": "Kw2hPA6Tc_i-",
1456 | "colab_type": "code",
1457 | "colab": {}
1458 | },
1459 | "cell_type": "code",
1460 | "source": [
1461 | "row_sz, col_sz = list(zip(*size_d.values()))"
1462 | ],
1463 | "execution_count": 0,
1464 | "outputs": []
1465 | },
1466 | {
1467 | "metadata": {
1468 | "id": "u4fty6ylc_jG",
1469 | "colab_type": "code",
1470 | "colab": {}
1471 | },
1472 | "cell_type": "code",
1473 | "source": [
1474 | "row_sz = np.array(row_sz); col_sz = np.array(col_sz); "
1475 | ],
1476 | "execution_count": 0,
1477 | "outputs": []
1478 | },
1479 | {
1480 | "metadata": {
1481 | "id": "lOs_hRzMc_jM",
1482 | "colab_type": "code",
1483 | "outputId": "e562d030-4bcf-4216-d902-f9988e2b0ed9",
1484 | "colab": {
1485 | "base_uri": "https://localhost:8080/",
1486 | "height": 34
1487 | }
1488 | },
1489 | "cell_type": "code",
1490 | "source": [
1491 | "row_sz[:15]"
1492 | ],
1493 | "execution_count": 0,
1494 | "outputs": [
1495 | {
1496 | "output_type": "execute_result",
1497 | "data": {
1498 | "text/plain": [
1499 | "array([1024, 1024, 332, 1024, 1024, 640, 333, 1024, 1024, 1024, 1024, 1024, 500, 1024, 1024])"
1500 | ]
1501 | },
1502 | "metadata": {
1503 | "tags": []
1504 | },
1505 | "execution_count": 23
1506 | }
1507 | ]
1508 | },
1509 | {
1510 | "metadata": {
1511 | "id": "I-k8-ohVc_jS",
1512 | "colab_type": "code",
1513 | "outputId": "763a9980-149e-4b64-ef24-f4de2f7c2528",
1514 | "colab": {
1515 | "base_uri": "https://localhost:8080/",
1516 | "height": 34
1517 | }
1518 | },
1519 | "cell_type": "code",
1520 | "source": [
1521 | "col_sz[:15]"
1522 | ],
1523 | "execution_count": 0,
1524 | "outputs": [
1525 | {
1526 | "output_type": "execute_result",
1527 | "data": {
1528 | "text/plain": [
1529 | "array([771, 683, 500, 768, 683, 426, 500, 681, 683, 768, 678, 683, 375, 683, 730])"
1530 | ]
1531 | },
1532 | "metadata": {
1533 | "tags": []
1534 | },
1535 | "execution_count": 24
1536 | }
1537 | ]
1538 | },
1539 | {
1540 | "metadata": {
1541 | "id": "IiPw64R4c_jY",
1542 | "colab_type": "code",
1543 | "colab": {}
1544 | },
1545 | "cell_type": "code",
1546 | "source": [
1547 | "plt.hist(row_sz);"
1548 | ],
1549 | "execution_count": 0,
1550 | "outputs": []
1551 | },
1552 | {
1553 | "metadata": {
1554 | "id": "bUzCl5eoc_je",
1555 | "colab_type": "code",
1556 | "colab": {}
1557 | },
1558 | "cell_type": "code",
1559 | "source": [
1560 | "plt.hist(col_sz);"
1561 | ],
1562 | "execution_count": 0,
1563 | "outputs": []
1564 | },
1565 | {
1566 | "metadata": {
1567 | "id": "ZWe-CDA8c_ji",
1568 | "colab_type": "code",
1569 | "colab": {}
1570 | },
1571 | "cell_type": "code",
1572 | "source": [
1573 | "plt.hist(row_sz[row_sz<1000])"
1574 | ],
1575 | "execution_count": 0,
1576 | "outputs": []
1577 | },
1578 | {
1579 | "metadata": {
1580 | "id": "WHOZHGOq0GtW",
1581 | "colab_type": "text"
1582 | },
1583 | "cell_type": "markdown",
1584 | "source": [
1585 | "## Training"
1586 | ]
1587 | },
1588 | {
1589 | "metadata": {
1590 | "id": "Ul0pcMQuc_jm",
1591 | "colab_type": "code",
1592 | "colab": {}
1593 | },
1594 | "cell_type": "code",
1595 | "source": [
1596 | "def get_data(sz, bs):\n",
1597 | " tfms = tfms_from_model(arch, sz, aug_tfms=transforms_side_on,\n",
1598 | " max_zoom=1.1)\n",
1599 | " data = ImageClassifierData.from_csv(PATH, 'train', \n",
1600 | " f'{PATH}train.csv', test_name='test', num_workers=4,\n",
1601 | " val_idxs = val_idxs ,tfms=tfms, bs=bs)\n",
1602 | "\n",
1603 | " return data if sz>300 else data.resize(340, 'tmp')"
1604 | ],
1605 | "execution_count": 0,
1606 | "outputs": []
1607 | },
1608 | {
1609 | "metadata": {
1610 | "id": "cEiLCYCpc_kM",
1611 | "colab_type": "code",
1612 | "outputId": "c550ae9e-ed74-46dd-8533-2b44759d3ced",
1613 | "colab": {
1614 | "base_uri": "https://localhost:8080/",
1615 | "height": 238
1616 | }
1617 | },
1618 | "cell_type": "code",
1619 | "source": [
1620 | "data = get_data(224, 64)\n",
1621 | "\n",
1622 | "learn = ConvLearner.pretrained(arch, data, precompute=True)\n",
1623 | "\n",
1624 | "learn.fit(0.01,4)"
1625 | ],
1626 | "execution_count": 0,
1627 | "outputs": [
1628 | {
1629 | "output_type": "display_data",
1630 | "data": {
1631 | "application/vnd.jupyter.widget-view+json": {
1632 | "model_id": "32cba6fd76194502b704c5e64a3159e7",
1633 | "version_minor": 0,
1634 | "version_major": 2
1635 | },
1636 | "text/plain": [
1637 | "HBox(children=(IntProgress(value=0, max=6), HTML(value='')))"
1638 | ]
1639 | },
1640 | "metadata": {
1641 | "tags": []
1642 | }
1643 | },
1644 | {
1645 | "output_type": "stream",
1646 | "text": [
1647 | "\n",
1648 | "100%|██████████| 204/204 [07:27<00:00, 2.20s/it]\n",
1649 | "100%|██████████| 1/1 [00:00<00:00, 4.95it/s]"
1650 | ],
1651 | "name": "stdout"
1652 | },
1653 | {
1654 | "output_type": "stream",
1655 | "text": [
1656 | "\n",
1657 | "100%|██████████| 94/94 [03:24<00:00, 2.18s/it]\n"
1658 | ],
1659 | "name": "stdout"
1660 | },
1661 | {
1662 | "output_type": "display_data",
1663 | "data": {
1664 | "application/vnd.jupyter.widget-view+json": {
1665 | "model_id": "1cc4aa8196ef46afa251d01c62adfeaa",
1666 | "version_minor": 0,
1667 | "version_major": 2
1668 | },
1669 | "text/plain": [
1670 | "HBox(children=(IntProgress(value=0, description='Epoch', max=4), HTML(value='')))"
1671 | ]
1672 | },
1673 | "metadata": {
1674 | "tags": []
1675 | }
1676 | },
1677 | {
1678 | "output_type": "stream",
1679 | "text": [
1680 | "epoch trn_loss val_loss accuracy \n",
1681 | " 0 0.313086 0.003255 1.0 \n",
1682 | " 1 0.216928 0.000648 1.0 \n",
1683 | " 96%|█████████▌| 195/204 [00:06<00:00, 28.14it/s, loss=0.183]"
1684 | ],
1685 | "name": "stdout"
1686 | },
1687 | {
1688 | "output_type": "stream",
1689 | "text": [
1690 | " 2 0.180505 0.000462 1.0 \n",
1691 | " 3 0.146408 0.000409 1.0 \n",
1692 | "\n"
1693 | ],
1694 | "name": "stdout"
1695 | },
1696 | {
1697 | "output_type": "execute_result",
1698 | "data": {
1699 | "text/plain": [
1700 | "[array([0.00041]), 1.0]"
1701 | ]
1702 | },
1703 | "metadata": {
1704 | "tags": []
1705 | },
1706 | "execution_count": 16
1707 | }
1708 | ]
1709 | },
1710 | {
1711 | "metadata": {
1712 | "id": "nN4FgKoHqa9c",
1713 | "colab_type": "text"
1714 | },
1715 | "cell_type": "markdown",
1716 | "source": [
1717 | "###choosing learning rate"
1718 | ]
1719 | },
1720 | {
1721 | "metadata": {
1722 | "id": "BZ6Rh-Ns8RYS",
1723 | "colab_type": "code",
1724 | "outputId": "16e58a1f-8a2e-4489-b6b1-a78e676387c4",
1725 | "colab": {
1726 | "base_uri": "https://localhost:8080/",
1727 | "height": 51
1728 | }
1729 | },
1730 | "cell_type": "code",
1731 | "source": [
1732 | "#choosing learning rate\n",
1733 | "lrf=learn.lr_find()"
1734 | ],
1735 | "execution_count": 0,
1736 | "outputs": [
1737 | {
1738 | "output_type": "display_data",
1739 | "data": {
1740 | "application/vnd.jupyter.widget-view+json": {
1741 | "model_id": "f6d90297ebf644c791c0baa3c9f6a459",
1742 | "version_minor": 0,
1743 | "version_major": 2
1744 | },
1745 | "text/plain": [
1746 | "HBox(children=(IntProgress(value=0, description='Epoch', max=1), HTML(value='')))"
1747 | ]
1748 | },
1749 | "metadata": {
1750 | "tags": []
1751 | }
1752 | },
1753 | {
1754 | "output_type": "stream",
1755 | "text": [
1756 | " 66%|██████▌ | 426/650 [00:07<00:03, 57.73it/s, loss=0.23] \n"
1757 | ],
1758 | "name": "stdout"
1759 | }
1760 | ]
1761 | },
1762 | {
1763 | "metadata": {
1764 | "id": "qj0mOAaI8dPd",
1765 | "colab_type": "code",
1766 | "colab": {}
1767 | },
1768 | "cell_type": "code",
1769 | "source": [
1770 | "learn.sched.plot_lr()"
1771 | ],
1772 | "execution_count": 0,
1773 | "outputs": []
1774 | },
1775 | {
1776 | "metadata": {
1777 | "id": "fOZOP8oC8WBV",
1778 | "colab_type": "code",
1779 | "colab": {}
1780 | },
1781 | "cell_type": "code",
1782 | "source": [
1783 | "learn.sched.plot()"
1784 | ],
1785 | "execution_count": 0,
1786 | "outputs": []
1787 | },
1788 | {
1789 | "metadata": {
1790 | "id": "R0NS5jLeqgwx",
1791 | "colab_type": "text"
1792 | },
1793 | "cell_type": "markdown",
1794 | "source": [
1795 | "### Continue Training "
1796 | ]
1797 | },
1798 | {
1799 | "metadata": {
1800 | "id": "8Yrto0ZSmCX0",
1801 | "colab_type": "code",
1802 | "colab": {}
1803 | },
1804 | "cell_type": "code",
1805 | "source": [
1806 | "bs=64 #batch size"
1807 | ],
1808 | "execution_count": 0,
1809 | "outputs": []
1810 | },
1811 | {
1812 | "metadata": {
1813 | "id": "7A8sGufvRW54",
1814 | "colab_type": "code",
1815 | "colab": {}
1816 | },
1817 | "cell_type": "code",
1818 | "source": [
1819 | "learn.precompute = False"
1820 | ],
1821 | "execution_count": 0,
1822 | "outputs": []
1823 | },
1824 | {
1825 | "metadata": {
1826 | "id": "QInZdoMIRZI8",
1827 | "colab_type": "code",
1828 | "outputId": "06571970-d165-4fc0-addb-f1e2eee72bbd",
1829 | "colab": {
1830 | "base_uri": "https://localhost:8080/",
1831 | "height": 119
1832 | }
1833 | },
1834 | "cell_type": "code",
1835 | "source": [
1836 | "learn.fit(1e-2, 2, cycle_len=1)"
1837 | ],
1838 | "execution_count": 0,
1839 | "outputs": [
1840 | {
1841 | "output_type": "display_data",
1842 | "data": {
1843 | "application/vnd.jupyter.widget-view+json": {
1844 | "model_id": "a8e011a0f0404b6f802a7cea5baebea7",
1845 | "version_minor": 0,
1846 | "version_major": 2
1847 | },
1848 | "text/plain": [
1849 | "HBox(children=(IntProgress(value=0, description='Epoch', max=2), HTML(value='')))"
1850 | ]
1851 | },
1852 | "metadata": {
1853 | "tags": []
1854 | }
1855 | },
1856 | {
1857 | "output_type": "stream",
1858 | "text": [
1859 | "epoch trn_loss val_loss accuracy \n",
1860 | " 0 0.16175 0.000257 1.0 \n",
1861 | " 1 0.149721 9e-05 1.0 \n",
1862 | "\n"
1863 | ],
1864 | "name": "stdout"
1865 | },
1866 | {
1867 | "output_type": "execute_result",
1868 | "data": {
1869 | "text/plain": [
1870 | "[array([0.00009]), 1.0]"
1871 | ]
1872 | },
1873 | "metadata": {
1874 | "tags": []
1875 | },
1876 | "execution_count": 19
1877 | }
1878 | ]
1879 | },
1880 | {
1881 | "metadata": {
1882 | "id": "OkeTophrRc38",
1883 | "colab_type": "code",
1884 | "colab": {}
1885 | },
1886 | "cell_type": "code",
1887 | "source": [
1888 | "learn.save('224_pre')\n",
1889 | "learn.load('224_pre')"
1890 | ],
1891 | "execution_count": 0,
1892 | "outputs": []
1893 | },
1894 | {
1895 | "metadata": {
1896 | "id": "wLkRcU6NRczY",
1897 | "colab_type": "code",
1898 | "colab": {}
1899 | },
1900 | "cell_type": "code",
1901 | "source": [
1902 | "lr = 0.01"
1903 | ],
1904 | "execution_count": 0,
1905 | "outputs": []
1906 | },
1907 | {
1908 | "metadata": {
1909 | "id": "1q2bXEClRcrp",
1910 | "colab_type": "code",
1911 | "colab": {}
1912 | },
1913 | "cell_type": "code",
1914 | "source": [
1915 | "lrs=np.array([1e-4,1e-3,1e-2])"
1916 | ],
1917 | "execution_count": 0,
1918 | "outputs": []
1919 | },
1920 | {
1921 | "metadata": {
1922 | "id": "HwLvwsqZRcnP",
1923 | "colab_type": "code",
1924 | "outputId": "2b57b81e-7c1d-42f3-94ab-b08cb3f4a5a9",
1925 | "colab": {
1926 | "base_uri": "https://localhost:8080/",
1927 | "height": 170
1928 | }
1929 | },
1930 | "cell_type": "code",
1931 | "source": [
1932 | "learn.set_data(get_data(224, 16))\n",
1933 | "learn.unfreeze()\n",
1934 | "learn.fit(lrs, 2, cycle_len=1, cycle_mult=2)"
1935 | ],
1936 | "execution_count": 0,
1937 | "outputs": [
1938 | {
1939 | "output_type": "display_data",
1940 | "data": {
1941 | "application/vnd.jupyter.widget-view+json": {
1942 | "model_id": "140c098074ca4a49aaaa230b0ee2ae84",
1943 | "version_minor": 0,
1944 | "version_major": 2
1945 | },
1946 | "text/plain": [
1947 | "HBox(children=(IntProgress(value=0, max=6), HTML(value='')))"
1948 | ]
1949 | },
1950 | "metadata": {
1951 | "tags": []
1952 | }
1953 | },
1954 | {
1955 | "output_type": "stream",
1956 | "text": [
1957 | "\n"
1958 | ],
1959 | "name": "stdout"
1960 | },
1961 | {
1962 | "output_type": "display_data",
1963 | "data": {
1964 | "application/vnd.jupyter.widget-view+json": {
1965 | "model_id": "389ac3da7b2647efaa60797eff2b5a53",
1966 | "version_minor": 0,
1967 | "version_major": 2
1968 | },
1969 | "text/plain": [
1970 | "HBox(children=(IntProgress(value=0, description='Epoch', max=3), HTML(value='')))"
1971 | ]
1972 | },
1973 | "metadata": {
1974 | "tags": []
1975 | }
1976 | },
1977 | {
1978 | "output_type": "stream",
1979 | "text": [
1980 | "epoch trn_loss val_loss accuracy \n",
1981 | " 0 0.306817 0.018615 1.0 \n",
1982 | " 0%| | 2/813 [00:06<45:18, 3.35s/it, loss=0.299]"
1983 | ],
1984 | "name": "stdout"
1985 | },
1986 | {
1987 | "output_type": "stream",
1988 | "text": [
1989 | " 1 0.282475 0.014633 1.0 \n",
1990 | " 1%| | 6/813 [00:12<27:15, 2.03s/it, loss=0.258]"
1991 | ],
1992 | "name": "stdout"
1993 | },
1994 | {
1995 | "output_type": "stream",
1996 | "text": [
1997 | " 2 0.121539 0.000603 1.0 \n",
1998 | "\n"
1999 | ],
2000 | "name": "stdout"
2001 | },
2002 | {
2003 | "output_type": "execute_result",
2004 | "data": {
2005 | "text/plain": [
2006 | "[array([0.0006]), 1.0]"
2007 | ]
2008 | },
2009 | "metadata": {
2010 | "tags": []
2011 | },
2012 | "execution_count": 23
2013 | }
2014 | ]
2015 | },
2016 | {
2017 | "metadata": {
2018 | "id": "UsXsdVx-RclT",
2019 | "colab_type": "code",
2020 | "colab": {}
2021 | },
2022 | "cell_type": "code",
2023 | "source": [
2024 | "learn.save('224_unf')\n",
2025 | "learn.load('224_unf')"
2026 | ],
2027 | "execution_count": 0,
2028 | "outputs": []
2029 | },
2030 | {
2031 | "metadata": {
2032 | "id": "utAxQJFTRcez",
2033 | "colab_type": "code",
2034 | "outputId": "a913c495-55af-47cc-8127-be92f3f42cad",
2035 | "colab": {
2036 | "base_uri": "https://localhost:8080/",
2037 | "height": 238
2038 | }
2039 | },
2040 | "cell_type": "code",
2041 | "source": [
2042 | "learn.set_data(get_data(299, 64))\n",
2043 | "learn.freeze()\n",
2044 | "learn.fit(lr, 3, cycle_len=1, cycle_mult=2)"
2045 | ],
2046 | "execution_count": 0,
2047 | "outputs": [
2048 | {
2049 | "output_type": "display_data",
2050 | "data": {
2051 | "application/vnd.jupyter.widget-view+json": {
2052 | "model_id": "0b4f590e82454e9c95f9114e1e9703f0",
2053 | "version_minor": 0,
2054 | "version_major": 2
2055 | },
2056 | "text/plain": [
2057 | "HBox(children=(IntProgress(value=0, max=6), HTML(value='')))"
2058 | ]
2059 | },
2060 | "metadata": {
2061 | "tags": []
2062 | }
2063 | },
2064 | {
2065 | "output_type": "stream",
2066 | "text": [
2067 | "\n"
2068 | ],
2069 | "name": "stdout"
2070 | },
2071 | {
2072 | "output_type": "display_data",
2073 | "data": {
2074 | "application/vnd.jupyter.widget-view+json": {
2075 | "model_id": "2535b2c2273a49978865cda87c1b08b9",
2076 | "version_minor": 0,
2077 | "version_major": 2
2078 | },
2079 | "text/plain": [
2080 | "HBox(children=(IntProgress(value=0, description='Epoch', max=7), HTML(value='')))"
2081 | ]
2082 | },
2083 | "metadata": {
2084 | "tags": []
2085 | }
2086 | },
2087 | {
2088 | "output_type": "stream",
2089 | "text": [
2090 | "epoch trn_loss val_loss accuracy \n",
2091 | " 0 0.047342 0.001577 1.0 \n",
2092 | " 1 0.052206 0.000767 1.0 \n",
2093 | " 16%|█▌ | 32/204 [02:12<11:51, 4.14s/it, loss=0.0481]"
2094 | ],
2095 | "name": "stdout"
2096 | },
2097 | {
2098 | "output_type": "stream",
2099 | "text": [
2100 | " 2 0.042767 0.000401 1.0 \n",
2101 | " 3 0.044702 0.000616 1.0 \n",
2102 | " 58%|█████▊ | 118/204 [07:56<05:47, 4.04s/it, loss=0.04] "
2103 | ],
2104 | "name": "stdout"
2105 | },
2106 | {
2107 | "output_type": "stream",
2108 | "text": [
2109 | " 4 0.04556 0.00046 1.0 \n",
2110 | " 5 0.039715 0.000788 1.0 \n",
2111 | " 75%|███████▌ | 153/204 [10:17<03:25, 4.04s/it, loss=0.0378]"
2112 | ],
2113 | "name": "stdout"
2114 | },
2115 | {
2116 | "output_type": "stream",
2117 | "text": [
2118 | " 6 0.037948 0.000463 1.0 \n",
2119 | "\n"
2120 | ],
2121 | "name": "stdout"
2122 | },
2123 | {
2124 | "output_type": "execute_result",
2125 | "data": {
2126 | "text/plain": [
2127 | "[array([0.00046]), 1.0]"
2128 | ]
2129 | },
2130 | "metadata": {
2131 | "tags": []
2132 | },
2133 | "execution_count": 25
2134 | }
2135 | ]
2136 | },
2137 | {
2138 | "metadata": {
2139 | "id": "VFKQFInzRyGh",
2140 | "colab_type": "code",
2141 | "colab": {}
2142 | },
2143 | "cell_type": "code",
2144 | "source": [
2145 | "learn.save('229_pre')\n",
2146 | "learn.load('229_pre')"
2147 | ],
2148 | "execution_count": 0,
2149 | "outputs": []
2150 | },
2151 | {
2152 | "metadata": {
2153 | "id": "XGBtQE-FRyCN",
2154 | "colab_type": "code",
2155 | "colab": {}
2156 | },
2157 | "cell_type": "code",
2158 | "source": [
2159 | "learn.set_data(get_data(360, 64))"
2160 | ],
2161 | "execution_count": 0,
2162 | "outputs": []
2163 | },
2164 | {
2165 | "metadata": {
2166 | "id": "kiSow-v7Rx_e",
2167 | "colab_type": "code",
2168 | "outputId": "2de05600-5a5a-4d07-f107-7fbaa677ed9b",
2169 | "colab": {
2170 | "base_uri": "https://localhost:8080/",
2171 | "height": 136
2172 | }
2173 | },
2174 | "cell_type": "code",
2175 | "source": [
2176 | "learn.fit(lr, 2, cycle_len=1, cycle_mult=2)"
2177 | ],
2178 | "execution_count": 0,
2179 | "outputs": [
2180 | {
2181 | "output_type": "display_data",
2182 | "data": {
2183 | "application/vnd.jupyter.widget-view+json": {
2184 | "model_id": "52f3b7fa1534432aa63579b1197ef18d",
2185 | "version_minor": 0,
2186 | "version_major": 2
2187 | },
2188 | "text/plain": [
2189 | "HBox(children=(IntProgress(value=0, description='Epoch', max=3), HTML(value='')))"
2190 | ]
2191 | },
2192 | "metadata": {
2193 | "tags": []
2194 | }
2195 | },
2196 | {
2197 | "output_type": "stream",
2198 | "text": [
2199 | "epoch trn_loss val_loss accuracy \n",
2200 | " 0 0.054711 0.027197 1.0 \n",
2201 | " 1 0.044915 0.02951 1.0 \n",
2202 | " 16%|█▌ | 33/204 [03:13<16:44, 5.88s/it, loss=0.0458]"
2203 | ],
2204 | "name": "stdout"
2205 | },
2206 | {
2207 | "output_type": "stream",
2208 | "text": [
2209 | " 2 0.040435 0.038124 1.0 \n",
2210 | "\n"
2211 | ],
2212 | "name": "stdout"
2213 | },
2214 | {
2215 | "output_type": "execute_result",
2216 | "data": {
2217 | "text/plain": [
2218 | "[array([0.03812]), 1.0]"
2219 | ]
2220 | },
2221 | "metadata": {
2222 | "tags": []
2223 | },
2224 | "execution_count": 28
2225 | }
2226 | ]
2227 | },
2228 | {
2229 | "metadata": {
2230 | "id": "oJOtpEG3Rx6t",
2231 | "colab_type": "code",
2232 | "colab": {}
2233 | },
2234 | "cell_type": "code",
2235 | "source": [
2236 | "learn.save('360_pre')\n",
2237 | "learn.load('360_pre')"
2238 | ],
2239 | "execution_count": 0,
2240 | "outputs": []
2241 | },
2242 | {
2243 | "metadata": {
2244 | "id": "2KvnRniOBH_f",
2245 | "colab_type": "code",
2246 | "outputId": "2ebd9c40-c3af-463c-e179-fc386cce36bc",
2247 | "colab": {
2248 | "base_uri": "https://localhost:8080/",
2249 | "height": 34
2250 | }
2251 | },
2252 | "cell_type": "code",
2253 | "source": [
2254 | "#making submission file\n",
2255 | "log_preds, y = learn.TTA(is_test=True)\n",
2256 | "probs = np.mean(np.exp(log_preds),0)\n",
2257 | "probs.shape"
2258 | ],
2259 | "execution_count": 0,
2260 | "outputs": [
2261 | {
2262 | "output_type": "stream",
2263 | "text": [
2264 | ""
2265 | ],
2266 | "name": "stdout"
2267 | },
2268 | {
2269 | "output_type": "execute_result",
2270 | "data": {
2271 | "text/plain": [
2272 | "(6000, 30)"
2273 | ]
2274 | },
2275 | "metadata": {
2276 | "tags": []
2277 | },
2278 | "execution_count": 30
2279 | }
2280 | ]
2281 | },
2282 | {
2283 | "metadata": {
2284 | "id": "eKY6AMl-BH6-",
2285 | "colab_type": "code",
2286 | "colab": {}
2287 | },
2288 | "cell_type": "code",
2289 | "source": [
2290 | "df = pd.DataFrame(probs)\n",
2291 | "df.columns = data.classes"
2292 | ],
2293 | "execution_count": 0,
2294 | "outputs": []
2295 | },
2296 | {
2297 | "metadata": {
2298 | "id": "sCcR_wCFBHPk",
2299 | "colab_type": "code",
2300 | "outputId": "888d803f-8037-45b8-cef2-399755739232",
2301 | "colab": {
2302 | "base_uri": "https://localhost:8080/",
2303 | "height": 338
2304 | }
2305 | },
2306 | "cell_type": "code",
2307 | "source": [
2308 | "df.insert(0, 'image_id', [o[5:] for o in data.test_ds.fnames])\n",
2309 | "df.head()"
2310 | ],
2311 | "execution_count": 0,
2312 | "outputs": [
2313 | {
2314 | "output_type": "execute_result",
2315 | "data": {
2316 | "text/html": [
2317 | "\n",
2318 | "\n",
2331 | "
\n",
2332 | " \n",
2333 | " \n",
2334 | " | \n",
2335 | " image_id | \n",
2336 | " antelope | \n",
2337 | " bat | \n",
2338 | " beaver | \n",
2339 | " bobcat | \n",
2340 | " buffalo | \n",
2341 | " chihuahua | \n",
2342 | " chimpanzee | \n",
2343 | " collie | \n",
2344 | " dalmatian | \n",
2345 | " ... | \n",
2346 | " raccoon | \n",
2347 | " rat | \n",
2348 | " rhinoceros | \n",
2349 | " seal | \n",
2350 | " siamese+cat | \n",
2351 | " spider+monkey | \n",
2352 | " squirrel | \n",
2353 | " walrus | \n",
2354 | " weasel | \n",
2355 | " wolf | \n",
2356 | "
\n",
2357 | " \n",
2358 | " \n",
2359 | " \n",
2360 | " | 0 | \n",
2361 | " Img-5647.jpg | \n",
2362 | " 1.619676e-04 | \n",
2363 | " 1.637927e-06 | \n",
2364 | " 8.536745e-07 | \n",
2365 | " 3.230958e-06 | \n",
2366 | " 8.353566e-05 | \n",
2367 | " 8.326990e-06 | \n",
2368 | " 6.242119e-06 | \n",
2369 | " 9.001495e-03 | \n",
2370 | " 4.528410e-05 | \n",
2371 | " ... | \n",
2372 | " 1.381171e-06 | \n",
2373 | " 2.179542e-07 | \n",
2374 | " 6.802338e-05 | \n",
2375 | " 6.979513e-05 | \n",
2376 | " 2.218990e-05 | \n",
2377 | " 9.709227e-06 | \n",
2378 | " 2.234400e-06 | \n",
2379 | " 1.430522e-05 | \n",
2380 | " 6.519805e-06 | \n",
2381 | " 3.543333e-05 | \n",
2382 | "
\n",
2383 | " \n",
2384 | " | 1 | \n",
2385 | " Img-3230.jpg | \n",
2386 | " 9.999941e-01 | \n",
2387 | " 6.272117e-09 | \n",
2388 | " 9.557740e-09 | \n",
2389 | " 7.821985e-07 | \n",
2390 | " 2.533016e-08 | \n",
2391 | " 8.435378e-07 | \n",
2392 | " 1.459975e-08 | \n",
2393 | " 4.509126e-07 | \n",
2394 | " 1.328060e-06 | \n",
2395 | " ... | \n",
2396 | " 5.077161e-08 | \n",
2397 | " 2.484132e-07 | \n",
2398 | " 2.345775e-08 | \n",
2399 | " 1.250904e-08 | \n",
2400 | " 7.436167e-09 | \n",
2401 | " 4.522560e-08 | \n",
2402 | " 1.120635e-07 | \n",
2403 | " 1.298633e-07 | \n",
2404 | " 7.652126e-08 | \n",
2405 | " 1.856314e-07 | \n",
2406 | "
\n",
2407 | " \n",
2408 | " | 2 | \n",
2409 | " Img-4568.jpg | \n",
2410 | " 1.083353e-06 | \n",
2411 | " 1.204197e-08 | \n",
2412 | " 3.752252e-06 | \n",
2413 | " 3.452412e-07 | \n",
2414 | " 8.563509e-09 | \n",
2415 | " 2.185422e-06 | \n",
2416 | " 1.215539e-07 | \n",
2417 | " 2.579241e-07 | \n",
2418 | " 6.394412e-07 | \n",
2419 | " ... | \n",
2420 | " 9.999822e-01 | \n",
2421 | " 8.342631e-07 | \n",
2422 | " 3.232788e-08 | \n",
2423 | " 9.012304e-09 | \n",
2424 | " 2.155636e-08 | \n",
2425 | " 1.926119e-07 | \n",
2426 | " 2.098884e-06 | \n",
2427 | " 5.669494e-08 | \n",
2428 | " 1.486224e-06 | \n",
2429 | " 1.395223e-07 | \n",
2430 | "
\n",
2431 | " \n",
2432 | " | 3 | \n",
2433 | " Img-395.jpg | \n",
2434 | " 2.140992e-07 | \n",
2435 | " 1.833635e-07 | \n",
2436 | " 1.340413e-05 | \n",
2437 | " 8.942153e-08 | \n",
2438 | " 4.466565e-05 | \n",
2439 | " 3.659269e-06 | \n",
2440 | " 2.771912e-05 | \n",
2441 | " 2.850984e-06 | \n",
2442 | " 2.819810e-06 | \n",
2443 | " ... | \n",
2444 | " 8.113968e-08 | \n",
2445 | " 1.954130e-05 | \n",
2446 | " 2.656360e-05 | \n",
2447 | " 1.217158e-02 | \n",
2448 | " 1.009568e-05 | \n",
2449 | " 7.167854e-07 | \n",
2450 | " 2.653717e-06 | \n",
2451 | " 4.624942e-03 | \n",
2452 | " 2.048628e-06 | \n",
2453 | " 4.179227e-06 | \n",
2454 | "
\n",
2455 | " \n",
2456 | " | 4 | \n",
2457 | " Img-4449.jpg | \n",
2458 | " 5.831538e-07 | \n",
2459 | " 9.878679e-07 | \n",
2460 | " 8.821865e-06 | \n",
2461 | " 1.653637e-06 | \n",
2462 | " 1.434233e-06 | \n",
2463 | " 3.211755e-07 | \n",
2464 | " 6.497939e-06 | \n",
2465 | " 8.012462e-07 | \n",
2466 | " 2.317253e-07 | \n",
2467 | " ... | \n",
2468 | " 2.606133e-04 | \n",
2469 | " 1.137030e-06 | \n",
2470 | " 5.770088e-07 | \n",
2471 | " 9.208277e-06 | \n",
2472 | " 1.705974e-07 | \n",
2473 | " 6.155243e-05 | \n",
2474 | " 9.996187e-01 | \n",
2475 | " 3.376758e-07 | \n",
2476 | " 5.925617e-07 | \n",
2477 | " 9.294068e-07 | \n",
2478 | "
\n",
2479 | " \n",
2480 | "
\n",
2481 | "
5 rows × 31 columns
\n",
2482 | "
"
2483 | ],
2484 | "text/plain": [
2485 | " image_id antelope bat beaver bobcat \\\n",
2486 | "0 Img-5647.jpg 1.619676e-04 1.637927e-06 8.536745e-07 3.230958e-06 \n",
2487 | "1 Img-3230.jpg 9.999941e-01 6.272117e-09 9.557740e-09 7.821985e-07 \n",
2488 | "2 Img-4568.jpg 1.083353e-06 1.204197e-08 3.752252e-06 3.452412e-07 \n",
2489 | "3 Img-395.jpg 2.140992e-07 1.833635e-07 1.340413e-05 8.942153e-08 \n",
2490 | "4 Img-4449.jpg 5.831538e-07 9.878679e-07 8.821865e-06 1.653637e-06 \n",
2491 | "\n",
2492 | " buffalo chihuahua chimpanzee collie dalmatian \\\n",
2493 | "0 8.353566e-05 8.326990e-06 6.242119e-06 9.001495e-03 4.528410e-05 \n",
2494 | "1 2.533016e-08 8.435378e-07 1.459975e-08 4.509126e-07 1.328060e-06 \n",
2495 | "2 8.563509e-09 2.185422e-06 1.215539e-07 2.579241e-07 6.394412e-07 \n",
2496 | "3 4.466565e-05 3.659269e-06 2.771912e-05 2.850984e-06 2.819810e-06 \n",
2497 | "4 1.434233e-06 3.211755e-07 6.497939e-06 8.012462e-07 2.317253e-07 \n",
2498 | "\n",
2499 | " ... raccoon rat rhinoceros seal \\\n",
2500 | "0 ... 1.381171e-06 2.179542e-07 6.802338e-05 6.979513e-05 \n",
2501 | "1 ... 5.077161e-08 2.484132e-07 2.345775e-08 1.250904e-08 \n",
2502 | "2 ... 9.999822e-01 8.342631e-07 3.232788e-08 9.012304e-09 \n",
2503 | "3 ... 8.113968e-08 1.954130e-05 2.656360e-05 1.217158e-02 \n",
2504 | "4 ... 2.606133e-04 1.137030e-06 5.770088e-07 9.208277e-06 \n",
2505 | "\n",
2506 | " siamese+cat spider+monkey squirrel walrus weasel \\\n",
2507 | "0 2.218990e-05 9.709227e-06 2.234400e-06 1.430522e-05 6.519805e-06 \n",
2508 | "1 7.436167e-09 4.522560e-08 1.120635e-07 1.298633e-07 7.652126e-08 \n",
2509 | "2 2.155636e-08 1.926119e-07 2.098884e-06 5.669494e-08 1.486224e-06 \n",
2510 | "3 1.009568e-05 7.167854e-07 2.653717e-06 4.624942e-03 2.048628e-06 \n",
2511 | "4 1.705974e-07 6.155243e-05 9.996187e-01 3.376758e-07 5.925617e-07 \n",
2512 | "\n",
2513 | " wolf \n",
2514 | "0 3.543333e-05 \n",
2515 | "1 1.856314e-07 \n",
2516 | "2 1.395223e-07 \n",
2517 | "3 4.179227e-06 \n",
2518 | "4 9.294068e-07 \n",
2519 | "\n",
2520 | "[5 rows x 31 columns]"
2521 | ]
2522 | },
2523 | "metadata": {
2524 | "tags": []
2525 | },
2526 | "execution_count": 32
2527 | }
2528 | ]
2529 | },
2530 | {
2531 | "metadata": {
2532 | "id": "7PwQvZHzBHLH",
2533 | "colab_type": "code",
2534 | "colab": {}
2535 | },
2536 | "cell_type": "code",
2537 | "source": [
2538 | "#make csv and zip it \n",
2539 | "SUBM = f'{PATH}sub/' \n",
2540 | "os.makedirs(SUBM, exist_ok=True) \n",
2541 | "df.to_csv(f'{SUBM}subm8.gz', compression='gzip', index=False)"
2542 | ],
2543 | "execution_count": 0,
2544 | "outputs": []
2545 | },
2546 | {
2547 | "metadata": {
2548 | "id": "M7MnWd5TBHIh",
2549 | "colab_type": "code",
2550 | "colab": {}
2551 | },
2552 | "cell_type": "code",
2553 | "source": [
2554 | "from google.colab import files\n",
2555 | "files.download(\"/content/clouderizer/fast.ai/data/sub/subm8.gz\")"
2556 | ],
2557 | "execution_count": 0,
2558 | "outputs": []
2559 | },
2560 | {
2561 | "metadata": {
2562 | "id": "Ey-ENf7cx7y6",
2563 | "colab_type": "code",
2564 | "colab": {}
2565 | },
2566 | "cell_type": "code",
2567 | "source": [
2568 | "#--------------------------------------------------------------------"
2569 | ],
2570 | "execution_count": 0,
2571 | "outputs": []
2572 | },
2573 | {
2574 | "metadata": {
2575 | "id": "P7dOH9aAxkVp",
2576 | "colab_type": "code",
2577 | "colab": {}
2578 | },
2579 | "cell_type": "code",
2580 | "source": [
2581 | "learn.set_data(get_data(420, 16))"
2582 | ],
2583 | "execution_count": 0,
2584 | "outputs": []
2585 | },
2586 | {
2587 | "metadata": {
2588 | "id": "euujKNIlRx1D",
2589 | "colab_type": "code",
2590 | "outputId": "9d4acba6-0224-4a8e-9255-9cf5895fcfb9",
2591 | "colab": {
2592 | "base_uri": "https://localhost:8080/",
2593 | "height": 102
2594 | }
2595 | },
2596 | "cell_type": "code",
2597 | "source": [
2598 | "learn.fit(lr, 1 )"
2599 | ],
2600 | "execution_count": 0,
2601 | "outputs": [
2602 | {
2603 | "output_type": "display_data",
2604 | "data": {
2605 | "application/vnd.jupyter.widget-view+json": {
2606 | "model_id": "259860f24278482e8da22087be30ce51",
2607 | "version_minor": 0,
2608 | "version_major": 2
2609 | },
2610 | "text/plain": [
2611 | "HBox(children=(IntProgress(value=0, description='Epoch', max=1), HTML(value='')))"
2612 | ]
2613 | },
2614 | "metadata": {
2615 | "tags": []
2616 | }
2617 | },
2618 | {
2619 | "output_type": "stream",
2620 | "text": [
2621 | "epoch trn_loss val_loss accuracy \n",
2622 | " 0 0.075403 0.027132 1.0 \n",
2623 | "\n"
2624 | ],
2625 | "name": "stdout"
2626 | },
2627 | {
2628 | "output_type": "execute_result",
2629 | "data": {
2630 | "text/plain": [
2631 | "[array([0.02713]), 1.0]"
2632 | ]
2633 | },
2634 | "metadata": {
2635 | "tags": []
2636 | },
2637 | "execution_count": 36
2638 | }
2639 | ]
2640 | },
2641 | {
2642 | "metadata": {
2643 | "id": "3cUXgeVSKkRt",
2644 | "colab_type": "code",
2645 | "outputId": "71b9db3d-33ae-4c68-bf90-763d474fa7ba",
2646 | "colab": {
2647 | "base_uri": "https://localhost:8080/",
2648 | "height": 119
2649 | }
2650 | },
2651 | "cell_type": "code",
2652 | "source": [
2653 | "learn.fit(lr, 2 )"
2654 | ],
2655 | "execution_count": 0,
2656 | "outputs": [
2657 | {
2658 | "output_type": "display_data",
2659 | "data": {
2660 | "application/vnd.jupyter.widget-view+json": {
2661 | "model_id": "91a49e6999594651825e5805c8e02a12",
2662 | "version_minor": 0,
2663 | "version_major": 2
2664 | },
2665 | "text/plain": [
2666 | "HBox(children=(IntProgress(value=0, description='Epoch', max=2), HTML(value='')))"
2667 | ]
2668 | },
2669 | "metadata": {
2670 | "tags": []
2671 | }
2672 | },
2673 | {
2674 | "output_type": "stream",
2675 | "text": [
2676 | ""
2677 | ],
2678 | "name": "stdout"
2679 | },
2680 | {
2681 | "output_type": "stream",
2682 | "text": [
2683 | "epoch trn_loss val_loss accuracy \n",
2684 | " 0 0.095298 0.079907 1.0 \n",
2685 | " 41%|████ | 331/813 [11:07<16:12, 2.02s/it, loss=0.0704]"
2686 | ],
2687 | "name": "stdout"
2688 | },
2689 | {
2690 | "output_type": "stream",
2691 | "text": [
2692 | " 1 0.071435 0.075263 1.0 \n",
2693 | "\n"
2694 | ],
2695 | "name": "stdout"
2696 | },
2697 | {
2698 | "output_type": "execute_result",
2699 | "data": {
2700 | "text/plain": [
2701 | "[array([0.07526]), 1.0]"
2702 | ]
2703 | },
2704 | "metadata": {
2705 | "tags": []
2706 | },
2707 | "execution_count": 37
2708 | }
2709 | ]
2710 | },
2711 | {
2712 | "metadata": {
2713 | "id": "7W1D2LUGziCJ",
2714 | "colab_type": "code",
2715 | "colab": {}
2716 | },
2717 | "cell_type": "code",
2718 | "source": [
2719 | "learn.save('420_pre')\n",
2720 | "learn.load('420_pre')"
2721 | ],
2722 | "execution_count": 0,
2723 | "outputs": []
2724 | },
2725 | {
2726 | "metadata": {
2727 | "id": "8kAfMelYznbu",
2728 | "colab_type": "code",
2729 | "colab": {}
2730 | },
2731 | "cell_type": "code",
2732 | "source": [
2733 | "#-------------------------------------"
2734 | ],
2735 | "execution_count": 0,
2736 | "outputs": []
2737 | },
2738 | {
2739 | "metadata": {
2740 | "id": "7z_6bzG2DPY5",
2741 | "colab_type": "code",
2742 | "outputId": "e0bd042f-a8ec-4279-cc0a-bc9a205fc41a",
2743 | "colab": {
2744 | "base_uri": "https://localhost:8080/",
2745 | "height": 34
2746 | }
2747 | },
2748 | "cell_type": "code",
2749 | "source": [
2750 | "log_preds, y = learn.TTA(is_test=True)\n",
2751 | "probs = np.mean(np.exp(log_preds),0)\n",
2752 | "probs.shape"
2753 | ],
2754 | "execution_count": 0,
2755 | "outputs": [
2756 | {
2757 | "output_type": "stream",
2758 | "text": [
2759 | ""
2760 | ],
2761 | "name": "stdout"
2762 | },
2763 | {
2764 | "output_type": "execute_result",
2765 | "data": {
2766 | "text/plain": [
2767 | "(6000, 30)"
2768 | ]
2769 | },
2770 | "metadata": {
2771 | "tags": []
2772 | },
2773 | "execution_count": 39
2774 | }
2775 | ]
2776 | },
2777 | {
2778 | "metadata": {
2779 | "id": "V2pSpalkDPV8",
2780 | "colab_type": "code",
2781 | "colab": {}
2782 | },
2783 | "cell_type": "code",
2784 | "source": [
2785 | "df = pd.DataFrame(probs)\n",
2786 | "df.columns = data.classes"
2787 | ],
2788 | "execution_count": 0,
2789 | "outputs": []
2790 | },
2791 | {
2792 | "metadata": {
2793 | "id": "BnMEAnizDhnd",
2794 | "colab_type": "code",
2795 | "outputId": "b9baab9d-8ed3-4158-9b66-4ac7ca3be03c",
2796 | "colab": {
2797 | "base_uri": "https://localhost:8080/",
2798 | "height": 338
2799 | }
2800 | },
2801 | "cell_type": "code",
2802 | "source": [
2803 | "df.insert(0, 'image_id', [o[5:] for o in data.test_ds.fnames])\n",
2804 | "df.head()"
2805 | ],
2806 | "execution_count": 0,
2807 | "outputs": [
2808 | {
2809 | "output_type": "execute_result",
2810 | "data": {
2811 | "text/html": [
2812 | "\n",
2813 | "\n",
2826 | "
\n",
2827 | " \n",
2828 | " \n",
2829 | " | \n",
2830 | " image_id | \n",
2831 | " antelope | \n",
2832 | " bat | \n",
2833 | " beaver | \n",
2834 | " bobcat | \n",
2835 | " buffalo | \n",
2836 | " chihuahua | \n",
2837 | " chimpanzee | \n",
2838 | " collie | \n",
2839 | " dalmatian | \n",
2840 | " ... | \n",
2841 | " raccoon | \n",
2842 | " rat | \n",
2843 | " rhinoceros | \n",
2844 | " seal | \n",
2845 | " siamese+cat | \n",
2846 | " spider+monkey | \n",
2847 | " squirrel | \n",
2848 | " walrus | \n",
2849 | " weasel | \n",
2850 | " wolf | \n",
2851 | "
\n",
2852 | " \n",
2853 | " \n",
2854 | " \n",
2855 | " | 0 | \n",
2856 | " Img-5647.jpg | \n",
2857 | " 3.159350e-05 | \n",
2858 | " 8.928788e-06 | \n",
2859 | " 1.424190e-06 | \n",
2860 | " 3.163671e-06 | \n",
2861 | " 9.531980e-05 | \n",
2862 | " 1.266143e-05 | \n",
2863 | " 3.213432e-06 | \n",
2864 | " 2.368384e-03 | \n",
2865 | " 8.829939e-05 | \n",
2866 | " ... | \n",
2867 | " 9.412486e-06 | \n",
2868 | " 8.175143e-07 | \n",
2869 | " 2.968850e-04 | \n",
2870 | " 5.378051e-05 | \n",
2871 | " 5.613676e-05 | \n",
2872 | " 3.570866e-05 | \n",
2873 | " 1.254341e-05 | \n",
2874 | " 7.219761e-06 | \n",
2875 | " 7.715807e-06 | \n",
2876 | " 1.594744e-05 | \n",
2877 | "
\n",
2878 | " \n",
2879 | " | 1 | \n",
2880 | " Img-3230.jpg | \n",
2881 | " 9.999989e-01 | \n",
2882 | " 4.410581e-10 | \n",
2883 | " 7.409740e-09 | \n",
2884 | " 3.252055e-07 | \n",
2885 | " 3.372520e-09 | \n",
2886 | " 1.509341e-08 | \n",
2887 | " 9.406571e-10 | \n",
2888 | " 4.785741e-08 | \n",
2889 | " 3.069857e-07 | \n",
2890 | " ... | \n",
2891 | " 1.290144e-08 | \n",
2892 | " 6.030067e-09 | \n",
2893 | " 2.595238e-09 | \n",
2894 | " 1.813413e-09 | \n",
2895 | " 1.153833e-10 | \n",
2896 | " 8.572713e-10 | \n",
2897 | " 1.105912e-08 | \n",
2898 | " 5.390022e-09 | \n",
2899 | " 1.162741e-09 | \n",
2900 | " 3.082452e-09 | \n",
2901 | "
\n",
2902 | " \n",
2903 | " | 2 | \n",
2904 | " Img-4568.jpg | \n",
2905 | " 2.687980e-07 | \n",
2906 | " 4.843321e-09 | \n",
2907 | " 1.006783e-06 | \n",
2908 | " 3.782131e-08 | \n",
2909 | " 1.027670e-09 | \n",
2910 | " 8.587640e-07 | \n",
2911 | " 2.681424e-08 | \n",
2912 | " 6.297764e-08 | \n",
2913 | " 1.676035e-08 | \n",
2914 | " ... | \n",
2915 | " 9.999946e-01 | \n",
2916 | " 4.205262e-08 | \n",
2917 | " 1.532161e-09 | \n",
2918 | " 3.884408e-09 | \n",
2919 | " 2.434926e-09 | \n",
2920 | " 2.533341e-08 | \n",
2921 | " 1.814196e-06 | \n",
2922 | " 8.880784e-09 | \n",
2923 | " 6.122975e-07 | \n",
2924 | " 3.280068e-08 | \n",
2925 | "
\n",
2926 | " \n",
2927 | " | 3 | \n",
2928 | " Img-395.jpg | \n",
2929 | " 2.902317e-07 | \n",
2930 | " 9.444283e-08 | \n",
2931 | " 4.002781e-06 | \n",
2932 | " 1.010353e-07 | \n",
2933 | " 1.339610e-05 | \n",
2934 | " 5.511737e-06 | \n",
2935 | " 2.670262e-04 | \n",
2936 | " 1.743207e-06 | \n",
2937 | " 2.048028e-06 | \n",
2938 | " ... | \n",
2939 | " 5.612122e-07 | \n",
2940 | " 1.355699e-05 | \n",
2941 | " 7.047990e-05 | \n",
2942 | " 6.026975e-04 | \n",
2943 | " 1.884430e-05 | \n",
2944 | " 1.994449e-06 | \n",
2945 | " 8.812417e-07 | \n",
2946 | " 3.871692e-04 | \n",
2947 | " 3.919969e-06 | \n",
2948 | " 3.350742e-06 | \n",
2949 | "
\n",
2950 | " \n",
2951 | " | 4 | \n",
2952 | " Img-4449.jpg | \n",
2953 | " 1.123357e-08 | \n",
2954 | " 1.097230e-07 | \n",
2955 | " 1.032839e-06 | \n",
2956 | " 9.813154e-08 | \n",
2957 | " 5.498913e-08 | \n",
2958 | " 3.354518e-08 | \n",
2959 | " 7.284951e-07 | \n",
2960 | " 1.356309e-07 | \n",
2961 | " 5.251192e-09 | \n",
2962 | " ... | \n",
2963 | " 2.768773e-05 | \n",
2964 | " 2.168487e-08 | \n",
2965 | " 4.325886e-09 | \n",
2966 | " 9.960676e-07 | \n",
2967 | " 1.121863e-08 | \n",
2968 | " 7.563170e-06 | \n",
2969 | " 9.999599e-01 | \n",
2970 | " 1.503267e-09 | \n",
2971 | " 4.816941e-08 | \n",
2972 | " 1.346436e-07 | \n",
2973 | "
\n",
2974 | " \n",
2975 | "
\n",
2976 | "
5 rows × 31 columns
\n",
2977 | "
"
2978 | ],
2979 | "text/plain": [
2980 | " image_id antelope bat beaver bobcat \\\n",
2981 | "0 Img-5647.jpg 3.159350e-05 8.928788e-06 1.424190e-06 3.163671e-06 \n",
2982 | "1 Img-3230.jpg 9.999989e-01 4.410581e-10 7.409740e-09 3.252055e-07 \n",
2983 | "2 Img-4568.jpg 2.687980e-07 4.843321e-09 1.006783e-06 3.782131e-08 \n",
2984 | "3 Img-395.jpg 2.902317e-07 9.444283e-08 4.002781e-06 1.010353e-07 \n",
2985 | "4 Img-4449.jpg 1.123357e-08 1.097230e-07 1.032839e-06 9.813154e-08 \n",
2986 | "\n",
2987 | " buffalo chihuahua chimpanzee collie dalmatian \\\n",
2988 | "0 9.531980e-05 1.266143e-05 3.213432e-06 2.368384e-03 8.829939e-05 \n",
2989 | "1 3.372520e-09 1.509341e-08 9.406571e-10 4.785741e-08 3.069857e-07 \n",
2990 | "2 1.027670e-09 8.587640e-07 2.681424e-08 6.297764e-08 1.676035e-08 \n",
2991 | "3 1.339610e-05 5.511737e-06 2.670262e-04 1.743207e-06 2.048028e-06 \n",
2992 | "4 5.498913e-08 3.354518e-08 7.284951e-07 1.356309e-07 5.251192e-09 \n",
2993 | "\n",
2994 | " ... raccoon rat rhinoceros seal \\\n",
2995 | "0 ... 9.412486e-06 8.175143e-07 2.968850e-04 5.378051e-05 \n",
2996 | "1 ... 1.290144e-08 6.030067e-09 2.595238e-09 1.813413e-09 \n",
2997 | "2 ... 9.999946e-01 4.205262e-08 1.532161e-09 3.884408e-09 \n",
2998 | "3 ... 5.612122e-07 1.355699e-05 7.047990e-05 6.026975e-04 \n",
2999 | "4 ... 2.768773e-05 2.168487e-08 4.325886e-09 9.960676e-07 \n",
3000 | "\n",
3001 | " siamese+cat spider+monkey squirrel walrus weasel \\\n",
3002 | "0 5.613676e-05 3.570866e-05 1.254341e-05 7.219761e-06 7.715807e-06 \n",
3003 | "1 1.153833e-10 8.572713e-10 1.105912e-08 5.390022e-09 1.162741e-09 \n",
3004 | "2 2.434926e-09 2.533341e-08 1.814196e-06 8.880784e-09 6.122975e-07 \n",
3005 | "3 1.884430e-05 1.994449e-06 8.812417e-07 3.871692e-04 3.919969e-06 \n",
3006 | "4 1.121863e-08 7.563170e-06 9.999599e-01 1.503267e-09 4.816941e-08 \n",
3007 | "\n",
3008 | " wolf \n",
3009 | "0 1.594744e-05 \n",
3010 | "1 3.082452e-09 \n",
3011 | "2 3.280068e-08 \n",
3012 | "3 3.350742e-06 \n",
3013 | "4 1.346436e-07 \n",
3014 | "\n",
3015 | "[5 rows x 31 columns]"
3016 | ]
3017 | },
3018 | "metadata": {
3019 | "tags": []
3020 | },
3021 | "execution_count": 41
3022 | }
3023 | ]
3024 | },
3025 | {
3026 | "metadata": {
3027 | "id": "obR15EWTDhgZ",
3028 | "colab_type": "code",
3029 | "colab": {}
3030 | },
3031 | "cell_type": "code",
3032 | "source": [
3033 | "#make csv and zip it \n",
3034 | "SUBM = f'{PATH}sub/' \n",
3035 | "os.makedirs(SUBM, exist_ok=True) \n",
3036 | "df.to_csv(f'{SUBM}subm9.gz', compression='gzip', index=False)"
3037 | ],
3038 | "execution_count": 0,
3039 | "outputs": []
3040 | },
3041 | {
3042 | "metadata": {
3043 | "id": "kbVAqi1nDhbY",
3044 | "colab_type": "code",
3045 | "colab": {}
3046 | },
3047 | "cell_type": "code",
3048 | "source": [
3049 | "from google.colab import files\n",
3050 | "files.download(\"/content/clouderizer/fast.ai/data/sub/subm9.gz\")"
3051 | ],
3052 | "execution_count": 0,
3053 | "outputs": []
3054 | },
3055 | {
3056 | "metadata": {
3057 | "id": "NvkUPeOcDO9t",
3058 | "colab_type": "code",
3059 | "colab": {}
3060 | },
3061 | "cell_type": "code",
3062 | "source": [
3063 | "#---------------------------------------"
3064 | ],
3065 | "execution_count": 0,
3066 | "outputs": []
3067 | },
3068 | {
3069 | "metadata": {
3070 | "id": "45UZP-1ofGUw",
3071 | "colab_type": "code",
3072 | "outputId": "54a9abb6-4c0d-4c44-f7db-a4f21fdee1a8",
3073 | "colab": {
3074 | "base_uri": "https://localhost:8080/",
3075 | "height": 102
3076 | }
3077 | },
3078 | "cell_type": "code",
3079 | "source": [
3080 | "learn.fit(lr, 1)"
3081 | ],
3082 | "execution_count": 0,
3083 | "outputs": [
3084 | {
3085 | "output_type": "display_data",
3086 | "data": {
3087 | "application/vnd.jupyter.widget-view+json": {
3088 | "model_id": "9e148876049043189b63151780c6c38e",
3089 | "version_minor": 0,
3090 | "version_major": 2
3091 | },
3092 | "text/plain": [
3093 | "HBox(children=(IntProgress(value=0, description='Epoch', max=1), HTML(value='')))"
3094 | ]
3095 | },
3096 | "metadata": {
3097 | "tags": []
3098 | }
3099 | },
3100 | {
3101 | "output_type": "stream",
3102 | "text": [
3103 | "epoch trn_loss val_loss accuracy \n",
3104 | " 0 0.068419 0.004453 1.0 \n",
3105 | "\n"
3106 | ],
3107 | "name": "stdout"
3108 | },
3109 | {
3110 | "output_type": "execute_result",
3111 | "data": {
3112 | "text/plain": [
3113 | "[array([0.00445]), 1.0]"
3114 | ]
3115 | },
3116 | "metadata": {
3117 | "tags": []
3118 | },
3119 | "execution_count": 44
3120 | }
3121 | ]
3122 | },
3123 | {
3124 | "metadata": {
3125 | "id": "vvBQrNEgsAKs",
3126 | "colab_type": "code",
3127 | "colab": {}
3128 | },
3129 | "cell_type": "code",
3130 | "source": [
3131 | "learn.save('420_pree')\n",
3132 | "learn.load('420_pree')"
3133 | ],
3134 | "execution_count": 0,
3135 | "outputs": []
3136 | },
3137 | {
3138 | "metadata": {
3139 | "id": "Fq8rVpVES4Nw",
3140 | "colab_type": "text"
3141 | },
3142 | "cell_type": "markdown",
3143 | "source": [
3144 | "#After Training"
3145 | ]
3146 | },
3147 | {
3148 | "metadata": {
3149 | "id": "5NHaPMDJWN2q",
3150 | "colab_type": "text"
3151 | },
3152 | "cell_type": "markdown",
3153 | "source": [
3154 | "##Getting data to submit"
3155 | ]
3156 | },
3157 | {
3158 | "metadata": {
3159 | "id": "qGR6-EguquW6",
3160 | "colab_type": "code",
3161 | "outputId": "09ee306d-39d2-40df-cef6-abb53a737269",
3162 | "colab": {
3163 | "base_uri": "https://localhost:8080/",
3164 | "height": 17
3165 | }
3166 | },
3167 | "cell_type": "code",
3168 | "source": [
3169 | "log_preds, y = learn.TTA(is_test=True)"
3170 | ],
3171 | "execution_count": 0,
3172 | "outputs": [
3173 | {
3174 | "output_type": "stream",
3175 | "text": [
3176 | ""
3177 | ],
3178 | "name": "stdout"
3179 | }
3180 | ]
3181 | },
3182 | {
3183 | "metadata": {
3184 | "id": "2f8XosBtrDXQ",
3185 | "colab_type": "code",
3186 | "colab": {}
3187 | },
3188 | "cell_type": "code",
3189 | "source": [
3190 | "probs = np.mean(np.exp(log_preds),0)"
3191 | ],
3192 | "execution_count": 0,
3193 | "outputs": []
3194 | },
3195 | {
3196 | "metadata": {
3197 | "id": "BhTXTdLctj7i",
3198 | "colab_type": "code",
3199 | "outputId": "3fba7f0e-0068-4808-fd9f-3efeae23508b",
3200 | "colab": {
3201 | "base_uri": "https://localhost:8080/",
3202 | "height": 34
3203 | }
3204 | },
3205 | "cell_type": "code",
3206 | "source": [
3207 | "probs.shape"
3208 | ],
3209 | "execution_count": 0,
3210 | "outputs": [
3211 | {
3212 | "output_type": "execute_result",
3213 | "data": {
3214 | "text/plain": [
3215 | "(6000, 30)"
3216 | ]
3217 | },
3218 | "metadata": {
3219 | "tags": []
3220 | },
3221 | "execution_count": 47
3222 | }
3223 | ]
3224 | },
3225 | {
3226 | "metadata": {
3227 | "id": "_Q52VLhttjmm",
3228 | "colab_type": "code",
3229 | "colab": {}
3230 | },
3231 | "cell_type": "code",
3232 | "source": [
3233 | "df = pd.DataFrame(probs)\n",
3234 | "df.columns = data.classes"
3235 | ],
3236 | "execution_count": 0,
3237 | "outputs": []
3238 | },
3239 | {
3240 | "metadata": {
3241 | "id": "2M8eM-3_ufGg",
3242 | "colab_type": "code",
3243 | "colab": {}
3244 | },
3245 | "cell_type": "code",
3246 | "source": [
3247 | "df.insert(0, 'image_id', [o[5:-4] for o in data.test_ds.fnames])"
3248 | ],
3249 | "execution_count": 0,
3250 | "outputs": []
3251 | },
3252 | {
3253 | "metadata": {
3254 | "id": "LCqR969Nui3S",
3255 | "colab_type": "code",
3256 | "outputId": "ca69b0e7-53c6-40b1-b22f-f6ab9b207099",
3257 | "colab": {
3258 | "base_uri": "https://localhost:8080/",
3259 | "height": 338
3260 | }
3261 | },
3262 | "cell_type": "code",
3263 | "source": [
3264 | "df.head()"
3265 | ],
3266 | "execution_count": 0,
3267 | "outputs": [
3268 | {
3269 | "output_type": "execute_result",
3270 | "data": {
3271 | "text/html": [
3272 | "\n",
3273 | "\n",
3286 | "
\n",
3287 | " \n",
3288 | " \n",
3289 | " | \n",
3290 | " image_id | \n",
3291 | " antelope | \n",
3292 | " bat | \n",
3293 | " beaver | \n",
3294 | " bobcat | \n",
3295 | " buffalo | \n",
3296 | " chihuahua | \n",
3297 | " chimpanzee | \n",
3298 | " collie | \n",
3299 | " dalmatian | \n",
3300 | " ... | \n",
3301 | " raccoon | \n",
3302 | " rat | \n",
3303 | " rhinoceros | \n",
3304 | " seal | \n",
3305 | " siamese+cat | \n",
3306 | " spider+monkey | \n",
3307 | " squirrel | \n",
3308 | " walrus | \n",
3309 | " weasel | \n",
3310 | " wolf | \n",
3311 | "
\n",
3312 | " \n",
3313 | " \n",
3314 | " \n",
3315 | " | 0 | \n",
3316 | " Img-5647 | \n",
3317 | " 5.316023e-05 | \n",
3318 | " 3.883140e-06 | \n",
3319 | " 8.864310e-07 | \n",
3320 | " 5.036297e-07 | \n",
3321 | " 5.317185e-05 | \n",
3322 | " 6.992554e-06 | \n",
3323 | " 1.703840e-06 | \n",
3324 | " 7.796769e-03 | \n",
3325 | " 3.373071e-05 | \n",
3326 | " ... | \n",
3327 | " 3.003962e-06 | \n",
3328 | " 1.079518e-06 | \n",
3329 | " 5.940852e-05 | \n",
3330 | " 6.497854e-05 | \n",
3331 | " 7.006856e-06 | \n",
3332 | " 5.007122e-06 | \n",
3333 | " 1.381043e-05 | \n",
3334 | " 7.140030e-06 | \n",
3335 | " 6.290088e-06 | \n",
3336 | " 8.939817e-06 | \n",
3337 | "
\n",
3338 | " \n",
3339 | " | 1 | \n",
3340 | " Img-3230 | \n",
3341 | " 1.000000e+00 | \n",
3342 | " 1.562931e-10 | \n",
3343 | " 5.964725e-10 | \n",
3344 | " 1.941112e-08 | \n",
3345 | " 7.937418e-10 | \n",
3346 | " 1.104478e-08 | \n",
3347 | " 8.903778e-10 | \n",
3348 | " 6.634715e-09 | \n",
3349 | " 4.054542e-08 | \n",
3350 | " ... | \n",
3351 | " 2.050071e-09 | \n",
3352 | " 2.025541e-09 | \n",
3353 | " 7.023994e-10 | \n",
3354 | " 1.447848e-09 | \n",
3355 | " 1.249744e-10 | \n",
3356 | " 3.772094e-10 | \n",
3357 | " 4.312124e-09 | \n",
3358 | " 3.678966e-09 | \n",
3359 | " 3.786923e-10 | \n",
3360 | " 4.623049e-10 | \n",
3361 | "
\n",
3362 | " \n",
3363 | " | 2 | \n",
3364 | " Img-4568 | \n",
3365 | " 2.464635e-07 | \n",
3366 | " 3.461924e-09 | \n",
3367 | " 2.878338e-07 | \n",
3368 | " 7.212703e-08 | \n",
3369 | " 2.331194e-09 | \n",
3370 | " 4.699698e-06 | \n",
3371 | " 1.668912e-08 | \n",
3372 | " 1.040845e-07 | \n",
3373 | " 2.820643e-08 | \n",
3374 | " ... | \n",
3375 | " 9.999901e-01 | \n",
3376 | " 4.331356e-08 | \n",
3377 | " 4.257209e-09 | \n",
3378 | " 5.682838e-09 | \n",
3379 | " 5.741929e-09 | \n",
3380 | " 4.775297e-08 | \n",
3381 | " 2.498116e-06 | \n",
3382 | " 1.137850e-08 | \n",
3383 | " 1.029529e-06 | \n",
3384 | " 2.286205e-08 | \n",
3385 | "
\n",
3386 | " \n",
3387 | " | 3 | \n",
3388 | " Img-395 | \n",
3389 | " 2.333444e-06 | \n",
3390 | " 2.174487e-07 | \n",
3391 | " 9.582183e-07 | \n",
3392 | " 1.255184e-07 | \n",
3393 | " 1.866524e-05 | \n",
3394 | " 8.003702e-06 | \n",
3395 | " 1.147674e-04 | \n",
3396 | " 1.643990e-06 | \n",
3397 | " 1.079168e-05 | \n",
3398 | " ... | \n",
3399 | " 1.286151e-07 | \n",
3400 | " 5.902455e-06 | \n",
3401 | " 1.085797e-04 | \n",
3402 | " 8.845142e-04 | \n",
3403 | " 5.214484e-05 | \n",
3404 | " 1.413803e-06 | \n",
3405 | " 3.528847e-07 | \n",
3406 | " 3.425514e-02 | \n",
3407 | " 1.035389e-06 | \n",
3408 | " 1.650207e-06 | \n",
3409 | "
\n",
3410 | " \n",
3411 | " | 4 | \n",
3412 | " Img-4449 | \n",
3413 | " 1.239025e-08 | \n",
3414 | " 3.571765e-08 | \n",
3415 | " 2.042582e-06 | \n",
3416 | " 3.933425e-08 | \n",
3417 | " 5.096384e-08 | \n",
3418 | " 3.194642e-08 | \n",
3419 | " 3.507893e-07 | \n",
3420 | " 2.088610e-07 | \n",
3421 | " 7.279828e-09 | \n",
3422 | " ... | \n",
3423 | " 3.286292e-05 | \n",
3424 | " 3.809642e-08 | \n",
3425 | " 9.676155e-09 | \n",
3426 | " 2.271983e-06 | \n",
3427 | " 1.482867e-08 | \n",
3428 | " 1.288601e-05 | \n",
3429 | " 9.999371e-01 | \n",
3430 | " 2.057785e-09 | \n",
3431 | " 2.277810e-08 | \n",
3432 | " 9.102267e-08 | \n",
3433 | "
\n",
3434 | " \n",
3435 | "
\n",
3436 | "
5 rows × 31 columns
\n",
3437 | "
"
3438 | ],
3439 | "text/plain": [
3440 | " image_id antelope bat beaver bobcat \\\n",
3441 | "0 Img-5647 5.316023e-05 3.883140e-06 8.864310e-07 5.036297e-07 \n",
3442 | "1 Img-3230 1.000000e+00 1.562931e-10 5.964725e-10 1.941112e-08 \n",
3443 | "2 Img-4568 2.464635e-07 3.461924e-09 2.878338e-07 7.212703e-08 \n",
3444 | "3 Img-395 2.333444e-06 2.174487e-07 9.582183e-07 1.255184e-07 \n",
3445 | "4 Img-4449 1.239025e-08 3.571765e-08 2.042582e-06 3.933425e-08 \n",
3446 | "\n",
3447 | " buffalo chihuahua chimpanzee collie dalmatian \\\n",
3448 | "0 5.317185e-05 6.992554e-06 1.703840e-06 7.796769e-03 3.373071e-05 \n",
3449 | "1 7.937418e-10 1.104478e-08 8.903778e-10 6.634715e-09 4.054542e-08 \n",
3450 | "2 2.331194e-09 4.699698e-06 1.668912e-08 1.040845e-07 2.820643e-08 \n",
3451 | "3 1.866524e-05 8.003702e-06 1.147674e-04 1.643990e-06 1.079168e-05 \n",
3452 | "4 5.096384e-08 3.194642e-08 3.507893e-07 2.088610e-07 7.279828e-09 \n",
3453 | "\n",
3454 | " ... raccoon rat rhinoceros seal \\\n",
3455 | "0 ... 3.003962e-06 1.079518e-06 5.940852e-05 6.497854e-05 \n",
3456 | "1 ... 2.050071e-09 2.025541e-09 7.023994e-10 1.447848e-09 \n",
3457 | "2 ... 9.999901e-01 4.331356e-08 4.257209e-09 5.682838e-09 \n",
3458 | "3 ... 1.286151e-07 5.902455e-06 1.085797e-04 8.845142e-04 \n",
3459 | "4 ... 3.286292e-05 3.809642e-08 9.676155e-09 2.271983e-06 \n",
3460 | "\n",
3461 | " siamese+cat spider+monkey squirrel walrus weasel \\\n",
3462 | "0 7.006856e-06 5.007122e-06 1.381043e-05 7.140030e-06 6.290088e-06 \n",
3463 | "1 1.249744e-10 3.772094e-10 4.312124e-09 3.678966e-09 3.786923e-10 \n",
3464 | "2 5.741929e-09 4.775297e-08 2.498116e-06 1.137850e-08 1.029529e-06 \n",
3465 | "3 5.214484e-05 1.413803e-06 3.528847e-07 3.425514e-02 1.035389e-06 \n",
3466 | "4 1.482867e-08 1.288601e-05 9.999371e-01 2.057785e-09 2.277810e-08 \n",
3467 | "\n",
3468 | " wolf \n",
3469 | "0 8.939817e-06 \n",
3470 | "1 4.623049e-10 \n",
3471 | "2 2.286205e-08 \n",
3472 | "3 1.650207e-06 \n",
3473 | "4 9.102267e-08 \n",
3474 | "\n",
3475 | "[5 rows x 31 columns]"
3476 | ]
3477 | },
3478 | "metadata": {
3479 | "tags": []
3480 | },
3481 | "execution_count": 50
3482 | }
3483 | ]
3484 | },
3485 | {
3486 | "metadata": {
3487 | "id": "edxN3ZZjus8e",
3488 | "colab_type": "code",
3489 | "colab": {}
3490 | },
3491 | "cell_type": "code",
3492 | "source": [
3493 | "#make csv and zip it \n",
3494 | "SUBM = f'{PATH}sub/' \n",
3495 | "os.makedirs(SUBM, exist_ok=True) \n",
3496 | "df.to_csv(f'{SUBM}subm10.gz', compression='gzip', index=False)"
3497 | ],
3498 | "execution_count": 0,
3499 | "outputs": []
3500 | },
3501 | {
3502 | "metadata": {
3503 | "id": "hDm3r8dQvZJO",
3504 | "colab_type": "code",
3505 | "outputId": "95a6a9ec-954a-4f25-a9fc-596f577c270b",
3506 | "colab": {
3507 | "base_uri": "https://localhost:8080/",
3508 | "height": 34
3509 | }
3510 | },
3511 | "cell_type": "code",
3512 | "source": [
3513 | "FileLink(f'{SUBM}subm4.gz') # download file"
3514 | ],
3515 | "execution_count": 0,
3516 | "outputs": [
3517 | {
3518 | "output_type": "execute_result",
3519 | "data": {
3520 | "text/html": [
3521 | "/content/clouderizer/fast.ai/data/sub/subm.gz
"
3522 | ],
3523 | "text/plain": [
3524 | "/content/clouderizer/fast.ai/data/sub/subm.gz"
3525 | ]
3526 | },
3527 | "metadata": {
3528 | "tags": []
3529 | },
3530 | "execution_count": 104
3531 | }
3532 | ]
3533 | },
3534 | {
3535 | "metadata": {
3536 | "id": "T6_Z5fgYFSoA",
3537 | "colab_type": "text"
3538 | },
3539 | "cell_type": "markdown",
3540 | "source": [
3541 | "### 1"
3542 | ]
3543 | },
3544 | {
3545 | "metadata": {
3546 | "id": "gDQKjFXsEA16",
3547 | "colab_type": "code",
3548 | "colab": {}
3549 | },
3550 | "cell_type": "code",
3551 | "source": [
3552 | "img = plt.imread('/content/clouderizer/fast.ai/fastai/courses/dl1/data1/competitions/dog-breed-identification/test/68cfc459e57429b1f8b6372fa1363a60.jpg')\n",
3553 | "plt.imshow(img);"
3554 | ],
3555 | "execution_count": 0,
3556 | "outputs": []
3557 | },
3558 | {
3559 | "metadata": {
3560 | "id": "aMwTDbgTG83m",
3561 | "colab_type": "code",
3562 | "colab": {}
3563 | },
3564 | "cell_type": "code",
3565 | "source": [
3566 | "trn_tfms, val_tfms = tfms_from_model(arch, sz)"
3567 | ],
3568 | "execution_count": 0,
3569 | "outputs": []
3570 | },
3571 | {
3572 | "metadata": {
3573 | "id": "mrPaavRFrUy4",
3574 | "colab_type": "code",
3575 | "outputId": "b61096f3-7854-45ff-83fd-3a3bcb9b4af4",
3576 | "colab": {
3577 | "base_uri": "https://localhost:8080/",
3578 | "height": 36
3579 | }
3580 | },
3581 | "cell_type": "code",
3582 | "source": [
3583 | "im = val_tfms(open_image('/content/clouderizer/fast.ai/fastai/courses/dl1/data1/competitions/dog-breed-identification/test/68cfc459e57429b1f8b6372fa1363a60.jpg'))\n",
3584 | " \n",
3585 | "preds = learn.predict_array(im[None])\n",
3586 | "\n",
3587 | "np.argmax(preds)"
3588 | ],
3589 | "execution_count": 0,
3590 | "outputs": [
3591 | {
3592 | "output_type": "execute_result",
3593 | "data": {
3594 | "text/plain": [
3595 | "79"
3596 | ]
3597 | },
3598 | "metadata": {
3599 | "tags": []
3600 | },
3601 | "execution_count": 224
3602 | }
3603 | ]
3604 | },
3605 | {
3606 | "metadata": {
3607 | "id": "9xJ-UIy8DxeS",
3608 | "colab_type": "text"
3609 | },
3610 | "cell_type": "markdown",
3611 | "source": [
3612 | "### 2"
3613 | ]
3614 | },
3615 | {
3616 | "metadata": {
3617 | "id": "V6HTPYynD63e",
3618 | "colab_type": "code",
3619 | "outputId": "15650411-01d6-471b-882b-28f65b87b010",
3620 | "colab": {
3621 | "base_uri": "https://localhost:8080/",
3622 | "height": 36
3623 | }
3624 | },
3625 | "cell_type": "code",
3626 | "source": [
3627 | "fn = data.val_ds.fnames[10]; fn\n",
3628 | "\n"
3629 | ],
3630 | "execution_count": 0,
3631 | "outputs": [
3632 | {
3633 | "output_type": "execute_result",
3634 | "data": {
3635 | "text/plain": [
3636 | "'train/00cc68a50b2d016a6b29af628ea4e04b.jpg'"
3637 | ]
3638 | },
3639 | "metadata": {
3640 | "tags": []
3641 | },
3642 | "execution_count": 243
3643 | }
3644 | ]
3645 | },
3646 | {
3647 | "metadata": {
3648 | "id": "YFw-gL5HGY2O",
3649 | "colab_type": "code",
3650 | "colab": {}
3651 | },
3652 | "cell_type": "code",
3653 | "source": [
3654 | "#Image.open(PATH + fn)\n",
3655 | "open_image\n",
3656 | "img = plt.imread(PATH + fn)\n",
3657 | "plt.imshow(img);"
3658 | ],
3659 | "execution_count": 0,
3660 | "outputs": []
3661 | },
3662 | {
3663 | "metadata": {
3664 | "id": "JuzShX1bD6oI",
3665 | "colab_type": "code",
3666 | "colab": {}
3667 | },
3668 | "cell_type": "code",
3669 | "source": [
3670 | "trn_tfms, val_tfms = tfms_from_model(arch, sz)"
3671 | ],
3672 | "execution_count": 0,
3673 | "outputs": []
3674 | },
3675 | {
3676 | "metadata": {
3677 | "id": "0iTo7liVD6Rs",
3678 | "colab_type": "code",
3679 | "outputId": "c1d41e35-a324-47c6-cb81-096e2ef1f8d1",
3680 | "colab": {
3681 | "base_uri": "https://localhost:8080/",
3682 | "height": 36
3683 | }
3684 | },
3685 | "cell_type": "code",
3686 | "source": [
3687 | "im = val_tfms(open_image(PATH+fn))\n",
3688 | " \n",
3689 | "preds = learn.predict_array(im[None])\n",
3690 | "\n",
3691 | "np.argmax(preds)"
3692 | ],
3693 | "execution_count": 0,
3694 | "outputs": [
3695 | {
3696 | "output_type": "execute_result",
3697 | "data": {
3698 | "text/plain": [
3699 | "67"
3700 | ]
3701 | },
3702 | "metadata": {
3703 | "tags": []
3704 | },
3705 | "execution_count": 245
3706 | }
3707 | ]
3708 | },
3709 | {
3710 | "metadata": {
3711 | "id": "zpE5v4C3jNSC",
3712 | "colab_type": "text"
3713 | },
3714 | "cell_type": "markdown",
3715 | "source": [
3716 | "## Download data to pc through google drive & syncronization"
3717 | ]
3718 | },
3719 | {
3720 | "metadata": {
3721 | "id": "K4XDQ8PdjCkO",
3722 | "colab_type": "code",
3723 | "colab": {}
3724 | },
3725 | "cell_type": "code",
3726 | "source": [
3727 | "from google.colab import files\n",
3728 | "files.download(\"/content/clouderizer/fast.ai/data/sub/subm10.gz\")"
3729 | ],
3730 | "execution_count": 0,
3731 | "outputs": []
3732 | }
3733 | ]
3734 | }
--------------------------------------------------------------------------------