{"metadata": {"language_info": {"file_extension": ".py", "codemirror_mode": {"name": "ipython", "version": 3}, "pygments_lexer": "ipython3", "name": "python", "nbconvert_exporter": "python", "mimetype": "text/x-python", "version": "3.6.3"}, "kernelspec": {"language": "python", "display_name": "Python 3", "name": "python3"}}, "nbformat_minor": 1, "cells": [{"metadata": {"_uuid": "ae0df6a520487e080515d7a76cf955d095b483c0", "_cell_guid": "499ebdfb-fede-4ba2-9ff4-067292f9a865"}, "cell_type": "code", "outputs": [], "execution_count": null, "source": ["# This Python 3 environment comes with many helpful analytics libraries installed\n", "# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n", "# For example, here's several helpful packages to load in \n", "\n", "import numpy as np # linear algebra\n", "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n", "from random import randint\n", "from tqdm import tqdm\n", "import cv2\n", "import matplotlib.pyplot as plt\n", "# Input data files are available in the \"../input/\" directory.\n", "# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n", "\n", "from subprocess import check_output\n", "print(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n", "\n", "# Any results you write to the current directory are saved as output."]}, {"metadata": {"_uuid": "598ecef55dd7ea2d05b9130be0819cb21932ef42", "_cell_guid": "fb24deb7-b58c-40ed-8670-718c78a77297"}, "cell_type": "markdown", "source": ["***Load CSV-File with pandas and print the first ten rows***"]}, {"metadata": {"_uuid": "8a9e1edb957ac7a7706a2248902f87ca8b39bc0f", "_cell_guid": "1a219277-cf22-4d2d-84cf-3b421f591913"}, "cell_type": "code", "outputs": [], "execution_count": null, "source": ["df_train = pd.read_csv(\"../input/labels.csv\")\n", "df_train.head(10)\n"]}, {"metadata": {"_uuid": "d41536607ab5486cba4beaf9f0e93798065af702", "_cell_guid": "52de0fd9-a626-4980-a474-7ae7d00b9a30"}, "cell_type": "markdown", "source": ["***Visualize trainingsdata distribution***"]}, {"metadata": {"_uuid": "d6266f5fcdb58edf9f78ca9dac4050495ed92932", "_cell_guid": "a589c755-c23c-41b2-b4b0-95397a5a2149", "scrolled": false}, "cell_type": "code", "outputs": [], "execution_count": null, "source": ["ax=pd.value_counts(df_train['breed'],ascending=True).plot(kind='barh',\n", "                                                       fontsize=\"40\",\n", "                                                       title=\"Class Distribution\",\n", "                                                       figsize=(50,100))\n", "ax.set(xlabel=\"Images per class\", ylabel=\"Classes\")\n", "ax.xaxis.label.set_size(40)\n", "ax.yaxis.label.set_size(40)\n", "ax.title.set_size(60)\n"]}, {"metadata": {"_uuid": "1babc26e0d0a1f10ed40d342db378b06ad55d0d8", "_cell_guid": "b1150326-4ad8-4835-8042-c3ae6c38f4c1"}, "cell_type": "markdown", "source": ["***Plot example  training images***\n", "\n"]}, {"metadata": {"_uuid": "470155510b860ca5df799579604f2c16b18ee516", "_cell_guid": "4727d247-7a49-432d-9496-8758be028264"}, "cell_type": "markdown", "source": ["***Helper-function for plotting images***\n", "\n", "[Reference](https://github.com/Hvass-Labs/TensorFlow-Tutorials)"]}, {"metadata": {"_uuid": "2beabc5637359f977b784e607a33bcfb79e44193", "_cell_guid": "ce5b56e1-f9d3-4d5a-9dac-8567921d26e9", "collapsed": true}, "cell_type": "code", "outputs": [], "execution_count": null, "source": ["def plot_images(images, classes):\n", "    assert len(images) == len(classes) == 9\n", "    \n", "    # Create figure with 3x3 sub-plots.\n", "    fig, axes = plt.subplots(3, 3,figsize=(60,60),sharex=True)\n", "    fig.subplots_adjust(hspace=0.3, wspace=0.3)\n", "   \n", "    for i, ax in enumerate(axes.flat):\n", "        # Plot image.\n", "        \n", "        ax.imshow(cv2.cvtColor(images[i], cv2.COLOR_BGR2RGB).reshape(img_width,img_height,3), cmap='hsv')    \n", "        xlabel = \"Breed: {0}\".format(classes[i])\n", "    \n", "        # Show the classes as the label on the x-axis.\n", "        ax.set_xlabel(xlabel)\n", "        ax.xaxis.label.set_size(60)\n", "        # Remove ticks from the plot.\n", "        ax.set_xticks([])\n", "        ax.set_yticks([])\n", "    \n", "    # Ensure the plot is shown correctly with multiple plots\n", "    # in a single Notebook cell.\n", "    \n", "    plt.show()"]}, {"metadata": {"_uuid": "e9a23a1858b115b6260c0bb419234db8d4741d87", "_cell_guid": "a280db79-ce8f-4742-9ee4-599f1769f397"}, "cell_type": "markdown", "source": ["***Load trainingsdata***"]}, {"metadata": {"_uuid": "f41baaf90b16b8957a86a847aa98f723c520655d", "_cell_guid": "a55f656a-1af1-4ee1-814d-86f984692f7f"}, "cell_type": "code", "outputs": [], "execution_count": null, "source": ["img_width=250\n", "img_height=250\n", "images=[]\n", "classes=[]\n", "#load training images\n", "for f, breed in tqdm(df_train.values):\n", "    img = cv2.imread('../input/train/{}.jpg'.format(f))\n", "    classes.append(breed)\n", "    images.append(cv2.resize(img, (img_width, img_height)))"]}, {"metadata": {"_uuid": "ae67ce24433159dad5f3ea5d16d0e1c3e504932c", "_cell_guid": "78666aef-0728-4dd0-a601-2792fac909ba"}, "cell_type": "markdown", "source": ["***Plot some example images***"]}, {"metadata": {"_uuid": "f9c8f2ac1b6feab999464e3f64c90bf49e8e25b1", "_cell_guid": "8bd8db60-26f5-4b28-92e8-6ae1f34b124e"}, "cell_type": "code", "outputs": [], "execution_count": null, "source": ["\n", "# select random images\n", "random_numbers = [randint(0, len(images)) for p in range(0,9)]\n", "images_to_show = [images[i] for i in random_numbers]\n", "classes_to_show = [classes[i] for i in random_numbers]\n", "print(\"Images to show: {0}\".format(len(images_to_show)))\n", "print(\"Classes to show: {0}\".format(len(classes_to_show)))\n", "\n", "#plot the images\n", "plot_images(images_to_show, classes_to_show)\n", "   "]}], "nbformat": 4}