Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: fastai/courses
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: nambrot/courses
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Aug 2, 2017

  1. Copy the full SHA
    ae0681f View commit details
Showing with 193 additions and 0 deletions.
  1. +193 −0 deeplearning1/nbs/catsvdogs.ipynb
193 changes: 193 additions & 0 deletions deeplearning1/nbs/catsvdogs.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Create Submission for Dogs v Cats"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING (theano.sandbox.cuda): The cuda backend is deprecated and will be removed in the next release (v0.10). Please switch to the gpuarray backend. You can get more information about how to switch at this URL:\n",
" https://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end%28gpuarray%29\n",
"\n",
"WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu is not available (error: Unable to get the number of gpus available: CUDA driver version is insufficient for CUDA runtime version)\n",
"Using Theano backend.\n"
]
}
],
"source": [
"\n",
"from __future__ import division,print_function\n",
"\n",
"import os, json\n",
"from glob import glob\n",
"import numpy as np\n",
"np.set_printoptions(precision=4, linewidth=100)\n",
"from matplotlib import pyplot as plt\n",
"import utils; reload(utils)\n",
"from utils import plots\n",
"\n",
"path = \"/home/docker/fastai/data/dogscats/sample/\"\n",
"batch_size=64\n",
"training_epochs=100"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Found 16 images belonging to 2 classes.\n",
"Found 8 images belonging to 2 classes.\n"
]
}
],
"source": [
"import vgg16; reload(vgg16)\n",
"from vgg16 import Vgg16\n",
"vgg = Vgg16()\n",
"# Grab a few images at a time for training and validation.\n",
"# NB: They must be in subdirectories named based on their category\n",
"batches = vgg.get_batches(path+'train', batch_size=batch_size)\n",
"val_batches = vgg.get_batches(path+'valid', batch_size=batch_size*2)\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING (theano.configdefaults): install mkl with `conda install mkl-service`: No module named mkl\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Epoch 1/1\n",
"16/16 [==============================] - 10s - loss: 1.0448 - acc: 0.5625 - val_loss: 0.4350 - val_acc: 0.7500\n"
]
}
],
"source": [
"vgg.finetune(batches)\n",
"vgg.fit(batches, val_batches, nb_epoch=training_epochs)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Found 12500 images belonging to 1 classes.\n"
]
}
],
"source": [
"test_batches = vgg.get_batches('/home/docker/fastai/data/dogscats/test', shuffle=False, batch_size=batch_size, class_mode=None)\n",
"preds = vgg.model.predict_generator(test_batches, test_batches.nb_sample)\n",
"ids = [int(f[8:f.find('.')]) for f in test_batches.filenames]\n",
"np.savetxt(\n",
" '/home/docker/fastai/data/dogscats/predictions.csv',\n",
" np.stack([ids[:64], preds[:, 1]], axis=1),\n",
" fmt='%d,%.5f',\n",
" header='id,label')"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 9.9282e-01, 3.7662e-02, 1.2637e-01, 9.1407e-01, 9.8101e-01, 3.2519e-03,\n",
" 1.4810e-01, 9.2504e-01, 9.7665e-01, 1.2542e-01, 4.2551e-01, 4.7124e-02,\n",
" 3.8424e-03, 9.5007e-05, 1.9337e-03, 9.2162e-01, 4.3270e-01, 1.0448e-01,\n",
" 2.5918e-03, 4.0333e-01, 9.9630e-01, 1.2269e-02, 1.8081e-02, 1.3105e-01,\n",
" 9.5527e-03, 9.0018e-01, 3.5744e-02, 7.2640e-02, 9.3611e-01, 9.9815e-01,\n",
" 9.9639e-01, 6.0718e-01, 8.8965e-01, 6.8264e-01, 6.1572e-02, 6.9096e-01,\n",
" 7.2765e-01, 9.9822e-01, 1.1135e-02, 1.0433e-01, 4.3059e-02, 6.4779e-01,\n",
" 6.5410e-01, 8.1530e-01, 4.7941e-01, 8.3378e-01, 9.4393e-01, 7.4797e-01,\n",
" 2.1743e-03, 9.5461e-01, 8.9325e-02, 8.4831e-01, 3.7092e-02, 4.6873e-01,\n",
" 4.6222e-01, 9.9916e-01, 9.6830e-01, 4.1478e-01, 1.4131e-01, 1.1278e-02,\n",
" 2.5148e-04, 5.2522e-02, 9.1643e-01, 3.6839e-02], dtype=float32)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}