This file contains 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
# Build model | |
import sklearn | |
from sklearn.cross_validation import train_test_split | |
from sklearn.grid_search import GridSearchCV | |
from sklearn.svm import LinearSVC | |
X_train, y_train = svm_features.reshape(300,7*7*512), svm_labels | |
param = [{ | |
"C": [0.01, 0.1, 1, 10, 100] |
This file contains 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
# Concatenate training and validation sets | |
svm_features = np.concatenate((train_features, validation_features)) | |
svm_labels = np.concatenate((train_labels, validation_labels)) |
This file contains 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
# Define model | |
from keras import models | |
from keras import layers | |
from keras import optimizers | |
epochs = 100 | |
model = models.Sequential() | |
model.add(layers.GlobalAveragePooling2D(input_shape=(7,7,512))) | |
model.add(layers.Dense(1, activation='sigmoid')) |
This file contains 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
# Define model | |
from keras import models | |
from keras import layers | |
from keras import optimizers | |
epochs = 100 | |
model = models.Sequential() | |
model.add(layers.Flatten(input_shape=(7,7,512))) | |
model.add(layers.Dense(256, activation='relu', input_dim=(7*7*512))) |
This file contains 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
# Extract features | |
import os, shutil | |
from keras.preprocessing.image import ImageDataGenerator | |
datagen = ImageDataGenerator(rescale=1./255) | |
batch_size = 32 | |
def extract_features(directory, sample_count): | |
features = np.zeros(shape=(sample_count, 7, 7, 512)) # Must be equal to the output of the convolutional base | |
labels = np.zeros(shape=(sample_count)) |
This file contains 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
# Create smaller dataset for Dogs vs. Cats | |
import os, shutil | |
original_dataset_dir = '/Users/macbook/dogs_cats_dataset/train/' | |
base_dir = '/Users/macbook/book/dogs_cats/data' | |
if not os.path.exists(base_dir): | |
os.mkdir(base_dir) | |
# Create directories |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Missing Data" | |
] | |
}, | |
{ |
NewerOlder