Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
b2ec17a2a1 | |||
15cda53bad | |||
2c09f8d00e | |||
3e33585f11 | |||
443e1976bb | |||
0c99fbc020 | |||
![]() |
31680f6fa0 | ||
![]() |
c09d8849c9 | ||
![]() |
82e7f75686 |
21
README.md
21
README.md
@@ -95,21 +95,28 @@ keras project.
|
|||||||
python setup.py install
|
python setup.py install
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also rebuild the hdf5 files from scratch by running the
|
You can also rebuild the hdf5 files from scratch by running
|
||||||
`kero-download` and `kero-convert` scripts, which are currently
|
`fuel-download` and `fuel-convert` with updated settings for
|
||||||
part of the kerosene installation. For example:
|
`EXTRA_DOWNLOADERS` and `EXTRA_CONVERTERS`.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
kero-download lfw_fuel/lfw.py
|
FUEL_EXTRA_DOWNLOADERS="lfw_fuel" fuel-download lfw
|
||||||
kero-convert lfw_fuel/lfw.py
|
FUEL_EXTRA_CONVERTERS="lfw_fuel" fuel-convert lfw
|
||||||
```
|
```
|
||||||
|
|
||||||
This will convert the original version of lfw, but funneled and
|
This will convert the original version of lfw, but funneled and
|
||||||
deepfunneled formats are also supported:
|
deepfunneled formats are also supported:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
kero-download lfw_fuel/lfw.py --format deepfunneled
|
FUEL_EXTRA_DOWNLOADERS="lfw_fuel" fuel-download lfw --format deepfunneled
|
||||||
kero-convert lfw_fuel/lfw.py --format deepfunneled
|
FUEL_EXTRA_CONVERTERS="lfw_fuel" fuel-convert lfw --format deepfunneled
|
||||||
|
```
|
||||||
|
|
||||||
|
These settings can also be set in the `~/.fuelrc` file:
|
||||||
|
|
||||||
|
```
|
||||||
|
extra_downloaders: ['lfw_fuel']
|
||||||
|
extra_converters: ['lfw_fuel']
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
@@ -5,7 +5,7 @@ np.random.seed(1337) # for reproducibility
|
|||||||
|
|
||||||
from keras.models import Sequential
|
from keras.models import Sequential
|
||||||
from keras.layers.core import Dense, Dropout, Activation, Flatten
|
from keras.layers.core import Dense, Dropout, Activation, Flatten
|
||||||
from keras.layers.convolutional import Convolution2D, MaxPooling2D
|
from keras.layers.convolutional import Conv2D, MaxPooling2D
|
||||||
from keras.utils import np_utils
|
from keras.utils import np_utils
|
||||||
from scipy.misc import imresize
|
from scipy.misc import imresize
|
||||||
|
|
||||||
@@ -37,8 +37,8 @@ def cropImage(im):
|
|||||||
# the data, shuffled and split between train and test sets
|
# the data, shuffled and split between train and test sets
|
||||||
(X_train, y_train), (X_test, y_test) = lfw.load_data("deepfunneled")
|
(X_train, y_train), (X_test, y_test) = lfw.load_data("deepfunneled")
|
||||||
# crop features
|
# crop features
|
||||||
X_train = np.asarray(map(cropImage, X_train))
|
X_train = np.asarray(list(map(cropImage, X_train)))
|
||||||
X_test = np.asarray(map(cropImage, X_test))
|
X_test = np.asarray(list(map(cropImage, X_test)))
|
||||||
|
|
||||||
# print shape of data while model is building
|
# print shape of data while model is building
|
||||||
print("{1} train samples, {2} channel{0}, {3}x{4}".format("" if X_train.shape[1] == 1 else "s", *X_train.shape))
|
print("{1} train samples, {2} channel{0}, {3}x{4}".format("" if X_train.shape[1] == 1 else "s", *X_train.shape))
|
||||||
@@ -50,24 +50,24 @@ Y_test = np_utils.to_categorical(y_test, nb_classes)
|
|||||||
|
|
||||||
model = Sequential()
|
model = Sequential()
|
||||||
|
|
||||||
model.add(Convolution2D(32, 6, 3, 3, border_mode='full'))
|
model.add(Conv2D(32, (3,3), input_shape=(6,32,32), padding='valid'))
|
||||||
model.add(Activation('relu'))
|
model.add(Activation('relu'))
|
||||||
model.add(Convolution2D(32, 32, 3, 3))
|
model.add(Conv2D(32, (3,3), input_shape=(6,32,32), padding='valid'))
|
||||||
model.add(Activation('relu'))
|
model.add(Activation('relu'))
|
||||||
model.add(MaxPooling2D(poolsize=(2, 2)))
|
model.add(MaxPooling2D(pool_size=(2, 2)))
|
||||||
model.add(Dropout(0.25))
|
model.add(Dropout(0.25))
|
||||||
|
|
||||||
model.add(Flatten())
|
model.add(Flatten())
|
||||||
model.add(Dense(feature_width*feature_height*8, 128))
|
model.add(Dense(128))
|
||||||
model.add(Activation('relu'))
|
model.add(Activation('relu'))
|
||||||
model.add(Dropout(0.5))
|
model.add(Dropout(0.5))
|
||||||
|
|
||||||
model.add(Dense(128, nb_classes))
|
model.add(Dense(nb_classes))
|
||||||
model.add(Activation('softmax'))
|
model.add(Activation('softmax'))
|
||||||
|
|
||||||
model.compile(loss='categorical_crossentropy', optimizer='adadelta')
|
model.compile(loss='categorical_crossentropy', metrics=['binary_accuracy'], optimizer='adadelta')
|
||||||
|
|
||||||
model.fit(X_train, Y_train, batch_size=batch_size, nb_epoch=nb_epoch, show_accuracy=True, verbose=1, validation_data=(X_test, Y_test))
|
model.fit(X_train, Y_train, batch_size=batch_size, epochs=nb_epoch, verbose=1, validation_data=(X_test, Y_test))
|
||||||
score = model.evaluate(X_test, Y_test, show_accuracy=True, verbose=0)
|
score = model.evaluate(X_test, Y_test, verbose=0)
|
||||||
print('Test score:', score[0])
|
print('Test score:', score[0])
|
||||||
print('Test accuracy:', score[1])
|
print('Test accuracy:', score[1])
|
||||||
|
@@ -0,0 +1,4 @@
|
|||||||
|
from lfw_fuel import lfw
|
||||||
|
|
||||||
|
all_downloaders = (('lfw', lfw.download_subparser),)
|
||||||
|
all_converters = (('lfw', lfw.convert_subparser),)
|
||||||
|
@@ -51,7 +51,7 @@ def resolve_filename(format):
|
|||||||
def downloader_wrapper(format, directory, **kwargs):
|
def downloader_wrapper(format, directory, **kwargs):
|
||||||
# add the right format file to the download list
|
# add the right format file to the download list
|
||||||
files.insert(0, "{}.tgz".format(resolve_filename(format)))
|
files.insert(0, "{}.tgz".format(resolve_filename(format)))
|
||||||
urls = map(lambda s: 'http://vis-www.cs.umass.edu/lfw/' + s, files)
|
urls = list(map(lambda s: 'http://vis-www.cs.umass.edu/lfw/' + s, files))
|
||||||
default_downloader(directory, urls=urls, filenames=files, **kwargs)
|
default_downloader(directory, urls=urls, filenames=files, **kwargs)
|
||||||
|
|
||||||
# this subparser hook is used for briq-download
|
# this subparser hook is used for briq-download
|
||||||
@@ -67,9 +67,9 @@ def download_subparser(subparser):
|
|||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
"--format", help="alternate format", type=str, default=None)
|
"--format", help="alternate format", type=str, default=None)
|
||||||
|
|
||||||
urls = map(lambda s: 'http://vis-www.cs.umass.edu/lfw/' + s, files)
|
urls = list(map(lambda s: 'http://vis-www.cs.umass.edu/lfw/' + s, files))
|
||||||
|
|
||||||
subparser.set_defaults(func=downloader_wrapper)
|
return downloader_wrapper
|
||||||
|
|
||||||
|
|
||||||
########### Convert section ##############
|
########### Convert section ##############
|
||||||
@@ -121,9 +121,9 @@ def convert_lfw(directory, basename, output_directory):
|
|||||||
|
|
||||||
print("--> Building test/train lists")
|
print("--> Building test/train lists")
|
||||||
# build lists, throwing away heading
|
# build lists, throwing away heading
|
||||||
with open('pairsDevTrain.txt', 'rb') as csvfile:
|
with open('pairsDevTrain.txt', 'r') as csvfile:
|
||||||
trainrows = list(csv.reader(csvfile, delimiter='\t'))[1:]
|
trainrows = list(csv.reader(csvfile, delimiter='\t'))[1:]
|
||||||
with open('pairsDevTest.txt', 'rb') as csvfile:
|
with open('pairsDevTest.txt', 'r') as csvfile:
|
||||||
testrows = list(csv.reader(csvfile, delimiter='\t'))[1:]
|
testrows = list(csv.reader(csvfile, delimiter='\t'))[1:]
|
||||||
|
|
||||||
print("--> Converting")
|
print("--> Converting")
|
||||||
@@ -131,8 +131,8 @@ def convert_lfw(directory, basename, output_directory):
|
|||||||
train_images = load_images("train", tar, tar_subdir, trainrows)
|
train_images = load_images("train", tar, tar_subdir, trainrows)
|
||||||
test_images = load_images("test", tar, tar_subdir, testrows)
|
test_images = load_images("test", tar, tar_subdir, testrows)
|
||||||
|
|
||||||
train_labels = np.array(map(lambda r:loadLabelsFromRow(r), trainrows))
|
train_labels = np.array(list(map(lambda r:loadLabelsFromRow(r), trainrows)))
|
||||||
test_labels = np.array(map(lambda r:loadLabelsFromRow(r), testrows))
|
test_labels = np.array(list(map(lambda r:loadLabelsFromRow(r), testrows)))
|
||||||
|
|
||||||
train_features = np.array([[f[0,:,:,0], f[0,:,:,1], f[0,:,:,2], f[1,:,:,0], f[1,:,:,1], f[1,:,:,2]] for f in train_images])
|
train_features = np.array([[f[0,:,:,0], f[0,:,:,1], f[0,:,:,2], f[1,:,:,0], f[1,:,:,1], f[1,:,:,2]] for f in train_images])
|
||||||
test_features = np.array([[f[0,:,:,0], f[0,:,:,1], f[0,:,:,2], f[1,:,:,0], f[1,:,:,1], f[1,:,:,2]] for f in test_images])
|
test_features = np.array([[f[0,:,:,0], f[0,:,:,1], f[0,:,:,2], f[1,:,:,0], f[1,:,:,1], f[1,:,:,2]] for f in test_images])
|
||||||
@@ -173,7 +173,7 @@ def convert_subparser(subparser):
|
|||||||
# optional format can be funneled, deepfunneled, etc
|
# optional format can be funneled, deepfunneled, etc
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
"--format", help="alternate format", type=str, default=None)
|
"--format", help="alternate format", type=str, default=None)
|
||||||
subparser.set_defaults(func=convert_lfw_wrapper)
|
return convert_lfw_wrapper
|
||||||
|
|
||||||
|
|
||||||
########### Fuel Dataset section ##############
|
########### Fuel Dataset section ##############
|
||||||
|
2
setup.py
2
setup.py
@@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
from setuptools import find_packages
|
from setuptools import find_packages
|
||||||
|
|
||||||
setup(name='lfw_fuel',
|
setup(name='lfw_fuel',
|
||||||
version='0.1.0',
|
version='0.1.1',
|
||||||
description='Labeled Faces in the Wild fuel dataset',
|
description='Labeled Faces in the Wild fuel dataset',
|
||||||
author='Tom White',
|
author='Tom White',
|
||||||
author_email='tom@sixdozen.com',
|
author_email='tom@sixdozen.com',
|
||||||
|
Reference in New Issue
Block a user