Skip to content

Instantly share code, notes, and snippets.

@Dexdev08
Created June 24, 2017 14:58
Show Gist options
  • Save Dexdev08/0f01bf364e47d860443690c120410268 to your computer and use it in GitHub Desktop.
Save Dexdev08/0f01bf364e47d860443690c120410268 to your computer and use it in GitHub Desktop.
test_keras_two.py
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import SGD
import keras as keras
import numpy as np
x_train = np.random.random((1000,20))
y_train = keras.utils.np_utils.to_categorical(np.random.randint(10, size=(1000,1)), nb_classes=10)
x_test = np.random.random((100,20))
y_test = keras.utils.np_utils.to_categorical(np.random.randint(10, size=(100,1)),nb_classes=10)
model = Sequential()
model.add(Dense(64, activation='relu', input_dim=20))
model.add(Dropout(0.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, nb_epoch=20, batch_size=128)
score=model.evaluate(x_test, y_test, batch_size=128)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment