Пример #1
0
def exercise5():
    dm = DataManager()
    dm.preprocessData()
    nn = NeuralNetwork()
    nn.setInputLayer(28,28)
    nn.setHiddenLayer(28)
    nn.setOutputLayer(10)
    nn.createModel()
    print("Testing train function: ")
    nn.train(dm.train_data, dm.train_labels, 10)
Пример #2
0
def main():
    a = DataManager()
    a.loadData()
    b = NeuralNetwork()
    b.createModel()

    b.train(a.train_data, a.train_labels, epochs=100)
    res = b.evaluate(a.eval_data, a.eval_labels)
    print("Accuracy : {}".format(res))
    b.saveModel()

    pass
Пример #3
0
def main():
    a = DataManager()
    a.loadData()
    b = NeuralNetwork()
    b.createModel()

    b.train(a.train_data,
            a.train_labels,
            a.eval_data,
            a.eval_labels,
            epochs=100)
    b.saveModel("test.h5")
Пример #4
0
def main():
    data_manager = DataManager()
    data_manager.loadData()
    neural_network = NeuralNetwork()
    neural_network.create_model()
    neural_network.train(data_manager.train_data,
                         data_manager.train_labels,
                         data_manager.eval_data,
                         data_manager.eval_labels,
                         epochs=100)
    result = neural_network.evaluate(data_manager.eval_data,
                                     data_manager.eval_labels)
    neural_network.save_model()
    print("Accuracy : {}".format(result))
    pass
Пример #5
0
def main():
    #loss: 15.552 , acc: 0.0967

	manager = DataManager()
	
	manager.preprocessData()
	
	network = NeuralNetwork()
	
	network.createModel()
	
	network.train(manager.datagen,manager.train_data,manager.train_labels,10)
	
	network.saveModel()
	
	results = network.evaluate(manager.eval_data,manager.eval_labels)
Пример #6
0
def main():
    #run 1 : 5.7071 loss, 0.1564 acc          .1 epoch : lr = 0.001
    #run 2:  2.3683 loss, 0.1066 acc : 0.1215 .1 epoch : lr = 0.001
    #run 3 : 2.8534     , 0.1001     : 0.1    .1 epoch : lr = 1
    #run 4 : 11.0573    , 0.0772     : 0.0763 .3 epochs: lr = 1 : batch_size = 32
    #run 5 : 0. 805      ,0.7291               30 epochs    lr = 0.001 batch size = 32

    dm = DataManager()
    dm.preprocessData()
    nn = NeuralNetwork()
    nn.createModel()
    nn.train(dm.datagen,dm.train_data,dm.train_labels,30);
    nn.saveModel("best.h5")
    result = nn.evaluate(dm.eval_data,dm.eval_labels)
    print(result[0])
    print(result[1])
    print(nn.test(dm.eval_data));
Пример #7
0
def exercise1():
    dm = DataManager()
    dm.preprocessData()
    outstring = ("Testing image preprocessing: ")
    if dm.train_data.dtype != np.float64:
        outstring += ("{}KO| Expected train_data type to be float64, got {}{}"
                      "".format(Fore.RED, dm.train_data.dtype, Fore.RESET))
    elif dm.eval_data is None:
        outstring += ("{}KO| Expected eval_data type to be float64, got {}{}"
                      "".format(Fore.RED, None, Fore.RESET))
    elif dm.eval_labels is None:
        outstring += ("{}KO| Expected eval_labels type to be float64, got {}{}"
                      "".format(Fore.RED, None, Fore.RESET))
    elif dm.eval_data.dtype !=np.float64:
        outstring += ("{}KO| Expected eval_data type to be float64, got {}{}"
                      "".format(Fore.RED, dm.train_data.dtype, Fore.RESET))
    elif dm.test_data.dtype != np.float64:
        outstring += ("{}KO| Expected test_data type to be float64, got {}{}"
                      "".format(Fore.RED, dm.train_data.dtype, Fore.RESET))
    elif (dm.train_data < 0).any() or (dm.train_data > 1).any():
        outstring += ("{}KO| Train data values should be between 0 and 1.{}"
                      "".format(Fore.RED, Fore.RESET))
    elif (dm.eval_data < 0).any() or (dm.eval_data > 1).any():
        outstring += ("{}KO| Train data values should be between 0 and 1.{}"
                      "".format(Fore.RED, Fore.RESET)) 
    elif (dm.test_data < 0).any() or (dm.test_data > 1).any():
        outstring += ("{}KO| Train data values should be between 0 and 1.{}"
                      "".format(Fore.RED, Fore.RESET))
    elif dm.eval_data.shape != (6000, 28, 28):
        outstring += ("{}KO| Expected eval_data length to be (6000, 28, 28), got {}{}"
                      "".format(Fore.RED, dm.eval_data.shape, Fore.RESET))
    elif dm.eval_labels.shape != (6000,):
        outstring += ("{}KO| Expected eval_labels length to be (6000,), got {}{}"
                      "".format(Fore.RED, dm.eval_labels.shape, Fore.RESET))
    elif dm.test_data.shape != (4000, 28, 28):
        outstring += ("{}KO| Expected test_data length to be (4000, 28, 28), got {}{}"
                      "".format(Fore.RED, dm.test_data.shape, Fore.RESET))
    elif dm.test_labels.shape != (4000,):
        outstring += ("{}KO| Expected test_labels length to be (4000,), got {}{}"
                      "".format(Fore.RED, dm.test_labels.shape, Fore.RESET))
    else:
        outstring += "{}OK{}".format(Fore.GREEN, Fore.RESET)

    print (outstring)
Пример #8
0
def exercise6():
    dm = DataManager()
    dm.preprocessData()
    nn = NeuralNetwork()
    nn.setInputLayer(28,28)
    nn.setHiddenLayer(28)
    nn.setOutputLayer(10)
    nn.createModel()
    nn.train(dm.train_data, dm.train_labels, 1)
    outstring = "Testing eval function: "
    eval_results = nn.evaluate(dm.eval_data, dm.eval_labels)
    if eval_results is None:
        outstring += ("{}KO| no results were returned{}"
                      "".format(Fore.RED, Fore.RESET))
    else:
       outstring += "{0}OK| Test accuracy was: {1:.4f}{2}".format(Fore.GREEN, 
                                                                  eval_results, 
                                                                  Fore.RESET)

    print (outstring)
Пример #9
0
def exercise7():
    dm = DataManager()
    dm.preprocessData()
    nn = NeuralNetwork()
    nn.setInputLayer(28,28)
    nn.setHiddenLayer(28)
    nn.setOutputLayer(10)
    nn.createModel()
    nn.train(dm.train_data, dm.train_labels, 1)
    nn.saveModel("test.h5")
    nn2 = NeuralNetwork()
    nn2.loadModel("test.h5")
    eval_results = nn.evaluate(dm.eval_data, dm.eval_labels)
    eval_results2 = nn2.evaluate(dm.eval_data, dm.eval_labels)
    outstring = "Testing save and load functions: "
    if eval_results != eval_results2:
        outstring += ("{}KO| evaluation results for loaded network were {} expected {}{}"
                      "".format(Fore.RED, eval_results2, eval_results, Fore.RESET))

    else:
        outstring += "{}OK{}".format(Fore.GREEN, Fore.RESET)

    print(outstring)