Created
May 6, 2017 13:02
-
-
Save charlesreid1/5d764ad9e3942197dd89ffa8e49ea6f5 to your computer and use it in GitHub Desktop.
fuel + lfw_fuel configuration for Python 2 or Python 3 compatibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data_path: "/Users/charles/fuel_data" | |
floatX : "float32" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python2 run-lfw.py | |
Using TensorFlow backend. | |
2200 train samples, 6 channels, 32x32 | |
1000 test samples, 6 channels, 32x32 | |
Train on 2200 samples, validate on 1000 samples | |
Epoch 1/12 | |
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. | |
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. | |
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. | |
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. | |
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. | |
2200/2200 [==============================] - 1s - loss: 0.6943 - binary_accuracy: 0.4877 - val_loss: 0.6929 - val_binary_accuracy: 0.4990 | |
Epoch 2/12 | |
2200/2200 [==============================] - 1s - loss: 0.6919 - binary_accuracy: 0.5027 - val_loss: 0.6928 - val_binary_accuracy: 0.5010 | |
Epoch 3/12 | |
2200/2200 [==============================] - 1s - loss: 0.6913 - binary_accuracy: 0.5191 - val_loss: 0.6931 - val_binary_accuracy: 0.4840 | |
Epoch 4/12 | |
2200/2200 [==============================] - 1s - loss: 0.6902 - binary_accuracy: 0.5250 - val_loss: 0.6929 - val_binary_accuracy: 0.4870 | |
Epoch 5/12 | |
2200/2200 [==============================] - 1s - loss: 0.6900 - binary_accuracy: 0.5205 - val_loss: 0.6932 - val_binary_accuracy: 0.4990 | |
Epoch 6/12 | |
2200/2200 [==============================] - 1s - loss: 0.6887 - binary_accuracy: 0.5255 - val_loss: 0.6933 - val_binary_accuracy: 0.4960 | |
Epoch 7/12 | |
2200/2200 [==============================] - 1s - loss: 0.6884 - binary_accuracy: 0.5232 - val_loss: 0.6935 - val_binary_accuracy: 0.4960 | |
Epoch 8/12 | |
2200/2200 [==============================] - 1s - loss: 0.6861 - binary_accuracy: 0.5336 - val_loss: 0.6937 - val_binary_accuracy: 0.4910 | |
Epoch 9/12 | |
2200/2200 [==============================] - 1s - loss: 0.6853 - binary_accuracy: 0.5268 - val_loss: 0.6936 - val_binary_accuracy: 0.4860 | |
Epoch 10/12 | |
2200/2200 [==============================] - 1s - loss: 0.6829 - binary_accuracy: 0.5564 - val_loss: 0.6941 - val_binary_accuracy: 0.4830 | |
Epoch 11/12 | |
2200/2200 [==============================] - 1s - loss: 0.6827 - binary_accuracy: 0.5455 - val_loss: 0.6941 - val_binary_accuracy: 0.4960 | |
Epoch 12/12 | |
2200/2200 [==============================] - 1s - loss: 0.6797 - binary_accuracy: 0.5495 - val_loss: 0.6946 - val_binary_accuracy: 0.4900 | |
Test score: 0.694578546047 | |
Test accuracy: 0.49 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python3 run-lfw.py | |
Using TensorFlow backend. | |
2200 train samples, 6 channels, 32x32 | |
1000 test samples, 6 channels, 32x32 | |
Train on 2200 samples, validate on 1000 samples | |
Epoch 1/12 | |
2017-05-06 05:46:21.839092: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. | |
2017-05-06 05:46:21.839142: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. | |
2017-05-06 05:46:21.839147: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. | |
2017-05-06 05:46:21.839152: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. | |
2017-05-06 05:46:21.839156: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. | |
2200/2200 [==============================] - 1s - loss: 0.6943 - binary_accuracy: 0.4859 - val_loss: 0.6929 - val_binary_accuracy: 0.4980 | |
Epoch 2/12 | |
2200/2200 [==============================] - 1s - loss: 0.6918 - binary_accuracy: 0.5041 - val_loss: 0.6928 - val_binary_accuracy: 0.5000 | |
Epoch 3/12 | |
2200/2200 [==============================] - 1s - loss: 0.6913 - binary_accuracy: 0.5173 - val_loss: 0.6931 - val_binary_accuracy: 0.4820 | |
Epoch 4/12 | |
2200/2200 [==============================] - 1s - loss: 0.6903 - binary_accuracy: 0.5223 - val_loss: 0.6929 - val_binary_accuracy: 0.4850 | |
Epoch 5/12 | |
2200/2200 [==============================] - 1s - loss: 0.6900 - binary_accuracy: 0.5232 - val_loss: 0.6932 - val_binary_accuracy: 0.5000 | |
Epoch 6/12 | |
2200/2200 [==============================] - 1s - loss: 0.6887 - binary_accuracy: 0.5200 - val_loss: 0.6934 - val_binary_accuracy: 0.4930 | |
Epoch 7/12 | |
2200/2200 [==============================] - 1s - loss: 0.6885 - binary_accuracy: 0.5264 - val_loss: 0.6936 - val_binary_accuracy: 0.4970 | |
Epoch 8/12 | |
2200/2200 [==============================] - 1s - loss: 0.6860 - binary_accuracy: 0.5355 - val_loss: 0.6937 - val_binary_accuracy: 0.4890 | |
Epoch 9/12 | |
2200/2200 [==============================] - 1s - loss: 0.6852 - binary_accuracy: 0.5286 - val_loss: 0.6936 - val_binary_accuracy: 0.4840 | |
Epoch 10/12 | |
2200/2200 [==============================] - 1s - loss: 0.6829 - binary_accuracy: 0.5550 - val_loss: 0.6941 - val_binary_accuracy: 0.4780 | |
Epoch 11/12 | |
2200/2200 [==============================] - 1s - loss: 0.6826 - binary_accuracy: 0.5482 - val_loss: 0.6940 - val_binary_accuracy: 0.4860 | |
Epoch 12/12 | |
2200/2200 [==============================] - 1s - loss: 0.6795 - binary_accuracy: 0.5509 - val_loss: 0.6945 - val_binary_accuracy: 0.4860 | |
Test score: 0.694488404274 | |
Test accuracy: 0.486 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import | |
from __future__ import print_function | |
import numpy as np | |
np.random.seed(1337) # for reproducibility | |
from keras.models import Sequential | |
from keras.layers.core import Dense, Dropout, Activation, Flatten | |
from keras.layers.convolutional import Conv2D, MaxPooling2D | |
from keras.utils import np_utils | |
from scipy.misc import imresize | |
# this allows the example to be run in-repo | |
# (or can be removed if lfw_fuel is installed) | |
import sys | |
sys.path.append('.') | |
from lfw_fuel import lfw | |
''' | |
Train a simple convnet on the LFW dataset. | |
''' | |
batch_size = 128 | |
nb_classes = 2 | |
nb_epoch = 12 | |
feature_width = 32 | |
feature_height = 32 | |
def cropImage(im): | |
im2 = np.dstack(im).astype(np.uint8) | |
# return centered 128x128 from original 250x250 (40% of area) | |
newim = im2[61:189, 61:189] | |
sized1 = imresize(newim[:,:,0:3], (feature_width, feature_height), interp="bicubic", mode="RGB") | |
sized2 = imresize(newim[:,:,3:6], (feature_width, feature_height), interp="bicubic", mode="RGB") | |
return np.asarray([sized1[:,:,0], sized1[:,:,1], sized1[:,:,2], sized2[:,:,0], sized2[:,:,1], sized2[:,:,2]]) | |
# the data, shuffled and split between train and test sets | |
(X_train, y_train), (X_test, y_test) = lfw.load_data("deepfunneled") | |
# crop features | |
X_train = np.asarray(list(map(cropImage, X_train))) | |
X_test = np.asarray(list(map(cropImage, X_test))) | |
# 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} test samples, {2} channel{0}, {3}x{4}".format("" if X_test.shape[1] == 1 else "s", *X_test.shape)) | |
# convert class vectors to binary class matrices | |
Y_train = np_utils.to_categorical(y_train, nb_classes) | |
Y_test = np_utils.to_categorical(y_test, nb_classes) | |
model = Sequential() | |
model.add(Conv2D(32, (3,3), input_shape=(6,32,32), padding='valid')) | |
model.add(Activation('relu')) | |
model.add(Conv2D(32, (3,3), input_shape=(6,32,32), padding='valid')) | |
model.add(Activation('relu')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Dropout(0.25)) | |
model.add(Flatten()) | |
model.add(Dense(128)) | |
model.add(Activation('relu')) | |
model.add(Dropout(0.5)) | |
model.add(Dense(nb_classes)) | |
model.add(Activation('softmax')) | |
model.compile(loss='categorical_crossentropy', metrics=['binary_accuracy'], optimizer='adadelta') | |
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, verbose=0) | |
print('Test score:', score[0]) | |
print('Test accuracy:', score[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment