Example #1
0
def main(phase):
    # load train_data, valid_data, test_data
    train_data, valid_data, test_data = load_data()
    # pdb.set_trace()
    # construct the network
    model = network2.Network([784, 20, 10])
    # train the network using SGD
    if phase == "train":
        result = model.SGD(training_data=train_data,
                           epochs=100,
                           mini_batch_size=128,
                           eta=1e-3,
                           lmbda=0.0,
                           evaluation_data=valid_data,
                           monitor_evaluation_cost=True,
                           monitor_evaluation_accuracy=True,
                           monitor_training_cost=True,
                           monitor_training_accuracy=True)
        show_metric_plot(result[2], result[0], 100, 'Training Error',
                         'Validation Error', 'Loss', 'Loss v/s Epochs')
        evaluation_accuracy = list(map(lambda x: x * 100 / 10000, result[1]))
        training_accuracy = list(map(lambda x: x * 100 / 3000, result[3]))
        show_metric_plot(training_accuracy, evaluation_accuracy, 100,
                         'Training Accuracy', 'Validation Accuracy',
                         'Accuracy %', 'Accuracy v/s Epochs')
        model.save('train_model')
    if phase == "test":
        net = network2.load('train_model')
        print('Accuracy for Test Data:{}%'.format(
            net.accuracy(test_data) / 100))
Example #2
0
def test():

    train_data, valid_data, test_data = load_data()
    print("length of test data:",len(test_data[0]))
    net=network2.load('Saved_Weights')
    accuracy = net.accuracy(test_data)

    print("Test Accuracy",accuracy/len(test_data[0]))
    print("Test Accuracy: {} / {}".format(accuracy, len(test_data[0])))
def test_model():
    # load train_data, valid_data, test_data.
    train_data, valid_data, test_data = load_data()
    # load the model.
    model = network2.load('../../sgd_model.json')
    accuracy = model.accuracy(test_data, convert=False)
    total_cost = model.total_cost(test_data, 0.0, convert=True)
    print('Accuracy: {}'.format(accuracy))
    print('Total Cost: {}'.format(total_cost))
Example #4
0
def main_test():
    # load train_data, valid_data, test_data
    train_data, valid_data, test_data = load_data()
    # construct the network
    #model = network2.Network([784, 20, 10])
    model = network2.load('saver')
    #test the network using SGD
    test_cost = model.total_cost(test_data, lmbda = 0.0, convert=True)
    test_accuracy = model.accuracy(test_data, convert=False)
    
    print('Test cost : ', test_cost)
    print('Test Accuracy : ', test_accuracy)
Example #5
0
 def __init__(self):
     super(Root, self).__init__()
     self.title("Recognize handwritten digits")
     self.minsize(500, 400)
     self.labelFrame = LabelFrame(self, text="Otwórz plik")
     self.labelFrame.grid(column=1, row=1, padx=20, pady=20)
     self.button1()
     self.button2()
     self.label_file = ttk.Label(self.labelFrame, text="")
     self.label_result = ttk.Label(self.labelFrame, text="")
     self.fig = Figure(figsize=(5, 5), dpi=100)
     self.net = network2.load('../data/network_params')
def test_network(file_name):
    print('testing network')
    print('loading saved file: ', file_name)
    model = network2.load(file_name)

    # load train_data, valid_data, test_data
    train_data, valid_data, test_data = load_data()

    num_correct = 0
    for i in range(len(test_data[0])):
        prediction = np.argmax(model.feedforward(test_data[0][i]))
        if prediction == test_data[1][i]:
            num_correct += 1
    test_accuracy = num_correct / len(test_data[0])
    print("Test accuracy: " + str(test_accuracy))
def test():
    # load train_data, valid_data, test_data
    test_data = load_data()[2]
    #loading the neural Network
    model = network2.load('NeuralNet_new_fc.csv')
    test_cost = model.total_cost(test_data, lmbda=0.0, convert=True)
    test_accuracy = model.accuracy(test_data)
    '''result = []
    for i in range(len(test_data[0])):
        result.append(network2.vectorized_result(np.argmax(model.feedforward(test_data[0][i]))))

    df = pd.DataFrame(list(map(np.ravel, result)))
    df.to_csv('Arsingh3_hw02b_Prediction_Submission.csv')'''

    #result = model.feedforward()
    print('Test Error: {}'.format(test_cost))
    print('Test accuracy: {}'.format(test_accuracy))
def main():
    # load train_data, valid_data, test_data
    train_data, valid_data, test_data = load_data()
    # construct the network
    model = network2.Network([784, 32, 10])
    # train the network using SGD
    validation_loss , validation_accuracy, training_loss, training_accuracy = model.SGD(
        training_data=train_data,
        epochs=75,
        mini_batch_size=64,
        eta=0.002,
        lmbda = 0.0,
        evaluation_data=valid_data,
        monitor_evaluation_cost=True,
        monitor_evaluation_accuracy=True,
        monitor_training_cost=True,
        monitor_training_accuracy=True)
    
    model.save("model0.json")
    model = network2.load("model0.json")
    predictions , prob, vector_base = predict(test_data, model)   
    
    plot_learning_curve(validation_loss, training_loss, validation_accuracy, training_accuracy)
    csvfile = open('predictions.csv','w', newline='')
    obj = csv.writer(csvfile)
    obj.writerows(predictions)
    csvfile.close()
    csvfile = open('raw.csv','w', newline='')
    obj1 = csv.writer(csvfile)
    obj1.writerows(prob)
    csvfile.close()
    
    test_accuracy = 0;
    for x, y in zip(vector_base, test_data[1]):
        if x == y:
            test_accuracy += 1
    print("The accuracy on test set is: " , test_accuracy)
Example #9
0
def test_accuracy():
    train_data, valid_data, test_data = load_data()
    loaded_model = network2.load('final_model.json')
    print(loaded_model.accuracy(test_data) / len(test_data[0]))
Example #10
0
def test():
    train_data, valid_data, test_data = load_data()
    model = network2.load("weights.json")
    print("Accuracy on test data: ", model.accuracy(test_data) / 100)