def populateData(self): path = "./training3/" fs = listdir(path) #print fs for f in fs: s = f.split(".") if len(s) < 2: continue s = f.split("_") if len(s) < 2: continue c = const.getConstantFromString(s[0]) c = cc.getColorFromId(c) if c is not None: self.loadTrainingImage(path + f, c) print "trained: " + path + f + " as " + str(c) return
def populateData(self): path = "./training3/" fs = listdir(path) #print fs for f in fs: s = f.split(".") if len(s) < 2: continue s = f.split("_") if len(s) < 2: continue c = const.getConstantFromString(s[0]) c = cc.getColorFromId(c) if c is not None: self.loadTrainingImage(path+f, c) print "trained: "+path+f+ " as "+str(c) return
def train(self, readFromFile=True, path="./training3/"): """ train the image processor :return: True if the training succeeds, false otherwise. """ self.knn = ColorKnnClassifier() self.ratioKnns = [] for i in range(7): self.ratioKnns.append(LetterKnnClassifier()) if readFromFile: f = open(path, 'r') for l in f: l = l.split(",") x = [float(i) for i in l[1:]] self.ratioKnns[cc.getColorFromId(int(l[0]))].train.append((int(l[0]), x)) f.close() f = open("color_data.csv", 'r') for l in f: l = l.split(',') x = [float(i) for i in l[1:]] self.knn.train.append((int(l[0]), x)) f.close() else: 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: self.ratioKnns[c2].loadTrainingImage(path + f, c1) print "LetterClass. " + str(c2) + ":" + str( cc.getColorFromNumber(c2)) + " trained: " + f + " as " + str(const.getStringFromNumber(c1)) self.knn.trainModel() for r in self.ratioKnns: r.trainModel() print "Completed training" print "------------------"
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"
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()
def train(self, readFromFile=True, path="./training3/"): """ train the image processor :return: True if the training succeeds, false otherwise. """ self.knn = ColorKnnClassifier() self.ratioKnns = [] for i in range(7): self.ratioKnns.append(LetterKnnClassifier()) if readFromFile: f = open(path, 'r') for l in f: l = l.split(",") x = [float(i) for i in l[1:]] self.ratioKnns[cc.getColorFromId(int(l[0]))].train.append( (int(l[0]), x)) f.close() f = open("color_data.csv", 'r') for l in f: l = l.split(',') x = [float(i) for i in l[1:]] self.knn.train.append((int(l[0]), x)) f.close() else: 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: self.ratioKnns[c2].loadTrainingImage(path + f, c1) print "LetterClass. " + str(c2) + ":" + str( cc.getColorFromNumber( c2)) + " trained: " + f + " as " + str( const.getStringFromNumber(c1)) self.knn.trainModel() for r in self.ratioKnns: r.trainModel() print "Completed training" print "------------------"