Skip to content

Instantly share code, notes, and snippets.

@Trion129
Created November 13, 2017 05:57
Show Gist options
  • Save Trion129/97c67af77725ee6130f6963dc5ad5163 to your computer and use it in GitHub Desktop.
Save Trion129/97c67af77725ee6130f6963dc5ad5163 to your computer and use it in GitHub Desktop.
Me trying to learn Transfer Learning using Inception :-)
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import cv2\n",
"import numpy as np\n",
"from tqdm import tqdm\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>id</th>\n",
" <th>breed</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>000bec180eb18c7604dcecc8fe0dba07</td>\n",
" <td>boston_bull</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>001513dfcb2ffafc82cccf4d8bbaba97</td>\n",
" <td>dingo</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>001cdf01b096e06d78e9e5112d419397</td>\n",
" <td>pekinese</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>00214f311d5d2247d5dfe4fe24b2303d</td>\n",
" <td>bluetick</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0021f9ceb3235effd7fcde7f7538ed62</td>\n",
" <td>golden_retriever</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" id breed\n",
"0 000bec180eb18c7604dcecc8fe0dba07 boston_bull\n",
"1 001513dfcb2ffafc82cccf4d8bbaba97 dingo\n",
"2 001cdf01b096e06d78e9e5112d419397 pekinese\n",
"3 00214f311d5d2247d5dfe4fe24b2303d bluetick\n",
"4 0021f9ceb3235effd7fcde7f7538ed62 golden_retriever"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.read_csv('../input/labels.csv')\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"n = len(df)\n",
"breed = set(df['breed'])\n",
"n_class = len(breed)\n",
"class_to_num = dict(zip(breed, range(n_class)))\n",
"num_to_class = dict(zip(range(n_class), breed))\n",
"width = 299"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"X = np.zeros((n, width, width, 3), dtype=np.uint8)\n",
"y = np.zeros((n, n_class), dtype=np.uint8)\n",
"for i in range(n):\n",
" X[i] = cv2.resize(cv2.imread('../input/train/%s.jpg' % df['id'][i]), (width, width))\n",
" y[i][class_to_num[df['breed'][i]]] = 1"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
@Trion129
Copy link
Author

😛 Final Predictions are so wrong and uncomparable to human ability.... But this simple thingy still got 0.59 logloss hmmm.... Machine learning is Strange

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment