In [3]:
%matplotlib inline
In [11]:
##For sample data
path = "data/distracted-driving/sample/"
results_path = 'distracted-driving-results/sample'
##For full data
#path = "data/distracted-driving/"
#results_path = 'distracted-driving-results/sample'
In [5]:
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 [6]:
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 [17]:
batches, preds = vgg.test(path+'test', batch_size = 32)
In [18]:
#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 [12]:
#Load our test predictions from file
preds = np.load(path + '/test_preds.dat.npy')
filenames = np.load(path + '/filenames.dat.npy')
In [13]:
preds
Out[13]:
In [20]:
file_ids = np.array([f[7:] for f in filenames])
file_ids.T
Out[20]:
In [18]:
import pandas as pd
df = pd.DataFrame(data=preds, columns=['c0','c1','c2','c3','c4','c5','c6','c7','c8','c9'])
df.head()
Out[18]:
In [24]:
filename_series = pd.Series(file_ids)
df['img'] = filename_series
cols = df.columns.tolist()
cols = cols[-1:] + cols[:-1]
df = df[cols]
df.head()
Out[24]:
In [26]:
df.to_csv('submission.csv', index=False)
In [ ]: