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

    img_x = 28
    img_y = 28
    u1 = 120
    u2 = 84
    n_classes = 10
    n_epochs = 10
    n_folds = 5

    # 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(X_train.shape[0], img_x, img_y, 1)
    X_test = X_test.reshape(X_test.shape[0], img_x, img_y, 1)
    dim = (img_x, img_y, 1)

    # 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

    X = (X_train, X_test)
    y = (y_train, y_test)
    models, res = strat_k_fold(n_folds, X, y, u1, u2, dim, n_classes, n_epochs)

    mn = "CV_LeNet_final"
    for i in range(len(models)):
        s = "_{}".format(i)
        save_model(models[i], mn + s)
    with open("res_dict_final", 'wb') as f:
        pickle.dump(res, f)

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


Compiles and trains a LeNet-5 neural network on the MNIST data set of gray-scale images.
Plots acc/loss vs. epochs.
Saves model data.
Compiles and trains a LeNet - 5 neural network on the MNIST data set of gray - scale images . Plots acc / loss vs . epochs . Saves model data .
def main():
    img_x = 28
    img_y = 28
    u1 = 120
    u2 = 84
    n_classes = 10
    n_epochs = 10
    n_folds = 5
    (X_train, y_train), (X_test, y_test) = mnist.load_data()
    X_train = X_train.reshape(X_train.shape[0], img_x, img_y, 1)
    X_test = X_test.reshape(X_test.shape[0], img_x, img_y, 1)
    dim = (img_x, img_y, 1)
    X_train = X_train.astype('float32')
    X_test = X_test.astype('float32')
    X_train /= 255
    X_test /= 255
    X = (X_train, X_test)
    y = (y_train, y_test)
    models, res = strat_k_fold(n_folds, X, y, u1, u2, dim, n_classes, n_epochs)
    mn = "CV_LeNet_final"
    for i in range(len(models)):
        s = "_{}".format(i)
        save_model(models[i], mn + s)
    with open("res_dict_final", 'wb') as f:
        pickle.dump(res, f)
def main ( ) : img_x = 28 img_y = 28 u1 = 120 u2 = 84 n_classes = 10 n_epochs = 10 n_folds = 5 ( X_train , y_train ) , ( X_test , y_test ) = mnist . load_data ( ) X_train = X_train . reshape ( X_train . shape [ 0 ] , img_x , img_y , 1 ) X_test = X_test . reshape ( X_test . shape [ 0 ] , img_x , img_y , 1 ) dim = ( img_x , img_y , 1 ) X_train = X_train . astype ( 'float32' ) X_test = X_test . astype ( 'float32' ) X_train /= 255 X_test /= 255 X = ( X_train , X_test ) y = ( y_train , y_test ) models , res = strat_k_fold ( n_folds , X , y , u1 , u2 , dim , n_classes , n_epochs ) mn = "CV_LeNet_final" for i in range ( len ( models ) ) : s = "_{}" . format ( i ) save_model ( models [ i ] , mn + s ) with open ( "res_dict_final" , 'wb' ) as f : pickle . dump ( res , f )
LeNet Model
LeNet Model
"""
    LeNet Model
    -------------------------------------
    - Compiles and trains a LeNet-5 neural network on the MNIST data set of gray-scale images.
    - Plots acc/loss vs. epochs.
    - Saves model data.
    """ # Load data.
 # Reshaping to make 4D tensor compatible with Keras.
 # Data normalization (needs to be type float for division to work).
