{"cells":[{"metadata":{},"cell_type":"markdown","source":"# <span style=\"font-family:Trebuchet MS; font-size:2em;\">Generative Dog Images</span>\n\n<img src=\"https://thehappypuppysite.com/wp-content/uploads/2018/07/how-long-do-golden-retrievers-live-KH-long.jpg\" alt=\"https://thehappypuppysite.com/wp-content/uploads/2018/07/how-long-do-golden-retrievers-live-KH-long.jpg\" style=\"width: 600px;\" title=\"Golden\" align=\"middle\"/>\n\n## <span style=\"font-family:Papyrus; font-size:1em;\">Experiment with creating puppy pics</span>"},{"metadata":{},"cell_type":"markdown","source":"# Table of Content\n* [General information](#General-information)\n* [Visualisation of pictures](#Visualisation-of-pictures)\n* [Breeds of dogs](#Breeds-of-dogs)\n* [Local conclusion](#Local-conclusion)"},{"metadata":{},"cell_type":"markdown","source":"# General information\n* **Task:** to generate pictures of dogs with about $20k$ different pictures of dogs given. \"This ~~person~~ ~~rental~~ ~~vessel~~ ~~waifu~~ ~~[etc.](https://thisxdoesnotexist.com/)~~ **dog** does not exist\".\n\n* **Data:** the data is [Stanford Dogs Dataset](http://vision.stanford.edu/aditya86/ImageNetDogs/) built from ImageNet. But, one of $20580$ images doesn't include, so we have $20579$.\n    * 120 dog breeds, from 148 to 252 photos per breed, with 75% quantile equal to 186 photos per breed.\n    * Format of pictures name: `ImageNet `[`synset`](https://en.wikipedia.org/wiki/Synonym_ring)` _ some number`. E.g. `n02090721_42` -- [Irish Wolfhound](https://en.wikipedia.org/wiki/Irish_wolfhound), picture with index 42.\n    * Here is a [poster](http://vision.stanford.edu/documents/KhoslaJayadevaprakashYaoFeiFei_FGVC2011.pdf)  of a dataset.\n* **Metric:** the metric is MiFID (Memorization-informed Fréchet Inception Distance). Explanation on the [forum](https://www.kaggle.com/c/generative-dog-images/discussion/97809#latest-564085) or in the [overview]((https://www.kaggle.com/c/generative-dog-images/overview/evaluation)).\n* [Kaggle overview](https://www.kaggle.com/c/generative-dog-images/overview)\n\n[To table of Content](#Table-of-Content)\n***"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"# import\nimport os\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nimport seaborn as sns\n%matplotlib inline\nplt.style.use('ggplot')\nnp.random.seed(2)\n\n\nimport keras\nprint(keras.backend.tensorflow_backend._get_available_gpus())\nprint(keras.backend.image_data_format()) # set_image_data_format('channels_first')\n\nimport warnings\nwarnings.filterwarnings('ignore')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Visualisation of pictures"},{"metadata":{},"cell_type":"markdown","source":"Interesting data facts are:\n\n* There are pictures with more than one dog (even with $3$ dogs);\n* There are pictures with the dog (-s) and person (people);\n* There are pictures with more than one person (even with $4$ people);\n* There are pictures where dogs occupy less than $1/5$ of the picture;\n\n* There are pictures with text (magazine covers, from dog shows, memes and pictures with text);\n* Even wild predators included, e.g. [African wild dog](https://en.wikipedia.org/wiki/African_wild_dog) or [Dingo](https://en.wikipedia.org/wiki/Dingo), but not wolves.\n\n\nLet's visualize $9$ random pictures of a given dataset."},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"PATH = '../input/all-dogs/all-dogs/'\nPATH_LIST = os.listdir(PATH)\nprint(f'There are #{len(os.listdir(PATH))} pictures of dogs.')\n\nfig, axes = plt.subplots(nrows=3, ncols=3, figsize=(12,10))\n\nfor indx, axis in enumerate(axes.flatten()):\n    rnd_indx = np.random.randint(0, len(os.listdir(PATH)))\n    # https://matplotlib.org/users/image_tutorial.html\n    img = plt.imread(PATH + PATH_LIST[rnd_indx])\n    imgplot = axis.imshow(img)\n    axis.set_title(PATH_LIST[rnd_indx])\n    axis.set_axis_off()\nplt.tight_layout(rect=[0, 0.03, 1, 0.95])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"[To table of Content](#Table-of-Content)\n***"},{"metadata":{},"cell_type":"markdown","source":"# Breeds of dogs"},{"metadata":{},"cell_type":"markdown","source":"<style type=\"text/css\">\n.tg  {border-collapse:collapse;border-spacing:0;}\n.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}\n.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}\n.tg .tg-ntt9{background-color:#ffffff;color:#ffffff;border-color:#ffffff;text-align:left;vertical-align:top}\n.tg .tg-sv5y{background-color:#ffffff;color:#ffffff;border-color:#ffffff;text-align:left}\n</style>\n<table class=\"tg\">\n  <tr>\n    <th class=\"tg-sv5y\">\n      <a href=\"http://vision.stanford.edu/aditya86/ImageNetDogs/n02090622.html\">\n        <img src=\"https://i.pinimg.com/originals/91/37/80/9137801911ac107b252532cb19ef2470.gif\" alt=\"Borzoi\" style=\"width: 120px;\"   title=\"Borzoi\"/>\n    </a>  </th>\n    <th class=\"tg-sv5y\"><a href=\"http://vision.stanford.edu/aditya86/ImageNetDogs/n02113799.html\">\n<img src=\"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTS2VVaklPQVwMlt5ugBZJ1bUftdKMsMkJha_cIVJlIzDAgjkcw\" alt=\"Standard poodle\" style=\"width: 90px;\" title=\"Standard poodle\"/>\n</a></th>\n    <th class=\"tg-ntt9\"><a href=\"http://vision.stanford.edu/aditya86/ImageNetDogs/n02111500.html\">\n<img src=\"https://i.pinimg.com/originals/60/22/c1/6022c1255e5ee2af51e94b6eff00c2c6.png\" alt=\"Great Pyrenees\" style=\"width: 160px;\" title=\"Great Pyrenees\"/></th>\n    <th class=\"tg-ntt9\"><a href=\"http://vision.stanford.edu/aditya86/ImageNetDogs/n02102973.html\">\n<img src=\"https://rlv.zcache.ca/irish_water_spaniel_silhouette_trucker_hat-r9e97977e1b594be8be6764f36a99600b_eahvn_8byvr_307.jpg?rvtype=content\" alt=\"Irish water spaniel\" style=\"width: 130px;\" title=\"Irish water spaniel\"/>\n</a></th>\n    <th class=\"tg-ntt9\"><a href=\"http://vision.stanford.edu/aditya86/ImageNetDogs/n02106166.html\">\n<img src=\"https://img2.embroiderypatterns.com/StockDesign/XLarge/King_Graphics/ed0858.jpg\" alt=\"Border collie\" style=\"width: 150px;\" title=\"Border collie\"/>\n</a></th>\n    <th class=\"tg-ntt9\"><a href=\"http://vision.stanford.edu/aditya86/ImageNetDogs/n02106662.html\">\n<img src=\"https://www.publicdomainpictures.net/pictures/60000/nahled/dog-german-shepherd-silhouette.jpg\" alt=\"German shepherd\" style=\"width: 180px;\" title=\"German shepherd\"/>\n</a></th>\n  </tr>\n</table>"},{"metadata":{},"cell_type":"markdown","source":"* **Silhouettes upper are clickable**. A right-click opens the [ImageNetDogs](http://vision.stanford.edu/aditya86/ImageNetDogs/) page with pictures of this breed.\n* There are $120$ **different by size, hairiness and other body characteristics** breeds of dogs.\n* Lower you can see some visualization of photo distribution of breeds."},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"from collections import defaultdict\nby_breeds_dict = defaultdict(list)\nfor breed_code_and_pict_indx in PATH_LIST:\n    breed_code, pict_indx = breed_code_and_pict_indx.split('_')\n    by_breeds_dict[breed_code].append(pict_indx) ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"df_aux = pd.DataFrame.from_dict(by_breeds_dict, orient='index').T\nprint(f'There are {df_aux.shape[1]} breeds')\n\nfig = plt.figure(figsize=(12, 6))\nfig.suptitle('Distribution of number of photos per breed')\nfig.add_subplot(121)\nsns.boxplot(df_aux.shape[0] - df_aux.isnull().sum())\nplt.xlabel('# of photos')\n#plt.xticks([])\nfig.add_subplot(122)\nsns.distplot(df_aux.shape[0] - df_aux.isnull().sum())\nplt.tight_layout(rect=[0, 0.03, 1, 0.95])\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"[To table of Content](#Table-of-Content)\n***"},{"metadata":{},"cell_type":"markdown","source":"# Local conclusion\n**Maybe knowledge of breeds features, distribution of photos and visual analysis of pictures may help in this task of an image generation.**  \n\n_Also, it is possible to get poses estimation and number of dogs per some pictures from the [ImageNetDogs](http://vision.stanford.edu/aditya86/ImageNetDogs/) page, but the question is it qualifies as External data (\"No external data can be added as a data source\" and \"C. External Data. You may use data other than the Competition Data (“External Data”) to develop and test your models and Submissions...\")_"},{"metadata":{},"cell_type":"markdown","source":"[To table of Content](#Table-of-Content)\n***"},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}