Skip to content

Instantly share code, notes, and snippets.

@z-a-f
Last active May 31, 2018 00:10
Show Gist options
  • Save z-a-f/1a91fee57380940c73f57452214cbbbe to your computer and use it in GitHub Desktop.
Save z-a-f/1a91fee57380940c73f57452214cbbbe to your computer and use it in GitHub Desktop.
import keras
def preprocess_images(images, normalization=255):
"""Normalizes the inputs"""
dims = images.shape
return images.reshape((dims[0], dims[1]*dims[2])).astype('float32') / normalization
def preprocess_labels(labels):
"""Preprocesses the labels into categorical"""
return keras.utils.to_categorical(labels)
def get_model(N=512):
"""Returns a simple FC model with N nodes in the first hidden layer"""
model = keras.models.Sequential()
model.add(keras.layers.Dense(N, activation='relu', input_shape=(28*28,)))
model.add(keras.layers.Dense(10, activation='tanh'))
model.compile(optimizer='rmsprop', loss='mse', metrics=['accuracy'])
return model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment