Пример #1
0
def train(readFromFile=True, path="./training3/"):
    """
    train the image processor
    :return: True if the training succeeds, false otherwise.
    """

    for i in range(7):
        ratioKnns.append(LetterKnnClassifier())

    print ratioKnns

    fs = listdir(path)

    for f in fs:
        s = f.split(".")
        if len(s) < 2:
            continue

        s = f.split("_")
        if len(s) < 2:
            continue

        c1 = const.getConstantFromString(s[0])

        c2 = cc.getColorFromId(c1)

        if c2 is not None:
            ratioKnns[c2].loadTrainingImage(path + f, c1)
            print "LetterClass. " + str(c2) + ":" + str(
                cc.getColorFromNumber(c2)) + " trained: " + f + " as " + str(
                    const.getStringFromNumber(c1))

    knn.populateData()
    knn.trainModel()

    for r in ratioKnns:
        r.trainModel()

    print "Completed training"
    print "------------------"
Пример #2
0
def train(readFromFile=True, path="./training3/"):
    """
    train the image processor
    :return: True if the training succeeds, false otherwise.
    """

    for i in range(7):
        ratioKnns.append(LetterKnnClassifier())

    print ratioKnns

    fs = listdir(path)

    for f in fs:
        s = f.split(".")
        if len(s) < 2:
            continue

        s = f.split("_")
        if len(s) < 2:
            continue

        c1 = const.getConstantFromString(s[0])

        c2 = cc.getColorFromId(c1)

        if c2 is not None:
            ratioKnns[c2].loadTrainingImage(path + f, c1)
            print "LetterClass. " + str(c2) + ":" + str(
                cc.getColorFromNumber(c2)) + " trained: " + f + " as " + str(const.getStringFromNumber(c1))

    knn.populateData()
    knn.trainModel()

    for r in ratioKnns:
        r.trainModel()

    print "Completed training"
    print "------------------"
Пример #3
0
path = "./training3/"

fs = listdir(path)

for f in fs:
    s = f.split(".")
    if len(s) < 2:
        continue

    s = f.split("_")
    if len(s) < 2:
        continue

    c1 = const.getConstantFromString(s[0])

    c2 = cc.getColorFromId(c1)

    if c2 is not None:
        ratioKnns[c2].loadTrainingImage(path+f, c1)
        print "LetterClass. "+str(c2)+":"+str(cc.getColorFromNumber(c2))+" trained: "+f+ " as "+str(const.getStringFromNumber(c1))

knn.populateData()
knn.trainModel()

for r in ratioKnns:
    r.trainModel()

print "done training"

print len(knn.train)
Пример #4
0
path = "./training3/"

fs = listdir(path)

for f in fs:
    s = f.split(".")
    if len(s) < 2:
        continue

    s = f.split("_")
    if len(s) < 2:
        continue

    c1 = const.getConstantFromString(s[0])

    c2 = cc.getColorFromId(c1)

    if c2 is not None:
        ratioKnns[c2].loadTrainingImage(path + f, c1)
        print "LetterClass. " + str(c2) + ":" + str(cc.getColorFromNumber(c2)) + " trained: " + f + " as " + str(
            const.getStringFromNumber(c1)
        )

knn.populateData()
knn.trainModel()

for r in ratioKnns:
    r.trainModel()

print "done training"