In [2]:
%matplotlib inline
In [3]:
path = "data/dogscats-redux/"
In [4]:
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 [5]:
import utils; reload(utils)
from utils import plots
In [6]:
batch_size=64
In [7]:
# Import our class, and instantiate
import vgg16; reload(vgg16)
from vgg16 import Vgg16
In [8]:
vgg = Vgg16()
In [9]:
batches = vgg.get_batches(path+'train', batch_size=4)
In [10]:
imgs,labels = next(batches)
plots(imgs, titles=labels)
In [11]:
vgg.predict(imgs, True)
Out[11]:
In [12]:
vgg.finetune(batches)
In [13]:
val_batches = vgg.get_batches(path+'valid', batch_size=batch_size)
In [14]:
vgg.fit(batches, val_batches, nb_epoch=1)
In [15]:
vgg.predict(imgs, True)
Out[15]:
In [32]:
batches = vgg.get_batches(path+'train', batch_size=32, shuffle=False)
imgs,labels = next(batches)
results = vgg.predict(imgs, True)
In [33]:
plots(imgs[0:4], titles=labels[0:4])
In [41]:
batches, preds = vgg.test(path+'test', batch_size = 32)
In [44]:
#Save our test results arrays so we can use them again later
filenames = batches.filenames
np.save(path + 'test_preds.dat', preds)
np.save(path + 'filenames.dat', filenames)
In [49]:
preds
Out[49]:
In [59]:
batches.filenames
ids = np.array([int(f[7:f.find('.')]) for f in filenames])
print(ids[:5])
print(filenames[:5])
In [63]:
isdog = preds[:,1]
In [64]:
subm = np.stack([ids,isdog], axis=1)
subm[:5]
Out[64]:
In [65]:
np.savetxt(path+'submission.csv', subm, fmt='%d,%.5f', header='id,label', comments='')
In [ ]: