Ejemplo n.º 1
0
def main():
    cuda = gpuInit()
    np.random.seed(1)
    num_iterations = 1000
    count = 10  # default
    nSample = 0
    layerStart = 0
    layerLimit = 8
    learning_rate = 0
    simpleNN = 0

    while (True):
        userInput = input()
        cds = Decision.userInput(userInput)
        commands = cds.commands

        # print(cds.noErr)
        # print(commands)
        if cds.noErr:
            first = commands[0]
            if first == 0:  #createDataSet
                count = 10
                second = commands[1]
                third = commands[2]
                if second == 0:  #train
                    trainSet = dataSet.createSimpleSet(1, third, count)
                    nSample = trainSet.X.shape[1]  #batch크기 또는 train set 수
                elif second == 1:  #test
                    testSet = dataSet.createSimpleSet(1, third, count)

                print("  | create datsSet complete ")
                print("  | nSample = ", third)

            elif first == 1:  #autoBuild
                if len(commands) == 1:
                    layerStart = 0
                    layerLimit = 8
                elif len(commands) == 2:
                    layerStart = commands[1]
                    layerLimit = max(8, layerStart)
                elif len(commands) == 3:
                    layerStart = commands[1]
                    layerLimit = commands[2]
                if nSample > 0:
                    package = NeuralNetwork.autoBuilder(trainSet,
                                                        nSample,
                                                        layerStart=0,
                                                        layerLimit=8,
                                                        developmentMode=True)
                    # autoBuilder가 learning rate와 hiddenLayer의 수를 알아서 정해준다. 작업이 오래 걸릴 수 있음.
                    simpleNN = package[0]
                    learning_rate = package[1]
                    print("learning_rate", learning_rate)
                else:
                    print("  error : please load trainSet first")
                    print("  or create dataSet | use command   createDataSet")

            elif first == 2:  #model
                if len(commands) > 1:
                    second = commands[1]
                    if second == 0:  #train
                        if (learning_rate != 0) and (simpleNN != 0):
                            simpleNN.training_with_regularization(
                                trainSet, num_iterations, learning_rate)
                            train_acc = simpleNN.getAccuracy(trainSet)
                            print('train set Accuracy: %f' % train_acc + '%')
                        else:
                            print("  error : please build NN first")
                            print("  | use command   autoBuild")
                    elif second == 1:  #test
                        if (simpleNN != 0):
                            try:
                                train_acc = simpleNN.getAccuracy(trainSet)
                                test_acc = simpleNN.getAccuracy(testSet)
                                print('train set Accuracy: %f' % train_acc +
                                      '%')
                                print('test set Accuracy: %f' % test_acc + '%')
                            except:
                                print("  error : please load test set")
                        else:
                            print("  error : please build NN first")
                            print("  | use command   autoBuild")

            elif first == 3:  #loadDataSet
                second = commands[1]
                third = commands[2]
                count = 100
                if second == 0:  #train
                    trainSet = dataSet.loadDataSet(count, third)
                    nSample = trainSet.X.shape[1]  #batch크기 또는 train set 수
                elif second == 1:  #test
                    testSet = dataSet.loadDataSet(count, third)

                print("  | load datsSet complete ")
                print("  | nSample = ", nSample)