simple/simple.py
def main():
    """
    Simple model:
    -------------------------------------
    - Evaluates loaded model on MNIST test data.
    - Shows loss and accuracy.
    - Predicts MNIST test data
    - Produces classification report and confusion matrix.
    """

    # defining variables.
    img_x = 28
    img_y = 28
    model_name = "MNIST_simple"
    model_weights = "MNIST_simple_weights"

    # Load data and prepare.
    (_X_train, _y_train), (X_test, y_test) = mnist.load_data()
    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_test = X_test.astype('float32')
    X_test /= 255
    y_test_1h = to_categorical(y_test, 10)

    # Load model and compile.
    model = load_model(model_name, model_weights)
    model.compile(loss="categorical_crossentropy", metrics=["accuracy"], optimizer=SGD())

    # 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)]

    # Predict test set.
    predictions = model.predict(X_test)

    # Reverting one hot encoding.
    predictions = [np.argmax(i) for i in predictions]

    # Displaying report.
    [print("=", end="") for i in range(20)]
    print("\nConfution Matrix:")
    [print("-", end="") for i in range(20)]
    print("\n", confusion_matrix(y_test, predictions))
    [print("=", end="") for i in range(20)]
    print("\nCls Report:")
    [print("-", end="") for i in range(20)]
    print("\n", classification_report(y_test, predictions))
    [print("-", end="") for i in range(20)]

    ################################################
    # Uncomment if you want to run the code below. #
    ################################################

    # Load up training history.
    hist = load_training_data("simple_train_hist_dict")
    print(hist.keys())
    # Print model summary/architecture.
    # print(model.summary())


    Simple model:
    -------------------------------------
    - Evaluates loaded model on MNIST test data.
    - Shows loss and accuracy.
    - Predicts MNIST test data
    - Produces classification report and confusion matrix.
    
Simple model.

Evaluates loaded model on MNIST test data.
Shows loss and accuracy.
Predicts MNIST test data
Produces classification report and confusion matrix.
Simple model . Evaluates loaded model on MNIST test data . Shows loss and accuracy . Predicts MNIST test data Produces classification report and confusion matrix .
def main():
    img_x = 28
    img_y = 28
    model_name = "MNIST_simple"
    model_weights = "MNIST_simple_weights"
    (_X_train, _y_train), (X_test, y_test) = mnist.load_data()
    X_test = X_test.reshape(10000, 784)
    input_shape = (img_x * img_y,)
    X_test = X_test.astype('float32')
    X_test /= 255
    y_test_1h = to_categorical(y_test, 10)
    model = load_model(model_name, model_weights)
    model.compile(loss="categorical_crossentropy", metrics=["accuracy"], optimizer=SGD())
    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)]
    predictions = model.predict(X_test)
    predictions = [np.argmax(i) for i in predictions]
    [print("=", end="") for i in range(20)]
    print("\nConfution Matrix:")
    [print("-", end="") for i in range(20)]
    print("\n", confusion_matrix(y_test, predictions))
    [print("=", end="") for i in range(20)]
    print("\nCls Report:")
    [print("-", end="") for i in range(20)]
    print("\n", classification_report(y_test, predictions))
    [print("-", end="") for i in range(20)]
    hist = load_training_data("simple_train_hist_dict")
    print(hist.keys())
def main ( ) : img_x = 28 img_y = 28 model_name = "MNIST_simple" model_weights = "MNIST_simple_weights" ( _X_train , _y_train ) , ( X_test , y_test ) = mnist . load_data ( ) X_test = X_test . reshape ( 10000 , 784 ) input_shape = ( img_x * img_y , ) X_test = X_test . astype ( 'float32' ) X_test /= 255 y_test_1h = to_categorical ( y_test , 10 ) model = load_model ( model_name , model_weights ) model . compile ( loss = "categorical_crossentropy" , metrics = [ "accuracy" ] , optimizer = SGD ( ) ) 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 ) ] predictions = model . predict ( X_test ) predictions = [ np . argmax ( i ) for i in predictions ] [ print ( "=" , end = "" ) for i in range ( 20 ) ] print ( "\nConfution Matrix:" ) [ print ( "-" , end = "" ) for i in range ( 20 ) ] print ( "\n" , confusion_matrix ( y_test , predictions ) ) [ print ( "=" , end = "" ) for i in range ( 20 ) ] print ( "\nCls Report:" ) [ print ( "-" , end = "" ) for i in range ( 20 ) ] print ( "\n" , classification_report ( y_test , predictions ) ) [ print ( "-" , end = "" ) for i in range ( 20 ) ] hist = load_training_data ( "simple_train_hist_dict" ) print ( hist . keys ( ) )
Simple model:
Simple model :
"""
    Simple model:
    -------------------------------------
    - Evaluates loaded model on MNIST test data.
    - Shows loss and accuracy.
    - Predicts MNIST test data
    - Produces classification report and confusion matrix.
    """ # defining variables.
 # Load data and prepare.
 # Data normalization (needs to be type float for division to work).
 # Load model and compile.
 # Evaluate model.
 # Predict test set.
 # Reverting one hot encoding.
 # Displaying report.
 ################################################
 # Uncomment if you want to run the code below. #
 ################################################
 # Load up training history.
 # Print model summary/architecture.
 # print(model.summary())
