simple/MNIST_simple.py
def main():
    """
    Simple Model
    -------------------------------------
    - Compiles and trains a simple neural network on the MNIST data set of gray-scale images.
    - Plots acc/loss vs. epochs.
    - Saves model data.
    """

    # Defining vars
    model_name = "MNIST_simple"
    img_x = 28
    img_y = 28
    validation_frac = 12
    n_classes = 10
    n_epochs = 10

    # Load data.
    (X_train, y_train), (X_test, y_test) = mnist.load_data()

    # Reshaping to make 4D tensor compatible with Keras.

    X_train = X_train.reshape(60000, 784)
    X_test = X_test.reshape(10000, 784)
    input_shape = (img_x * img_y, )

    # Data normalization (needs to be type float for division to work).
    X_train = X_train.astype('float32')
    X_test = X_test.astype('float32')
    X_train /= 255
    X_test /= 255
    y_train_1h = to_categorical(y_train, 10)
    y_test_1h = to_categorical(y_test, 10)

    # Creating validation set from training set.
    start_idx = X_train.shape[0] - (X_train.shape[0] // validation_frac)
    X_val = X_train[start_idx::]
    y_val_1h = y_train_1h[start_idx::]
    X_train = X_train[:start_idx]
    y_train_1h = y_train_1h[:start_idx]

    # Create and compile model.
    model = simple_model(32, input_shape, n_classes)

    # Train model.
    hist = model.fit(X_train, y_train_1h, batch_size=64, epochs=n_epochs,
                     verbose=1, validation_data=(X_val, y_val_1h))

    # Plot metrics.
    my_plot(hist, model_name)

    # Evaluate model.
    scores = model.evaluate(x=X_test, y=y_test_1h, batch_size=128, verbose=1)
    [print("-", end="") for i in range(20)]
    print("\nMetrics: {}".format(scores))
    [print("-", end="") for i in range(20)]

    # Save model.
    save_model(model, model_name, history=hist)

    Simple Model
    -------------------------------------
    - Compiles and trains a simple neural network on the MNIST data set of gray-scale images.
    - Plots acc/loss vs. epochs.
    - Saves model data.
    
Simple Model

Compiles and trains a simple neural network on the MNIST data set of gray-scale images.
Plots acc/loss vs. epochs.
Saves model data.
Simple Model Compiles and trains a simple neural network on the MNIST data set of gray - scale images . Plots acc / loss vs . epochs . Saves model data .
def main():
    model_name = "MNIST_simple"
    img_x = 28
    img_y = 28
    validation_frac = 12
    n_classes = 10
    n_epochs = 10
    (X_train, y_train), (X_test, y_test) = mnist.load_data()
    X_train = X_train.reshape(60000, 784)
    X_test = X_test.reshape(10000, 784)
    input_shape = (img_x * img_y, )
    X_train = X_train.astype('float32')
    X_test = X_test.astype('float32')
    X_train /= 255
    X_test /= 255
    y_train_1h = to_categorical(y_train, 10)
    y_test_1h = to_categorical(y_test, 10)
    start_idx = X_train.shape[0] - (X_train.shape[0] // validation_frac)
    X_val = X_train[start_idx::]
    y_val_1h = y_train_1h[start_idx::]
    X_train = X_train[:start_idx]
    y_train_1h = y_train_1h[:start_idx]
    model = simple_model(32, input_shape, n_classes)
    hist = model.fit(X_train, y_train_1h, batch_size=64, epochs=n_epochs,
                     verbose=1, validation_data=(X_val, y_val_1h))
    my_plot(hist, model_name)
    scores = model.evaluate(x=X_test, y=y_test_1h, batch_size=128, verbose=1)
    [print("-", end="") for i in range(20)]
    print("\nMetrics: {}".format(scores))
    [print("-", end="") for i in range(20)]
    save_model(model, model_name, history=hist)
def main ( ) : model_name = "MNIST_simple" img_x = 28 img_y = 28 validation_frac = 12 n_classes = 10 n_epochs = 10 ( X_train , y_train ) , ( X_test , y_test ) = mnist . load_data ( ) X_train = X_train . reshape ( 60000 , 784 ) X_test = X_test . reshape ( 10000 , 784 ) input_shape = ( img_x * img_y , ) X_train = X_train . astype ( 'float32' ) X_test = X_test . astype ( 'float32' ) X_train /= 255 X_test /= 255 y_train_1h = to_categorical ( y_train , 10 ) y_test_1h = to_categorical ( y_test , 10 ) start_idx = X_train . shape [ 0 ] - ( X_train . shape [ 0 ] // validation_frac ) X_val = X_train [ start_idx : : ] y_val_1h = y_train_1h [ start_idx : : ] X_train = X_train [ : start_idx ] y_train_1h = y_train_1h [ : start_idx ] model = simple_model ( 32 , input_shape , n_classes ) hist = model . fit ( X_train , y_train_1h , batch_size = 64 , epochs = n_epochs , verbose = 1 , validation_data = ( X_val , y_val_1h ) ) my_plot ( hist , model_name ) scores = model . evaluate ( x = X_test , y = y_test_1h , batch_size = 128 , verbose = 1 ) [ print ( "-" , end = "" ) for i in range ( 20 ) ] print ( "\nMetrics: {}" . format ( scores ) ) [ print ( "-" , end = "" ) for i in range ( 20 ) ] save_model ( model , model_name , history = hist )
Simple Model
Simple Model
"""
    Simple Model
    -------------------------------------
    - Compiles and trains a simple neural network on the MNIST data set of gray-scale images.
    - Plots acc/loss vs. epochs.
    - Saves model data.
    """ # Defining vars
 # Load data.
 # Reshaping to make 4D tensor compatible with Keras.
 # Data normalization (needs to be type float for division to work).
 # Creating validation set from training set.
 # Create and compile model.
 # Train model.
 # Plot metrics.
 # Evaluate model.
 # Save model.
