{"nbformat": 4, "cells": [{"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", "\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": {"_cell_guid": "979340d0-15bd-4cd5-bedb-998914e60657", "_uuid": "8436dc3fda9093492124e79d1829c4235f1bf9db"}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["from glob import glob\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "import tensorflow as tf\n", "\n", "labels = pd.read_csv(\"../input/labels.csv\")\n", "submi = pd.read_csv(\"../input/sample_submission.csv\")\n", "#getting the all the files\n", "data = pd.DataFrame([{'path': filepath} for filepath in glob(\"../input/train/*.jpg\")])\n"], "metadata": {"_cell_guid": "95f43064-c07c-4b9b-ab46-1a759b07529c", "_uuid": "c08e9682499b6797671f1eda1308fd4ec3a8c950"}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["df = pd.DataFrame()\n", "#reading all the files and converting into matrix form\n", "df['id'] = pd.DataFrame(data['path'].apply(lambda x : x.split('/')[-1].split('.')[0]))\n", "df['value'] = pd.DataFrame(data['path'].apply(lambda x :plt.imread(str(x))))\n"], "metadata": {"_cell_guid": "c8650d0c-44b7-4cad-8fb9-f40d6a483946", "_uuid": "7733f16b4dc00548cec113407cf2002847d983eb", "collapsed": true}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["df.head()"], "metadata": {"_cell_guid": "dc2a2783-9c40-43ac-aa1a-27ed8401f33f", "_uuid": "adf3a8e35354ff4f2ebba7611e42a9b4eda7f210"}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["#Getting Breed against Dog id\n", "df['Breed'] = None\n", "for i in range(len(df['id'])):\n", "    df['Breed'].iloc[i] =  labels[labels['id']== df['id'].iloc[i]]['breed'].any()"], "metadata": {"_cell_guid": "65f7e25e-3a5f-4c2b-aeb2-785a71781701", "_uuid": "997f736c0753eab9c41364bed058d1f7c99f879d", "collapsed": true}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["df.head()"], "metadata": {"_cell_guid": "0cf9b83c-f160-4295-89fb-a2750a103ed2", "_uuid": "0bd834d0107b0957165932c4f93188e2065f66fa"}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["df['value'][0].shape"], "metadata": {}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["(df['value'][0].flatten().reshape(194,237,3)).shape"], "metadata": {}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["# Ftattening the Dataframe into a single array (194 x 237 x 3) = 137934 \n", "194*237 = 45978 for red,  45978 for green, 45978 for blue channel"], "metadata": {}, "cell_type": "markdown"}, {"source": ["df['value'] = df['value'].apply(lambda x : x.flatten())"], "metadata": {}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["df.head()"], "metadata": {}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["# Normalising the data diving it with 255\n", "\n", "pixels = df['value'].values/255.0\n"], "metadata": {}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["# Plotting couple of images"], "metadata": {"_cell_guid": "f1e2bd64-7d85-4a18-9aec-2491d744e0ff", "_uuid": "5b2e18157f6b08eab319d7c9759a1dc4ad0f73cb"}, "cell_type": "markdown"}, {"source": ["plt.figure(figsize=(14,10))\n", "a,b = 3,3\n", "for i in range(0,(a*b)):\n", "    #getting random index\n", "    rand_ind = np.random.randint(0,len(df), size= a*b)\n", "    plt.subplot(a,b, i+1)\n", "    plt.imshow(df['value'].iloc[rand_ind[i]])\n", "    plt.title(df['Breed'].iloc[rand_ind[i]])"], "metadata": {"_cell_guid": "d6d27b6c-458c-4473-8818-9e9f744b256a", "_uuid": "51c0a960f3fb314700c8a4689ce7e74465cfc86e"}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["# Normalising the  data"], "metadata": {"_cell_guid": "b791c04f-f30b-4048-9944-8f9101d487a2", "_uuid": "145dfa934056e7fb0e776176e6079554aefa1e6d"}, "cell_type": "markdown"}, {"source": ["t=[]\n", "for i in range(len(df['value'])):\n", "    t.append(df['value'].iloc[i]/255.0)u"], "metadata": {"_cell_guid": "a6ea02ca-e9ee-4089-a756-bce5fa34ed1e", "_uuid": "083555625660adfe66fdd89540a5c57cff7a83b1", "collapsed": true}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["#df['value'].values/255.0"], "metadata": {"_cell_guid": "4d229bc9-d135-4d3f-82cd-cd3a476e2789", "_uuid": "2832298add36b59be2b1cd54458af5dca907a0f3", "collapsed": true}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": [], "metadata": {"_cell_guid": "33f8d37c-ff3f-4f5a-8b67-27f84992328d", "_uuid": "3d8e0bebc57ddb2e5c661b7666f8e861b63b0ed4", "collapsed": true}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": [], "metadata": {"_cell_guid": "20f92266-097d-44d8-ae60-7671ae915c27", "_uuid": "6efea784987f38860147f354abfaa5a25ff505f9", "collapsed": true}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": [], "metadata": {"_cell_guid": "705165dd-66f6-48de-9110-997aa10cca3a", "_uuid": "c4bba23c14b6fbae6eeb0bddf2e3c319719c3e3d", "collapsed": true}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": [], "metadata": {"_cell_guid": "8d29938d-2c14-48ee-866f-4caca8b38b73", "_uuid": "2ff14b072c4dd95d1735f21efbb20b5b39d20b7d", "collapsed": true}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": [], "metadata": {"_cell_guid": "d4bd218e-c4d7-46c3-8cb1-898cd8c2fc67", "_uuid": "4b8fec16612e273dd0d6e6c89b27e9c520672fe5", "collapsed": true}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["data.head(7)"], "metadata": {"_cell_guid": "1822b4c2-ba87-47cb-823c-475d8812a74b", "_uuid": "a340824f27b86acdc19238ce8be486c33fcc6190", "collapsed": true}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": [], "metadata": {"_cell_guid": "2a21ddee-225a-402a-b615-6165df3cdb52", "_uuid": "ffa75f331fdd4f39024b49ca2f5ab3ce15f1ea86", "collapsed": true}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["plt.imshow(df['path'][0])"], "metadata": {"_cell_guid": "9ec1b3e0-39fa-476e-bc6c-1502af019cc7", "_uuid": "976347c6881e8326755ff8754f6effabd27059b4", "collapsed": true}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["data['id'] = data['path'].apply(lambda x : x.split('/')[-1].split('.')[0]) "], "metadata": {"_cell_guid": "8d278a80-264d-4cb6-b20e-e5253c35e24e", "_uuid": "86048701e84c2cbacb5272d35656aca9b130711b", "collapsed": true}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": ["data.head()"], "metadata": {"_cell_guid": "138fadb2-0182-4d31-87e9-6cbf61e0f24c", "_uuid": "05b9614d2c187b6760db705e6f3db0139de48154", "collapsed": true}, "execution_count": null, "cell_type": "code", "outputs": []}, {"source": [], "metadata": {"_cell_guid": "6f334dbd-402a-431f-b5c8-faa30353cc11", "_uuid": "eeac5cc0b2d128a73ffdfeae0ff7cc7908572825", "collapsed": true}, "execution_count": null, "cell_type": "code", "outputs": []}], "nbformat_minor": 1, "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "3.6.3", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython3", "codemirror_mode": {"version": 3, "name": "ipython"}}}}