Beispiel #1
0
def test_imageloader():
    data = ImageDataSet(28, 28)
    data.loadImageData("digitdata/trainingimages", 1)

    matrix = np.array(data.images[0])
    print(matrix)
    print(data.number)
Beispiel #2
0
def lay():
    data = ImageDataSet(28, 28)
    data.loadImageData("digitdata/trainingimages", -1)
    data.loadLabelData("digitdata/traininglabels", data.number)
    nn = NeuralNetwork((28 * 28, 28, 14, 10),
                       ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
    testdata = ImageDataSet(28, 28)
    testdata.loadImageData("digitdata/testimages", -1)
    testdata.loadLabelData("digitdata/testlabels", testdata.number)

    for _ in range(50):
        print("Time:%d" % _)
        nn.train(data.images, data.labels, 1, 0.3)
        x = nn.classify(testdata.images)
        a = Accuracy(x, testdata.labels)
        print()
        print("Accuracy is : %d" % (a * 100))
Beispiel #3
0
def ops():

    testdata = ImageDataSet(28, 28)
    testdata.loadImageData("digitdata/testimages", -1)
    testdata.loadLabelData("digitdata/testlabels", testdata.number)
    data = ImageDataSet(28, 28)
    data.loadImageData("digitdata/trainingimages", -1)
    data.loadLabelData("digitdata/traininglabels", data.number)
    for t in range(20, 101, 20):
        images, labels = data.shuffleout(t)
        al = []
        il = []
        pc = Perceptron(28 * 28,
                        ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
        for i in range(100):
            pc.train(images, labels, 1, 0.8)
            x = pc.classify(testdata.images)
            a = Accuracy(x, testdata.labels)
            al.append(a * 100)
            il.append(i + 1)
            print(a * 100)
        plt.plot(il, al, label="size=%d" % (t * 0.01 * data.number))

    leg = plt.legend(ncol=2, shadow=True, fancybox=True)
    leg.get_frame().set_alpha(0.5)
    plt.xlim([1, 100])
    plt.xlabel("trainning time")
    plt.ylabel("accuracy")

    plt.show()
Beispiel #4
0
def nntest():
    data = ImageDataSet(28, 28)
    data.loadImageData("digitdata/trainingimages", 20)
    data.loadLabelData("digitdata/traininglabels", data.number)
    #print(   np.array(data.images[0]) / 2  )
    nn = NeuralNetwork(28 * 28, 15,
                       ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
    nn.train(data.images, data.labels, 50)

    testdata = ImageDataSet(28, 28)
    testdata.loadImageData("digitdata/testimages", 3)
    testdata.loadLabelData("digitdata/testlabels", testdata.number)

    x = nn.classify(testdata.images)
    print(testdata.labels)
    print(x)

    a = Accuracy(x, testdata.labels)

    print()
    print("Accuracy is : %d" % (a * 100))
Beispiel #5
0
def dataloader_digit(n_train=-1, n_test=-1):
    data = ImageDataSet(
        28, 28, labeldomain=['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
    data.loadImageData("digitdata/trainingimages", n_train)
    data.loadLabelData("digitdata/traininglabels", data.number)
    testdata = ImageDataSet(28, 28)
    testdata.loadImageData("digitdata/testimages", n_test)
    testdata.loadLabelData("digitdata/testlabels", testdata.number)
    return data, testdata
Beispiel #6
0
def dataloader_face(n_train=-1, n_test=-1):
    data = ImageDataSet(70, 60, labeldomain=['0', '1'])
    data.loadImageData("facedata/facedatatrain", n_train)
    data.loadLabelData("facedata/facedatatrainlabels", data.number)
    testdata = ImageDataSet(70, 60)
    testdata.loadImageData("facedata/facedatatest", n_test)
    testdata.loadLabelData("facedata/facedatatestlabels", testdata.number)
    return data, testdata
Beispiel #7
0
def layface():
    data = ImageDataSet(70, 60)
    data.loadImageData("facedata/facedatatrain", -1)
    data.loadLabelData("facedata/facedatatrainlabels", data.number)
    nn = NeuralNetwork((70 * 60, 30, 25, 25, 2), ['0', '1'])
    testdata = ImageDataSet(70, 60)
    testdata.loadImageData("facedata/facedatatest", -1)
    testdata.loadLabelData("facedata/facedatatestlabels", testdata.number)

    for _ in range(50):
        print("Time:%d" % _)
        nn.train(data.images, data.labels, 2, 0.5)
        x = nn.classify(testdata.images)
        a = Accuracy(x, testdata.labels)
        print()
        print("Accuracy is : %d" % (a * 100))
def dataloader_face(Tranum=-1, Testnum=-1):
    data = ImageDataSet(70, 60, labeldomain=['0', '1'])
    # data.loadImageData("facedata/facedatatrain", Tranum)
    # data.loadLabelData("facedata/facedatatrainlabels", data.number)
    data.loadImageData("facedata/facedatatrain", Tranum)
    data.loadLabelData("facedata/facedatatrainlabels", data.number)
    Data_test = ImageDataSet(70, 60)
    Data_test.loadImageData("facedata/facedatavalidation", Testnum)
    Data_test.loadLabelData("facedata/facedatavalidationlabels",
                            Data_test.number)
    # Data_test.loadImageData("facedata/facedatatest", Testnum)
    # Data_test.loadLabelData("facedata/facedatatestlabels", Data_test.number)
    return data, Data_test
def dataloader_digit(Tranum=-1, Testnum=-1):
    data = ImageDataSet(
        28, 28, labeldomain=['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
    # data.loadImageData("digitdata/trainingimages", Tranum)
    # data.loadLabelData("digitdata/traininglabels", data.number)
    data.loadImageData("digitdata/trainingimages", Tranum)
    data.loadLabelData("digitdata/traininglabels", data.number)
    Data_test = ImageDataSet(28, 28)
    Data_test.loadImageData("digitdata/validationimages", Testnum)
    Data_test.loadLabelData("digitdata/validationlabels", Data_test.number)
    # Data_test.loadImageData("digitdata/testimages", Testnum)
    # Data_test.loadLabelData("digitdata/testlabels", Data_test.number)
    return data, Data_test