Created
November 27, 2017 23:17
-
-
Save dcshapiro/a5ae666b8eb1b62c6d7bae3144cf2c32 to your computer and use it in GitHub Desktop.
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
%%time | |
import keras | |
from keras.models import Sequential | |
from keras.layers import Dense, Dropout, Activation | |
from keras.optimizers import SGD | |
# Generate dummy data | |
import numpy as np | |
x_train = np.random.random((10000, 20)) | |
y_train = keras.utils.to_categorical(np.random.randint(10, size=(10000, 1)), num_classes=10) | |
x_test = np.random.random((1000, 20)) | |
y_test = keras.utils.to_categorical(np.random.randint(10, size=(1000, 1)), num_classes=10) | |
model = Sequential() | |
# Dense(64) is a fully-connected layer with 64 hidden units. | |
# in the first layer, you must specify the expected input data shape: | |
# here, 20-dimensional vectors. | |
model.add(Dense(64, activation='relu', input_dim=20)) | |
model.add(Dropout(0.5)) | |
for i in range(5): | |
model.add(Dense(64, activation='relu')) | |
model.add(Dropout(0.5)) | |
model.add(Dense(10, activation='softmax')) | |
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True) | |
model.compile(loss='categorical_crossentropy', | |
optimizer=sgd, | |
metrics=['accuracy']) | |
model.fit(x_train, y_train, | |
epochs=20, | |
batch_size=128) | |
score = model.evaluate(x_test, y_test, batch_size=128) | |
print(score) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment