Dogs vs Cats with vgg16

Setup


In [1]:
%matplotlib inline

Path to training and test data


In [13]:
#path = "data/dogscats/"
path = "data/dogscats/sample/"

In [3]:
from __future__ import division, print_function
import os, json
from glob import glob
import numpy as np
np.set_printoptions(precision=4, linewidth=100)
from matplotlib import pyplot as plt

In [4]:
import utils; reload(utils)
from utils import plots


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:
 https://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end%28gpuarray%29

Using gpu device 0: Tesla K80 (CNMeM is disabled, cuDNN 5103)
Using Theano backend.

Vgg16 for basic image recognition


In [7]:
import vgg16; reload(vgg16)
from vgg16 import Vgg16

In [9]:
vgg = Vgg16()

In [10]:
batch_size = 64

In [14]:
batches = vgg.get_batches(path + "train", batch_size=batch_size)
val_batches = vgg.get_batches(path + "valid", batch_size=batch_size)


Found 160 images belonging to 2 classes.
Found 40 images belonging to 2 classes.

finetune() modifies the model so that it will be trained based on the batched data provided (cat or dog)


In [15]:
vgg.finetune(batches)

fit() the parameters of the model using the training data


In [16]:
vgg.fit(batches, val_batches, nb_epoch=1)


Epoch 1/1
160/160 [==============================] - 10s - loss: 1.1810 - acc: 0.5687 - val_loss: 0.2176 - val_acc: 0.8750

In [ ]: