Created
January 30, 2017 14:52
-
-
Save chakkritte/b2de412ba2efedf111aec3da18459270 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
1.Install Keras | |
git clone git://github.com/fchollet/keras.git | |
cd keras | |
python setup.py develop | |
2.Demo training data on keras with gpu | |
#### Create file 'test.py' and copy and paste this code ####### | |
python test.py |
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
from keras.models import Sequential | |
from keras.layers import Dense, Dropout, Activation | |
from keras.optimizers import SGD | |
import numpy as np | |
data_dim = 100 | |
nb_classes = 10 | |
model = Sequential() | |
model.add(Dense(32, input_dim=data_dim,init='uniform')) | |
model.add(Activation('relu')) | |
model.add(Dropout(0.5)) | |
model.add(Dense(64, input_dim=data_dim, init='uniform')) | |
model.add(Activation('relu')) | |
model.add(Dropout(0.5)) | |
model.add(Dense(nb_classes, init='uniform')) | |
model.add(Activation('softmax')) | |
model.compile(loss='categorical_crossentropy', | |
optimizer='sgd', | |
metrics=["accuracy"]) | |
# generate dummy training data | |
x_train = np.random.random((1000, data_dim)) | |
y_train = np.random.random((1000, nb_classes)) | |
# generate dummy test data | |
x_test = np.random.random((100, data_dim)) | |
y_test = np.random.random((100, nb_classes)) | |
model.fit(x_train, y_train, | |
nb_epoch=50, | |
batch_size=128) | |
score = model.evaluate(x_test, y_test, batch_size=16) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment