Last active
November 16, 2018 16:52
-
-
Save wotori/9b99312c6975cd691f62991931c9cc41 to your computer and use it in GitHub Desktop.
Working Keras with random generated data
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
import numpy as np | |
import keras | |
from keras.models import Sequential | |
from keras.layers import Dense, Dropout, Flatten | |
from keras.layers import Conv2D, MaxPooling2D | |
from keras.optimizers import SGD | |
# Generate dummy data | |
x_train = np.random.random((100, 100, 100, 3)) | |
y_train = keras.utils.to_categorical(np.random.randint(10, size=(100, 1)), num_classes=10) | |
model = Sequential() | |
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(100, 100, 3))) | |
model.add(Flatten()) | |
model.add(Dense(256, 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) | |
model.fit(x_train, y_train, batch_size=32, epochs=10) | |
score = model.evaluate(x_test, y_test, batch_size=32) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment