Created
October 5, 2017 08:15
-
-
Save ypwhs/59814dd8decf0bd2833fc993d51e0efa to your computer and use it in GitHub Desktop.
Keras Inception + Xception (0.47)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "# 载入数据集" | |
| ] | |
| }, | |
| { | |
| "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('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))" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "100%|██████████| 10222/10222 [00:27<00:00, 374.48it/s]\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "width = 299\n", | |
| "X = np.zeros((n, width, width, 3), dtype=np.uint8)\n", | |
| "y = np.zeros((n, n_class), dtype=np.uint8)\n", | |
| "for i in tqdm(range(n)):\n", | |
| " X[i] = cv2.resize(cv2.imread('train/%s.jpg' % df['id'][i]), (width, width))\n", | |
| " y[i][class_to_num[df['breed'][i]]] = 1" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "# 数据集可视化" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment