{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Dogs breeds\n", "\n", "https://youtu.be/JNxcznsrRb8?t=1h31m8s" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%reload_ext autoreload\n", "%autoreload 2\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from fastai.imports import *\n", "from fastai.torch_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 *" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "torch.cuda.set_device(0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Kaggle Dog Breed Identification. Get data from https://www.kaggle.com/c/dog-breed-identification" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "PATH = \"data/dogbreed/\"\n", "sz = 224\n", "arch = resnext101_64\n", "bs = 58" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "label_csv = f'{PATH}labels.csv'\n", "n = len(list(open(label_csv))) - 1 # header is not counted (-1)\n", "val_idxs = get_cv_idxs(n) # random 20% data for validation set" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10222" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2044" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(val_idxs)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# If you haven't downloaded weights.tgz yet, download the file.\n", "# http://forums.fast.ai/t/error-when-trying-to-use-resnext50/7555\n", "# http://forums.fast.ai/t/lesson-2-in-class-discussion/7452/222\n", "#!wget -O fastai/weights.tgz http://files.fast.ai/models/weights.tgz\n", "\n", "#!tar xvfz fastai/weights.tgz -C fastai" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Initial exploration" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "info.txt sample_submission.csv test tmp train.zip\r\n", "labels.csv subm\t\t test.zip train\r\n" ] } ], "source": [ "!ls {PATH}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "label_df = pd.read_csv(label_csv)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | id | \n", "breed | \n", "
---|---|---|
0 | \n", "000bec180eb18c7604dcecc8fe0dba07 | \n", "boston_bull | \n", "
1 | \n", "001513dfcb2ffafc82cccf4d8bbaba97 | \n", "dingo | \n", "
2 | \n", "001cdf01b096e06d78e9e5112d419397 | \n", "pekinese | \n", "
3 | \n", "00214f311d5d2247d5dfe4fe24b2303d | \n", "bluetick | \n", "
4 | \n", "0021f9ceb3235effd7fcde7f7538ed62 | \n", "golden_retriever | \n", "
\n", " | id | \n", "
---|---|
breed | \n", "\n", " |
scottish_deerhound | \n", "126 | \n", "
maltese_dog | \n", "117 | \n", "
afghan_hound | \n", "116 | \n", "
entlebucher | \n", "115 | \n", "
bernese_mountain_dog | \n", "114 | \n", "
shih-tzu | \n", "112 | \n", "
great_pyrenees | \n", "111 | \n", "
pomeranian | \n", "111 | \n", "
basenji | \n", "110 | \n", "
samoyed | \n", "109 | \n", "
airedale | \n", "107 | \n", "
tibetan_terrier | \n", "107 | \n", "
leonberg | \n", "106 | \n", "
cairn | \n", "106 | \n", "
beagle | \n", "105 | \n", "
japanese_spaniel | \n", "105 | \n", "
australian_terrier | \n", "102 | \n", "
blenheim_spaniel | \n", "102 | \n", "
miniature_pinscher | \n", "102 | \n", "
irish_wolfhound | \n", "101 | \n", "
lakeland_terrier | \n", "99 | \n", "
saluki | \n", "99 | \n", "
papillon | \n", "96 | \n", "
whippet | \n", "95 | \n", "
siberian_husky | \n", "95 | \n", "
norwegian_elkhound | \n", "95 | \n", "
pug | \n", "94 | \n", "
chow | \n", "93 | \n", "
italian_greyhound | \n", "92 | \n", "
pembroke | \n", "92 | \n", "
... | \n", "... | \n", "
german_short-haired_pointer | \n", "75 | \n", "
boxer | \n", "75 | \n", "
bull_mastiff | \n", "75 | \n", "
borzoi | \n", "75 | \n", "
pekinese | \n", "75 | \n", "
cocker_spaniel | \n", "74 | \n", "
american_staffordshire_terrier | \n", "74 | \n", "
doberman | \n", "74 | \n", "
brittany_spaniel | \n", "73 | \n", "
malinois | \n", "73 | \n", "
standard_schnauzer | \n", "72 | \n", "
flat-coated_retriever | \n", "72 | \n", "
redbone | \n", "72 | \n", "
border_collie | \n", "72 | \n", "
curly-coated_retriever | \n", "72 | \n", "
kuvasz | \n", "71 | \n", "
chihuahua | \n", "71 | \n", "
soft-coated_wheaten_terrier | \n", "71 | \n", "
french_bulldog | \n", "70 | \n", "
vizsla | \n", "70 | \n", "
tibetan_mastiff | \n", "69 | \n", "
german_shepherd | \n", "69 | \n", "
giant_schnauzer | \n", "69 | \n", "
walker_hound | \n", "69 | \n", "
otterhound | \n", "69 | \n", "
golden_retriever | \n", "67 | \n", "
brabancon_griffon | \n", "67 | \n", "
komondor | \n", "67 | \n", "
briard | \n", "66 | \n", "
eskimo_dog | \n", "66 | \n", "
120 rows × 1 columns
\n", "\n", " | id | \n", "affenpinscher | \n", "afghan_hound | \n", "african_hunting_dog | \n", "airedale | \n", "american_staffordshire_terrier | \n", "appenzeller | \n", "australian_terrier | \n", "basenji | \n", "basset | \n", "... | \n", "toy_poodle | \n", "toy_terrier | \n", "vizsla | \n", "walker_hound | \n", "weimaraner | \n", "welsh_springer_spaniel | \n", "west_highland_white_terrier | \n", "whippet | \n", "wire-haired_fox_terrier | \n", "yorkshire_terrier | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "ab2520c527e61f197be228208af48191 | \n", "7.957505e-08 | \n", "2.723862e-08 | \n", "2.435847e-08 | \n", "1.173262e-07 | \n", "2.351215e-08 | \n", "8.401931e-06 | \n", "1.372760e-06 | \n", "6.317406e-08 | \n", "3.063393e-08 | \n", "... | \n", "2.080939e-08 | \n", "2.456473e-07 | \n", "2.722122e-07 | \n", "5.030101e-08 | \n", "1.900935e-07 | \n", "6.053991e-07 | \n", "3.839476e-08 | \n", "5.778787e-08 | \n", "1.575098e-07 | \n", "1.075539e-08 | \n", "
1 | \n", "8ffc8a83bb9ac7884a9420c97b23940c | \n", "9.668808e-08 | \n", "2.355516e-08 | \n", "2.087995e-07 | \n", "6.298836e-08 | \n", "3.269388e-08 | \n", "2.796247e-07 | \n", "2.439702e-08 | \n", "2.535878e-06 | \n", "1.824919e-06 | \n", "... | \n", "4.051576e-08 | \n", "3.540100e-06 | \n", "2.388073e-07 | \n", "9.832689e-01 | \n", "1.823956e-07 | \n", "2.486797e-08 | \n", "8.325348e-08 | \n", "9.363868e-07 | \n", "2.608415e-07 | \n", "3.851193e-07 | \n", "
2 | \n", "9f4bbcd8a5b189514d3098516983621a | \n", "4.214103e-05 | \n", "2.804878e-04 | \n", "4.817631e-05 | \n", "7.178330e-03 | \n", "1.471457e-06 | \n", "1.140446e-05 | \n", "1.950280e-04 | \n", "7.519415e-06 | \n", "1.821058e-06 | \n", "... | \n", "5.793181e-05 | \n", "9.164357e-05 | \n", "1.187949e-04 | \n", "6.772134e-06 | \n", "5.031822e-05 | \n", "4.772470e-05 | \n", "6.114125e-06 | \n", "2.762433e-05 | \n", "5.382648e-04 | \n", "2.682866e-05 | \n", "
3 | \n", "f77793be1597dd1ea50b22532b38bd23 | \n", "2.568105e-07 | \n", "2.491144e-07 | \n", "7.142457e-07 | \n", "1.466020e-06 | \n", "3.212435e-05 | \n", "8.274229e-08 | \n", "3.600422e-08 | \n", "6.044879e-08 | \n", "1.201969e-07 | \n", "... | \n", "2.627351e-06 | \n", "3.965855e-08 | \n", "1.560448e-06 | \n", "6.965169e-08 | \n", "1.856623e-07 | \n", "1.051336e-07 | \n", "1.763770e-07 | \n", "2.664481e-07 | \n", "3.316928e-08 | \n", "9.700193e-08 | \n", "
4 | \n", "f719b425410b6eb3e3132702150affd6 | \n", "6.095974e-06 | \n", "2.696717e-06 | \n", "4.131879e-06 | \n", "6.457446e-05 | \n", "1.191631e-03 | \n", "3.560664e-05 | \n", "3.274512e-06 | \n", "2.229157e-06 | \n", "1.317608e-06 | \n", "... | \n", "2.345266e-06 | \n", "1.053057e-05 | \n", "2.322353e-05 | \n", "4.169483e-05 | \n", "1.918868e-05 | \n", "5.647749e-06 | \n", "5.437289e-06 | \n", "5.297930e-06 | \n", "3.867970e-06 | \n", "5.011518e-06 | \n", "
5 rows × 121 columns
\n", "