def main(mode): path = "/local/attale00/extracted_pascal__4__Multi-PIE" path_ea = path + "/color128/" allLabelFiles = utils.getAllFiles("/local/attale00/a_labels") labeledImages = [i[0:16] + ".png" for i in allLabelFiles] # labs=utils.parseLabelFiles(path+'/Multi-PIE/labels','mouth',labeledImages,cutoffSeq='.png',suffix='_face0.labels') labs = utils.parseLabelFiles( "/local/attale00/a_labels", "mouth", labeledImages, cutoffSeq=".png", suffix="_face0.labels" ) testSet = fg.dataContainer(labs) roi = (50, 74, 96, 160) X = fg.getAllImagesFlat(path_ea, testSet.fileNames, (128, 256), roi=roi) # perform ICA if mode not in ["s", "v"]: ica = FastICA(n_components=100, whiten=True) ica.fit(X) meanI = np.mean(X, axis=0) X1 = X - meanI data = ica.transform(X1) filters = ica.components_ elif mode in ["s", "v"]: W = np.load("/home/attale00/Desktop/classifiers/ica/filter1.npy") m = np.load("/home/attale00/Desktop/classifiers/ica/meanI1.npy") X1 = X - m data = np.dot(X1, W.T) for i in range(len(testSet.data)): testSet.data[i].extend(data[i, :]) strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)) # fg.getHogFeature(testSet,roi,path=path_ea,ending='.png',extraMask = None,orientations = 3, cells_per_block=(6,2),maskFromAlpha=False) # fg.getColorHistogram(testSet,roi,path=path_ea,ending='.png',colorspace='lab',bins=10) testSet.targetNum = map(utils.mapMouthLabels2Two, testSet.target) rf = classifierUtils.standardRF(max_features=np.sqrt(len(testSet.data[0])), min_split=5, max_depth=40) if mode in ["s", "v"]: print "Classifying with loaded classifier" classifierUtils.classifyWithOld( path, testSet, mode, clfPath="/home/attale00/Desktop/classifiers/ica/rf128ICA_1" ) elif mode in ["c"]: print "cross validation of data" print "Scores" # print classifierUtils.standardCrossvalidation(rf,testSet,n_jobs=5) # _cvDissect(testSet,rf) classifierUtils.dissectedCV(rf, testSet) print "----" elif mode in ["save"]: print "saving new classifier" _saveRF(testSet) else: print "not doing anything"
def main(mode): path = '/local/attale00/extracted_pascal__4__Multi-PIE' path_ea = path+'/color128/' allLabelFiles = utils.getAllFiles('/local/attale00/a_labels') labeledImages = [i[0:16]+'.png' for i in allLabelFiles] #labs=utils.parseLabelFiles(path+'/Multi-PIE/labels','mouth',labeledImages,cutoffSeq='.png',suffix='_face0.labels') labs=utils.parseLabelFiles('/local/attale00/a_labels','mouth',labeledImages,cutoffSeq='.png',suffix='_face0.labels') #fileNames = utils.getAllFiles(path_ea); #labs=utils.parseLabelFiles(path+'/labels/labels','mouth_opening',fileNames,cutoffSeq='.png',suffix='_face0.labels') testSet = fg.dataContainer(labs) roi=(50,74,96,160) #roi=(44,84,88,168) # eM=np.load('/home/attale00/Desktop/mouthMask.npy') # m=cv2.resize(np.uint8(eM),(256,256)); # strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) # dil = cv2.dilate(m,strel) # # m=dil>0; strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) fg.getHogFeature(testSet,roi,path=path_ea,ending='.png',extraMask = None,orientations = 8, cells_per_block=(6,2),maskFromAlpha=False) fg.getColorHistogram(testSet,roi,path=path_ea,ending='.png',colorspace='lab',bins=20) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = np.sqrt(len(testSet.data[0])),min_split=5,max_depth=40) if mode in ['s','v']: print 'Classifying with loaded classifier' _classifyWithOld(path,testSet,'s') elif mode in ['c']: print 'cross validation of data' print 'Scores' #print classifierUtils.standardCrossvalidation(rf,testSet,n_jobs=5) #_cvDissect(testSet,rf) classifierUtils.dissectedCV(rf,testSet) print '----' elif mode in ['save']: print 'saving new classifier' _saveRF(testSet) else: print 'not doing anything'
def main(mode): path = '/local/attale00/AFLW_ALL/' path_ea = '/local/attale00/AFLW_cropped/mouth_img_error/' # fileNames = utils.getAllFiles(path_ea); labs=utils.parseLabelFiles(path+'/labels/labels','mouth_opening',fileNames,cutoffSeq='.png',suffix='_face0.labels') testSet = fg.dataContainer(labs) fg_mode = 0 size=(4,12) overlap=2 #size=(40,120) fg.getImagePatchStat(testSet,path=path_ea,patchSize=size,overlap = overlap,mode=fg_mode) print 'feature vector length: {}'.format(len(testSet.data[0])) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = np.sqrt(len(testSet.data[0])),min_split=13,max_depth=40) #rf = svm.NuSVC() #rf = linear_model.SGDClassifier(loss='perceptron', eta0=1, learning_rate='constant', penalty=None) if mode in ['s','v']: print 'Classifying with loaded classifier' _classifyWithOld(path,testSet,mode) elif mode in ['c']: print 'cross validation of data' rValues = classifierUtils.dissectedCV(rf,testSet) pickle.dump(rValues,open('errorpatch_size_{}'.format(size[0]),'w')) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf) else: print 'not doing anything'
def main(mode): path = '/local/attale00/AFLW_ALL' path_ea = path+'/color256/' fileNames = utils.getAllFiles(path_ea); labs=utils.parseLabelFiles(path+'/labels/labels','mouth_opening',fileNames,cutoffSeq='.png',suffix='_face0.labels') testSet = fg.dataContainer(labs) roi=(88,165,150,362) #roi=(44,84,88,168) # eM=np.load('/home/attale00/Desktop/mouthMask.npy') # m=cv2.resize(np.uint8(eM),(256,256)); # strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) # dil = cv2.dilate(m,strel) # # m=dil>0; fg.getHogFeature(testSet,roi,path=path_ea,ending='.png',extraMask = None,orientations = 4, cells_per_block=(26,9),maskFromAlpha=False) fg.getColorHistogram(testSet,roi,path=path_ea,ending='.png',colorspace='lab',bins=20) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = np.sqrt(len(testSet.data[0])),min_split=5,max_depth=40) print len(testSet.data) if mode in ['s','v']: print 'Classifying with loaded classifier' _classifyWithOld(path,testSet,mode) elif mode in ['c']: print 'cross validation of data' #classifierUtils.standardCrossvalidation(rf,testSet,n_jobs=5) classifierUtils.dissectedCV(rf,testSet) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet) else: print 'not doing anything'
def main(mode): path='/local/attale00/' allFiles = utils.getAllFiles(path+'Multi-PIE/extracted') allLabelFiles = utils.getAllFiles(path+'Multi-PIE/labels') #allLabelFiles = utils.getAllFiles(path+'a_labels') labeledImages = [i[0:16]+'.png' for i in allLabelFiles] labs=utils.parseLabelFiles(path+'/Multi-PIE/labels','mouth',labeledImages,cutoffSeq='.png',suffix='_face0.labels') #labs=utils.parseLabelFiles(path+'a_labels','mouth',labeledImages,cutoffSeq='.png',suffix='_face0.labels') testSet = fg.dataContainer(labs) roi = (0,32,0,64) #roi = (128,256,0,256) eM=np.load('/home/attale00/Desktop/mouthMask.npy') m=cv2.resize(np.uint8(eM),(256,256)); strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) dil = cv2.dilate(m,strel) m=dil>0; fg.getHogFeature(testSet,roi,path=path+'Multi-PIE_grayScale64/',ending=None,extraMask = None) fg.getColorHistogram(testSet,(50,190,110,402),path = path+'/Multi-PIE/extracted/',ending=None,colorspace='lab',range=(1.,255.0),bins = 20) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) #testSet.targetNum = map(utils.mapGlassesLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = np.sqrt(len(testSet.data[0])),min_split=5,max_depth=40) if mode in ['s','v']: print 'Classifying with loaded classifier' _classifyWithOld(path,testSet,mode) elif mode in ['c']: print 'cross validation of data' classifierUtils.dissectedCV(rf,testSet) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf) else: print 'not doing anything'
def _cross_validate(testSet): rf=classifierUtils.standardRF(max_features = np.sqrt(len(testSet.data[0])),min_split=5,max_depth=40) #rf=svm.SVC(class_weight='auto') print 'Scores' #print classifierUtils.standardCrossvalidation(rf,testSet,n_jobs=5) classifierUtils.dissectedCV(rf,testSet) print '----' # print 'shuffeling the labels' # np.random.shuffle(testSet.targetNum) # # rf=classifierUtils.standardRF(max_features = np.sqrt(len(testSet.data[0])),min_split=5,max_depth=40) # #rf=svm.SVC(class_weight='auto') # print 'Scores' # print classifierUtils.standardCrossvalidation(rf,testSet,n_jobs=5) # print '----' return
def main(mode): path = '/local/attale00/AFLW_ALL/' path_ea = '/local/attale00/AFLW_cropped/mouth_img_error/' # fileNames = utils.getAllFiles(path_ea); labs=utils.parseLabelFiles(path+'/labels/labels','mouth_opening',fileNames,cutoffSeq='.png',suffix='_face0.labels') testSet = fg.dataContainer(labs) components = 150 roi=None X=fg.getAllImagesFlat(path_ea,testSet.fileNames,(40,120),roi=roi) # X=fg.getAllImagesFlat(path_ea,testSet.fileNames,(120,40),roi=roi,resizeFactor = .5) # # perform ICA if mode not in ['s','v']: ica = FastICA(n_components=components,whiten=True) ica.fit(X) meanI=np.mean(X,axis=0) X1=X-meanI data=ica.transform(X1) filters=ica.components_ elif mode in ['s','v']: W=np.load('/home/attale00/Desktop/classifiers/patches/filterMP1.npy') m=np.load('/home/attale00/Desktop/classifiers/patches/meanIMP1.npy') X1=X-m data=np.dot(X1,W.T) for i in range(len(fileNames)): testSet.data[i].extend(data[i,:]) print 'feature vector length: {}'.format(len(testSet.data[0])) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = np.sqrt(len(testSet.data[0])),min_split=13,max_depth=40) #rf = svm.NuSVC() #rf = linear_model.SGDClassifier(loss='perceptron', eta0=1, learning_rate='constant', penalty=None) if mode in ['s','v']: print 'Classifying with loaded classifier' _classifyWithOld(path,testSet,mode) elif mode in ['c']: print 'cross validation of data' rValues = classifierUtils.dissectedCV(rf,testSet) pickle.dump(rValues,open('errorpatch_ica','w')) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf,filters=filters,meanI=meanI) else: print 'not doing anything'
def main(mode): path = '/local/attale00/AFLW_ALL/' path_ea = '/local/attale00/AFLW_cropped/cropped3/' # fileNames = utils.getAllFiles(path_ea); labs=utils.parseLabelFiles(path+'/labels/labels','mouth_opening',fileNames,cutoffSeq='.png',suffix='_face0.labels') roi=None testSet = fg.dataContainer(labs) testSetMirror = fg.dataContainer(labs) for f in range(len(testSetMirror.fileNames)): testSetMirror.fileNames[f]+='M' orientations = 9 fg.getHogFeature(testSet,roi,path=path_ea,ending='.png',extraMask = None,orientations = orientations, cells_per_block=(3,3),pixels_per_cell=(24,8),maskFromAlpha=False) fg.getHogFeature(testSetMirror,roi,path='/local/attale00/AFLW_cropped/mirrored/', ending='.png',orientations = orientations, cells_per_block=(3,3),pixels_per_cell=(24,8)) testSet.addContainer(testSetMirror) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = 30,min_split=12,max_depth=70) #rf = svm.NuSVC() #rf = linear_model.SGDClassifier(loss='perceptron', eta0=1, learning_rate='constant', penalty=None) if mode in ['s','v']: print 'Classifying with loaded classifier' _classifyWithOld(path,testSet,mode) elif mode in ['c']: print 'cross validation of data' rValues = classifierUtils.dissectedCV(rf,testSet) pickle.dump(rValues,open('patches_cv_hog_{}'.format(orientations),'w')) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf) else: print 'not doing anything'
def main(mode): poses = multiPiePose() #poses = multiPiePoseOriginal() poseDict=splitByPose(poses,binmax=75, stepsize = 30) for k,v in poseDict.iteritems(): fn = [i[0] for i in v] labs=utils.parseLabelFiles(path_label,'mouth',fn,cutoffSeq='.png',suffix='_face0.labels') labs=dict((lk,lv) for (lk,lv) in labs.iteritems() if not lv.startswith('narr')) testSet = fg.dataContainer(labs) fg.getHogFeature(testSet,None,path=path_ea,ending='.png',extraMask = None,orientations = 9, cells_per_block=(3,3),pixels_per_cell=(24,8),maskFromAlpha=False) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = 30,min_split=12,max_depth=70) if mode in ['s','v']: print 'Classifying with loaded classifier' print '------------------- pose {}-----------------'.format(k) plt.figure() #obj=classifierUtils.classifyWithOld(path,testSet,mode,clfPath = '/home/attale00/Desktop/classifiers/thesis/poseSplit/pose{}'.format(k)) obj=classifierUtils.classifyWithOld(path,testSet,mode,clfPath = '/home/attale00/Desktop/classifiers/thesis/mirror/rfHogMirror'.format(k)) obj.plot(title='Mirrored,Pose: {}, ntot: {}, nOpen{}'.format(k,len(testSet.data),testSet.targetNum.count(1))) pickle.dump(obj,open('multiPie_mirror_aggregate{}'.format(k),'w')) elif mode in ['c']: print 'cross validation of data' rValues = classifierUtils.dissectedCV(rf,testSet) plt.title('Pose: {}, n: {}'.format(k,len(v))) #pickle.dump(rValues,open('patches_pose_hog_{}'.format(k),'w')) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf,identifier = k)
def main(mode): path = '/local/attale00/AFLW_ALL/' poses = aflwPose() poseDict=splitByPose(poses,binmax=100, stepsize = 40) for k,v in poseDict.iteritems(): fn = [i[0] for i in v] labs=utils.parseLabelFiles(path+'/labels/labels','mouth_opening',fn,cutoffSeq='.png',suffix='_face0.labels') testSet = fg.dataContainer(labs) fg.getHogFeature(testSet,None,path=path_ea,ending='.png',extraMask = None,orientations = 9, cells_per_block=(3,3),pixels_per_cell=(24,8),maskFromAlpha=False) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = 40,min_split=12,max_depth=70) if mode in ['s','v']: print 'Classifying with loaded classifier' _classifyWithOld(path,testSet,mode) elif mode in ['c']: print 'cross validation of data' rValues = classifierUtils.dissectedCV(rf,testSet) plt.title('Pose: {}, n: {}'.format(k,len(v))) #pickle.dump(rValues,open('patches_pose_hog_{}'.format(k),'w')) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf,identifier = k)
def main(mode): path = '/local/attale00/AFLW_ALL/' path_ea = '/local/attale00/AFLW_cropped/cropped3/' # fileNames = utils.getAllFiles(path_ea); # minr = 10000; # for f in fileNames: # im = cv2.imread(path_ea+f,-1) # if im.shape[0]!=40 or im.shape[1]!=120: # print f # print im.shape # minr = minr if im.shape[0]>= minr else im.shape[0] # # print minr # labs=utils.parseLabelFiles(path+'/labels/labels','mouth_opening',fileNames,cutoffSeq='.png',suffix='_face0.labels') testSet = fg.dataContainer(labs) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) roi=(0,37,0,115) roi=None #roi=(44,84,88,168) # eM=np.load('/home/attale00/Desktop/mouthMask.npy') # m=cv2.resize(np.uint8(eM),(256,256)); # strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) # dil = cv2.dilate(m,strel) # # m=dil>0; #X=fg.getAllImagesFlat(path_ea,testSet.fileNames,(40,120),roi=roi) # perform ICA names_open = [] names_closed = [] for i,f in enumerate(testSet.fileNames): if testSet.targetNum[i] == 0: names_closed.append(f) elif testSet.targetNum[i] == 1: names_open.append(f) Xopen = fg.getAllImagesFlat(path_ea,names_open,(40,120)) XClosed = fg.getAllImagesFlat(path_ea,names_closed,(40,120)) if mode not in ['s','v']: icaopen = FastICA(n_components=100,whiten=True) icaopen.fit(Xopen) meanIopen=np.mean(Xopen,axis=0) X1open=Xopen-meanIopen dataopen=icaopen.transform(X1open) filtersopen=icaopen.components_ plottingUtils.showICAComponents(filtersopen,(40,120),4,4) icaclosed = FastICA(n_components=100,whiten=True) icaclosed.fit(XClosed) meanIclosed=np.mean(XClosed,axis=0) X1closed=XClosed-meanIclosed dataclosed=icaclosed.transform(X1closed) filtersclosed=icaclosed.components_ plottingUtils.showICAComponents(filtersclosed,(40,120),4,4) plt.show() elif mode in ['s','v']: W=np.load('/home/attale00/Desktop/classifiers/patches/filterMP1.npy') m=np.load('/home/attale00/Desktop/classifiers/patches/meanIMP1.npy') X1=X-m data=np.dot(X1,W.T) for i in range(len(fileNames)): testSet.data[i].extend(data[i,:]) strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) #fg.getHogFeature(testSet,roi,path=path_ea,ending='.png',extraMask = None,orientations = 5, cells_per_block=(3,3),pixels_per_cell=(24,8),maskFromAlpha=False) #fg.getColorHistogram(testSet,roi,path=path_ea,ending='.png',colorspace='lab',bins=20) #pca # n_samples, n_features = X.shape # # mean_ = np.mean(X, axis=0) # X -= mean_ # U, S, V = linalg.svd(X) # explained_variance_ = (S ** 2) / n_samples # explained_variance_ratio_ = (explained_variance_ /explained_variance_.sum()) # K=V / S[:, np.newaxis] * np.sqrt(n_samples) # filters=K[:100] # data=np.dot(X,filters.T) rf=classifierUtils.standardRF(max_features = 27,min_split=13,max_depth=40) #rf = svm.NuSVC() #rf = linear_model.SGDClassifier(loss='perceptron', eta0=1, learning_rate='constant', penalty=None) if mode in ['s','v']: print 'Classifying with loaded classifier' _classifyWithOld(path,testSet,mode) elif mode in ['c']: print 'cross validation of data' classifierUtils.dissectedCV(rf,testSet) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf,filters=filters,meanI=meanI) else: print 'not doing anything'
def main(mode): path = '/local/attale00/AFLW_ALL/' path_ea = '/local/attale00/AFLW_cropped/mouth_img_error_multiPie/' allLabelFiles = utils.getAllFiles('/local/attale00/a_labels') labeledImages = [i[0:16]+'.png' for i in allLabelFiles] #labs=utils.parseLabelFiles(path+'/Multi-PIE/labels','mouth',labeledImages,cutoffSeq='.png',suffix='_face0.labels') labs=utils.parseLabelFiles('/local/attale00/a_labels','mouth',labeledImages,cutoffSeq='.png',suffix='_face0.labels') labs=dict((k,v) for (k,v) in labs.iteritems() if not v.startswith('narr')) # fileNames = labeledImages; # roi=None testSet = fg.dataContainer(labs) X=fg.getAllImagesFlat(path_ea,testSet.fileNames,(40,120),roi=roi) fgmode = 0 #fg.getImagePatchStat(testSet,path=path_ea,patchSize=(8,24),overlap = 2,mode=fgmode) roi=None orientations = 9 #fg.getHogFeature(testSet,roi,path=path_ea,ending='.png',extraMask = None,orientations = orientations, cells_per_block=(3,3),pixels_per_cell=(24,8),maskFromAlpha=False) # perform ICA if mode not in ['s','v']: ica = FastICA(n_components=100,whiten=True) ica.fit(X) meanI=np.mean(X,axis=0) X1=X-meanI data=ica.transform(X1) filters=ica.components_ elif mode in ['s','v']: W=np.load('/home/attale00/Desktop/classifiers/thesis/errorpatches/filter1.npy') m=np.load('/home/attale00/Desktop/classifiers/thesis/errorpatches/meanI1.npy') X1=X-m data=np.dot(X1,W.T) for i in range(len(testSet.fileNames)): testSet.data[i].extend(data[i,:]) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = 27,min_split=13,max_depth=40) #rf = svm.NuSVC() #rf = linear_model.SGDClassifier(loss='perceptron', eta0=1, learning_rate='constant', penalty=None) if mode in ['s','v']: print 'Classifying with loaded classifier' #r=classifierUtils.classifyWithOld(path,testSet,mode,clfPath = '/home/attale00/Desktop/classifiers/thesis/errorpatches/mode{}'.format(fgmode)) r=classifierUtils.classifyWithOld(path,testSet,mode,clfPath='/home/attale00/Desktop/classifiers/thesis/errorpatches/errorpatch_ica') pickle.dump(r,open('errorpatch_test_ica'.format(fgmode),'w')) elif mode in ['c']: print 'cross validation of data' classifierUtils.dissectedCV(rf,testSet) print classifierUtils.standardCrossvalidation(rf,testSet) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf,filters=filters,meanI=meanI) else: print 'not doing anything'
def main(mode): labelFiles='/local/attale00/aflw_original_labels' path_ea = '/local/attale00/AFLW_cropped/eyes/' fileNames = utils.getAllFiles(path_ea) goods = [] for f in fileNames: im = cv2.imread(path_ea+f) if im.shape[0] == 40 and im.shape[1] ==120: goods.append(f) fileNames = goods labs=utils.parseLabelFiles(labelFiles,'glasses',fileNames,cutoffSeq='.png',suffix='.labels') testSet = fg.dataContainer(labs) # # X=fg.getAllImagesFlat(path_ea,testSet.fileNames,(40,120),roi=roi) # # # # perform ICA # if mode not in ['s','v']: # ica = FastICA(n_components=100,whiten=True) # ica.fit(X) # meanI=np.mean(X,axis=0) # X1=X-meanI # data=ica.transform(X1) # filters=ica.components_ # # elif mode in ['s','v']: # W=np.load('/home/attale00/Desktop/classifiers/patches/filter2.npy') # m=np.load('/home/attale00/Desktop/classifiers/patches/meanI2.npy') # X1=X-m # data=np.dot(X1,W.T) # # for i in range(len(testSet.fileNames)): # testSet.data[i].extend(data[i,:]) # # strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) fg.getHogFeature(testSet,None,path=path_ea,ending='.png',extraMask = None,orientations = 5, pixels_per_cell=(24,8),cells_per_block=(3,3),maskFromAlpha=False) #testSet.targetNum=map(lambda x: 1 if x=='light' else 0,testSet.target) #rf = svm.NuSVC() #rf = linear_model.SGDClassifier(loss='perceptron', eta0=1, learning_rate='constant', penalty=None) if mode in ['s','v']: print 'Classifying with loaded classifier' obj=classifierUtils.classifyWithOld(path,testSet,mode,clfPath = '/home/attale00/Desktop/classifiers/thesis/color_only') #pickle.dump(obj,open('color_only','w')) elif mode in ['c']: print 'cross validation of data' testSet.targetNum=map(lambda x: 1 if x=='1' else 0,testSet.target) rf=classifierUtils.standardRF(max_features = 27,min_split=5,max_depth=60,n_estimators = 500) rValues = classifierUtils.dissectedCV(rf,testSet) plt.title('No glasses against rest') plt.show() #pickle.dump(rValues,open('patches_mp_','w')) elif mode in ['save']: print 'saving new classifier' testSet.targetNum=map(lambda x: 1 if x=='1' else 0,testSet.target) rf=classifierUtils.standardRF(max_features = 27,min_split=5,max_depth=60,n_estimators = 500) _saveRF(testSet,rf) else: print 'not doing anything'
def main(mode): path = '/local/attale00/AFLW_ALL' path_ea = path+'/color128/' fileNames = utils.getAllFiles(path_ea); labs=utils.parseLabelFiles(path+'/labels/labels','mouth_opening',fileNames,cutoffSeq='.png',suffix='_face0.labels') testSet = fg.dataContainer(labs) testSetMirror = fg.dataContainer(labs) for f in range(len(testSetMirror.fileNames)): testSetMirror.fileNames[f]+='M' roi=(50,74,96,160) X=fg.getAllImagesFlat(path_ea,testSet.fileNames,(128,256),roi=roi) Y=fg.getAllImagesFlat(path+'/mirror128/',testSet.fileNames,(128,256),roi=roi) Z=np.concatenate((X,Y),axis=0) # perform ICA ica = FastICA(n_components=100,whiten=True) ica.fit(Z) meanI=np.mean(Z,axis=0) X1=X-meanI Y1=Y-meanI data=ica.transform(X1) datam=ica.transform(Y1) filters=ica.components_ for i in range(len(fileNames)): testSet.data[i].extend(data[i,:]) testSetMirror.data[i].extend(datam[i,:]) strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) #fg.getHogFeature(testSet,roi,path=path_ea,ending='.png',extraMask = None,orientations = 3, cells_per_block=(6,2),maskFromAlpha=False) #fg.getColorHistogram(testSet,roi,path=path_ea,ending='.png',colorspace='lab',bins=10) #pca # n_samples, n_features = X.shape # # mean_ = np.mean(X, axis=0) # X -= mean_ # U, S, V = linalg.svd(X) # explained_variance_ = (S ** 2) / n_samples # explained_variance_ratio_ = (explained_variance_ /explained_variance_.sum()) # K=V / S[:, np.newaxis] * np.sqrt(n_samples) # filters=K[:100] # data=np.dot(X,filters.T) testSet.addContainer(testSetMirror) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = np.sqrt(len(testSet.data[0])),min_split=5,max_depth=40) if mode in ['s','v']: print 'Classifying with loaded classifier' _classifyWithOld(path,testSet,mode) elif mode in ['c']: print 'cross validation of data' classifierUtils.dissectedCV(rf,testSet) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf,filters=filters,meanI=meanI) else: print 'not doing anything'
def main(mode): path = '/local/attale00/extracted_pascal__4__Multi-PIE' path_ea = path+'/color128/' allLabelFiles = utils.getAllFiles('/local/attale00/a_labels') labeledImages = [i[0:16]+'.png' for i in allLabelFiles] #labs=utils.parseLabelFiles(path+'/Multi-PIE/labels','mouth',labeledImages,cutoffSeq='.png',suffix='_face0.labels') labs=utils.parseLabelFiles('/local/attale00/a_labels','mouth',labeledImages,cutoffSeq='.png',suffix='_face0.labels') testSet = fg.dataContainer(labs) roi=(50,74,96,160) # X=fg.getAllImagesFlat(path_ea,testSet.fileNames,(128,256),roi=roi) # # # # perform ICA # if mode not in ['s','v']: # ica = FastICA(n_components=50,whiten=True) # ica.fit(X) # meanI=np.mean(X,axis=0) # X1=X-meanI # data=ica.transform(X1) # filters=ica.components_ # # elif mode in ['s','v']: # W=np.load('/home/attale00/Desktop/classifiers/thesis/filter3.npy') # m=np.load('/home/attale00/Desktop/classifiers/thesis/meanI3.npy') # X1=X-m # data=np.dot(X1,W.T) # # for i in range(len(testSet.data)): # testSet.data[i].extend(data[i,:]) ### # # # # # strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) fg.getHogFeature(testSet,roi,path=path_ea,ending='.png',extraMask = None,orientations = 4, cells_per_block=(6,2),maskFromAlpha=False) fg.getPoseLabel(testSet,pathToPoseFiles='/local/attale00/poseLabels/multipie/') #fg.getColorHistogram(testSet,roi,path=path_ea,ending='.png',colorspace='lab',bins=40) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = np.sqrt(len(testSet.data[0])),min_split=5,max_depth=40) if mode in ['s','v']: print 'Classifying with loaded classifier' obj=classifierUtils.classifyWithOld(path,testSet,mode,clfPath = '/home/attale00/Desktop/classifiers/thesis/texture/hog_pose') pickle.dump(obj,open('hog_pose','w')) elif mode in ['c']: print 'cross validation of data' rValues = classifierUtils.dissectedCV(rf,testSet) pickle.dump(rValues,open('texture_mp_','w')) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet) else: print 'not doing anything'
def main(mode): path = '/local/attale00/AFLW_ALL' path_ea = path+'/color128/' fileNames = utils.getAllFiles(path_ea); labs=utils.parseLabelFiles(path+'/labels/labels','mouth_opening',fileNames,cutoffSeq='.png',suffix='_face0.labels') testSet = fg.dataContainer(labs) roi=(50,74,96,160) #roi=(44,84,88,168) # eM=np.load('/home/attale00/Desktop/mouthMask.npy') # m=cv2.resize(np.uint8(eM),(256,256)); # strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) # dil = cv2.dilate(m,strel) # # m=dil>0; path_mp = '/local/attale00/extracted_pascal__4__Multi-PIE/color128/' mpFiles = utils.getAllFiles(path_mp) X=fg.getAllImagesFlat(path_ea,testSet.fileNames,(128,256),roi=roi) #Y=fg.getAllImagesFlat(path_mp,mpFiles,(128,256),roi=roi) #Z=np.concatenate((X,Y),axis=0) Z=X # # perform ICA # ica = FastICA(n_components=50,whiten=True) # ica.fit(Z) # meanI=np.mean(X,axis=0) # # X1=X-meanI # data=ica.transform(X1) # filters=ica.components_ # for i in range(len(fileNames)): # testSet.data[i].extend(data[i,:]) bins = 40 strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) #fg.getHogFeature(testSet,roi,path=path_ea,ending='.png',extraMask = None,orientations = 3, cells_per_block=(6,2),maskFromAlpha=False) fg.getColorHistogram(testSet,roi,path=path_ea,ending='.png',colorspace='lab',bins=bins) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = np.sqrt(len(testSet.data[0])),min_split=1,max_depth=40) if mode in ['s','v']: print 'Classifying with loaded classifier' _classifyWithOld(path,testSet,mode) elif mode in ['c']: print 'cross validation of data' rValues = classifierUtils.dissectedCV(rf,testSet) pickle.dump(rValues,open('texture_color_{}'.format(bins),'w')) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf,filters=None,meanI=None) else: print 'not doing anything' return
def main(mode): path = '/local/attale00/AFLW_ALL/' path_ea = '/local/attale00/AFLW_cropped/cropped3/' # fileNames = utils.getAllFiles(path_ea); # minr = 10000; # for f in fileNames: # im = cv2.imread(path_ea+f,-1) # if im.shape[0]!=40 or im.shape[1]!=120: # print f # print im.shape # minr = minr if im.shape[0]>= minr else im.shape[0] # # print minr # labs=utils.parseLabelFiles(path+'/labels/labels','mouth_opening',fileNames,cutoffSeq='.png',suffix='_face0.labels') testSet = fg.dataContainer(labs) testSetMirror = fg.dataContainer(labs) for f in range(len(testSetMirror.fileNames)): testSetMirror.fileNames[f]+='M' roi=None #roi=(44,84,88,168) # eM=np.load('/home/attale00/Desktop/mouthMask.npy') # m=cv2.resize(np.uint8(eM),(256,256)); # strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) # dil = cv2.dilate(m,strel) # # m=dil>0; # # X=fg.getAllImagesFlat(path_ea,testSet.fileNames,(40,120),roi=roi) # Y=fg.getAllImagesFlat('/local/attale00/AFLW_cropped/mirrored/',testSet.fileNames,(40,120),roi=roi) # Z=np.concatenate((X,Y),axis=0) # # # perform ICA # ica = FastICA(n_components=100,whiten=True) # ica.fit(Z) # meanI=np.mean(Z,axis=0) # X1=X-meanI # Y1=Y-meanI # data=ica.transform(X1) # datam=ica.transform(Y1) # filters=ica.components_ # for i in range(len(fileNames)): # testSet.data[i].extend(data[i,:]) # testSetMirror.data[i].extend(datam[i,:]) ## # # # # strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) orientations = 9 fg.getHogFeature(testSet,roi,path=path_ea,ending='.png',extraMask = None,orientations = orientations, cells_per_block=(3,3),pixels_per_cell=(24,8),maskFromAlpha=False) fg.getHogFeature(testSetMirror,roi,path='/local/attale00/AFLW_cropped/mirrored/', ending='.png',orientations = orientations, cells_per_block=(3,3),pixels_per_cell=(24,8)) testSet.addContainer(testSetMirror) #pca # n_samples, n_features = X.shape # # mean_ = np.mean(X, axis=0) # X -= mean_ # U, S, V = linalg.svd(X) # explained_variance_ = (S ** 2) / n_samples # explained_variance_ratio_ = (explained_variance_ /explained_variance_.sum()) # K=V / S[:, np.newaxis] * np.sqrt(n_samples) # filters=K[:100] # data=np.dot(X,filters.T) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = 17,min_split=7,max_depth=40,n_estimators=200) #rf = svm.NuSVC() #rf = linear_model.SGDClassifier(loss='perceptron', eta0=1, learning_rate='constant', penalty=None) if mode in ['s','v']: print 'Classifying with loaded classifier' _classifyWithOld(path,testSet,mode) elif mode in ['c']: print 'cross validation of data' classifierUtils.dissectedCV(rf,testSet) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf,filters=filters,meanI=meanI) else: print 'not doing anything'
def main(mode): path = '/local/attale00/AFLW_ALL' path_ea = path+'/color128/' fileNames = utils.getAllFiles(path_ea); labs=utils.parseLabelFiles(path+'/labels/labels','mouth_opening',fileNames,cutoffSeq='.png',suffix='_face0.labels') testSet = fg.dataContainer(labs) roi=(50,74,96,160) # # # X=fg.getAllImagesFlat(path_ea,testSet.fileNames,(128,256),roi=roi) # #Y=fg.getAllImagesFlat(path_mp,mpFiles,(128,256),roi=roi) # #Z=np.concatenate((X,Y),axis=0) # Z=X # # #perform ICA # ica = FastICA(n_components=50,whiten=True) # ica.fit(Z) # meanI=np.mean(X,axis=0) # # X1=X-meanI # data=ica.transform(X1) # filters=ica.components_ # for i in range(len(fileNames)): # testSet.data[i].extend(data[i,:]) # orientations = 4 bins=40 fg.getHogFeature(testSet,roi,path=path_ea,ending='.png',extraMask = None,orientations = orientations, cells_per_block=(6,2),maskFromAlpha=False) fg.getPoseLabel(testSet,pathToPoseFiles='/local/attale00/poseLabels/aflw/') #fg.getColorHistogram(testSet,roi,path=path_ea,ending='.png',colorspace='lab',bins=bins) #pca # n_samples, n_features = X.shape # # mean_ = np.mean(X, axis=0) # X -= mean_ # U, S, V = linalg.svd(X) # explained_variance_ = (S ** 2) / n_samples # explained_variance_ratio_ = (explained_variance_ /explained_variance_.sum()) # K=V / S[:, np.newaxis] * np.sqrt(n_samples) # filters=K[:100] # data=np.dot(X,filters.T) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = np.sqrt(len(testSet.data[0])),min_split=1,max_depth=70) if mode in ['s','v']: print 'Classifying with loaded classifier' _classifyWithOld(path,testSet,mode) elif mode in ['c']: print 'cross validation of data' rValues = classifierUtils.dissectedCV(rf,testSet) #pickle.dump(rValues,open('texture_hog_{}'.format(orientations),'w')) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf,filters=None,meanI=None) else: print 'not doing anything' return
def main(mode): path = '/local/attale00/AFLW_ALL/' path_ea = '/local/attale00/AFLW_cropped/mouth_img_error_multiPie/' allLabelFiles = utils.getAllFiles('/local/attale00/a_labels') labeledImages = [i[0:16]+'.png' for i in allLabelFiles] #labs=utils.parseLabelFiles(path+'/Multi-PIE/labels','mouth',labeledImages,cutoffSeq='.png',suffix='_face0.labels') labs=utils.parseLabelFiles('/local/attale00/a_labels','mouth',labeledImages,cutoffSeq='.png',suffix='_face0.labels') # fileNames = labeledImages; # minr = 10000; # for f in fileNames: # im = cv2.imread(path_ea+f,-1) # if im.shape[0]!=40 or im.shape[1]!=120: # print f # print im.shape # minr = minr if im.shape[0]>= minr else im.shape[0] # # print minr # # testSet = fg.dataContainer(labs) roi=(0,37,0,115) roi=None fg.getImagePatchStat(testSet,path=path_ea,patchSize=(4,12),overlap = 2) #pca # n_samples, n_features = X.shape # # mean_ = np.mean(X, axis=0) # X -= mean_ # U, S, V = linalg.svd(X) # explained_variance_ = (S ** 2) / n_samples # explained_variance_ratio_ = (explained_variance_ /explained_variance_.sum()) # K=V / S[:, np.newaxis] * np.sqrt(n_samples) # filters=K[:100] # data=np.dot(X,filters.T) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = 27,min_split=13,max_depth=40) #rf = svm.NuSVC() #rf = linear_model.SGDClassifier(loss='perceptron', eta0=1, learning_rate='constant', penalty=None) if mode in ['s','v']: print 'Classifying with loaded classifier' classifierUtils.classifyWithOld(path,testSet,mode,clfPath = '/home/attale00/Desktop/classifiers/errorpatches/rferror') elif mode in ['c']: print 'cross validation of data' classifierUtils.dissectedCV(rf,testSet) print classifierUtils.standardCrossvalidation(rf,testSet) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf,filters=filters,meanI=meanI) else: print 'not doing anything'
def main(mode): path = '/local/attale00/AFLW_ALL/' path_ea = '/local/attale00/AFLW_cropped/multiPIE_cropped3/' allLabelFiles = utils.getAllFiles('/local/attale00/a_labels') labeledImages = [i[0:16]+'.png' for i in allLabelFiles] #labs=utils.parseLabelFiles(path+'/Multi-PIE/labels','mouth',labeledImages,cutoffSeq='.png',suffix='_face0.labels') labs=utils.parseLabelFiles('/local/attale00/a_labels','mouth',labeledImages,cutoffSeq='.png',suffix='_face0.labels') labs=dict((k,v) for (k,v) in labs.iteritems() if not v.startswith('narr')) # testSet = fg.dataContainer(labs) roi=(0,37,0,115) roi=None X=fg.getAllImagesFlat(path_ea,testSet.fileNames,(40,120),roi=roi) # perform ICA # if mode not in ['s','v']: # ica = FastICA(n_components=100,whiten=True) # ica.fit(X) # meanI=np.mean(X,axis=0) # X1=X-meanI # data=ica.transform(X1) # filters=ica.components_ # # elif mode in ['s','v']: # W=np.load('/home/attale00/Desktop/classifiers/thesis/filtercombined.npy') # m=np.load('/home/attale00/Desktop/classifiers/thesis/meancombined.npy') # X1=X-m # data=np.dot(X1,W.T) # # for i in range(len(testSet.fileNames)): # testSet.data[i].extend(data[i,:]) # # strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) #fg.getHogFeature(testSet,roi,path=path_ea,ending='.png',extraMask = None,orientations = 9, pixels_per_cell=(24,8),cells_per_block=(3,3),maskFromAlpha=False) fg.getColorHistogram(testSet,roi,path=path_ea,ending='.png',colorspace='lab',bins=40) #fg.getImagePatchStat(testSet,path='/local/attale00/AFLW_cropped/mouth_img_error_multiPie/',patchSize =(4,12)) #pca # n_samples, n_features = X.shape # # mean_ = np.mean(X, axis=0) # X -= mean_ # U, S, V = linalg.svd(X) # explained_variance_ = (S ** 2) / n_samples # explained_variance_ratio_ = (explained_variance_ /explained_variance_.sum()) # K=V / S[:, np.newaxis] * np.sqrt(n_samples) # filters=K[:100] # data=np.dot(X,filters.T) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = 27,min_split=13,max_depth=40) #rf = svm.NuSVC() #rf = linear_model.SGDClassifier(loss='perceptron', eta0=1, learning_rate='constant', penalty=None) if mode in ['s','v']: print 'Classifying with loaded classifier' obj=classifierUtils.classifyWithOld(path,testSet,mode,clfPath = '/home/attale00/Desktop/classifiers/thesis/color_only') pickle.dump(obj,open('color_only','w')) elif mode in ['c']: print 'cross validation of data' rValues = classifierUtils.dissectedCV(rf,testSet) pickle.dump(rValues,open('patches_mp_','w')) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf,filters=filters,meanI=meanI) else: print 'not doing anything'
def main(mode): path = '/local/attale00/AFLW_ALL/' path_ea = '/local/attale00/AFLW_cropped/cropped3/' # fileNames = utils.getAllFiles(path_ea); # minr = 10000; # for f in fileNames: # im = cv2.imread(path_ea+f,-1) # if im.shape[0]!=40 or im.shape[1]!=120: # print f # print im.shape # minr = minr if im.shape[0]>= minr else im.shape[0] # # print minr # labs=utils.parseLabelFiles(path+'/labels/labels','mouth_opening',fileNames,cutoffSeq='.png',suffix='_face0.labels') testSet = fg.dataContainer(labs) roi=(0,37,0,115) roi=None filters = None meanI = None #roi=(44,84,88,168) # eM=np.load('/home/attale00/Desktop/mouthMask.npy') # m=cv2.resize(np.uint8(eM),(256,256)); # strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) # dil = cv2.dilate(m,strel) # # m=dil>0; components = 150 X=fg.getAllImagesFlat(path_ea,testSet.fileNames,(40,120),roi=roi) # X=fg.getAllImagesFlat(path_ea,testSet.fileNames,(120,40),roi=roi,resizeFactor = .5) # # perform ICA if mode not in ['s','v']: ica = FastICA(n_components=components,whiten=True) ica.fit(X) meanI=np.mean(X,axis=0) X1=X-meanI data=ica.transform(X1) filters=ica.components_ elif mode in ['s','v']: W=np.load('/home/attale00/Desktop/classifiers/patches/filterMP1.npy') m=np.load('/home/attale00/Desktop/classifiers/patches/meanIMP1.npy') X1=X-m data=np.dot(X1,W.T) for i in range(len(fileNames)): testSet.data[i].extend(data[i,:]) #orientations = 2 #strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) #fg.getHogFeature(testSet,roi,path=path_ea,ending='.png',extraMask = None,orientations = 5, cells_per_block=(3,3),pixels_per_cell=(24,8),maskFromAlpha=False) #fg.getColorHistogram(testSet,(0,40,40,80),path=path_ea,ending='.png',colorspace='lab',bins=bins) #fg.getImagePatchStat(testSet,path=path_ea,patchSize=(4,12)) #fg.getImagePatchStat(testSet,path='/local/attale00/AFLW_cropped/mouth_img_error/',patchSize=(4,12)) #pca # n_samples, n_features = X.shape # # mean_ = np.mean(X, axis=0) # X -= mean_ # U, S, V = linalg.svd(X) # explained_variance_ = (S ** 2) / n_samples # explained_variance_ratio_ = (explained_variance_ /explained_variance_.sum()) # K=V / S[:, np.newaxis] * np.sqrt(n_samples) # filters=K[:100] # data=np.dot(X,filters.T) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) rf=classifierUtils.standardRF(max_features = 23,min_split=15,max_depth=70,n_estimators=150) #rf=classifierUtils.standardRF(max_features = 5,min_split=12,max_depth=45) #rf = svm.NuSVC() #rf = linear_model.SGDClassifier(loss='perceptron', eta0=1, learning_rate='constant', penalty=None) if mode in ['s','v']: print 'Classifying with loaded classifier' _classifyWithOld(path,testSet,mode) elif mode in ['c']: print 'cross validation of data' rValues = classifierUtils.dissectedCV(rf,testSet) pickle.dump(rValues,open('patches_cv_ica_{}'.format(components),'w')) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf,filters=filters,meanI=meanI) else: print 'not doing anything'
def main(mode): path = "/local/attale00/AFLW_ALL/" path_mirrored = "/local/attale00/AFLW_cropped/mirrored/" poses = aflwPose() binmax = 100 stepsize = 40 bins = range(-binmax, binmax, stepsize) poseDict = splitByPose(poses, bins=bins) testSets = {} # original Part for k, v in poseDict.iteritems(): fn = [i[0] for i in v] labs = utils.parseLabelFiles( path + "/labels/labels", "mouth_opening", fn, cutoffSeq=".png", suffix="_face0.labels" ) testSets[k] = fg.dataContainer(labs) fg.getHogFeature( testSets[k], None, path=path_ea, ending=".png", extraMask=None, orientations=9, cells_per_block=(3, 3), pixels_per_cell=(24, 8), maskFromAlpha=False, ) # mirrored part testSetsM = {} nBins = len(bins) for k, v in poseDict.iteritems(): binNumber = bins.index(k) oppositeBin = bins[nBins - 1 - binNumber] fn = [i[0] + "M" for i in poseDict[oppositeBin]] labs = utils.parseLabelFiles( path + "/labels/labels", "mouth_opening", fn, cutoffSeq=".pngM", suffix="_face0.labels" ) testSetsM[k] = fg.dataContainer(labs) fg.getHogFeature( testSetsM[k], None, path=path_mirrored, ending=".png", orientations=9, cells_per_block=(3, 3), pixels_per_cell=(24, 8), ) for k, v in poseDict.iteritems(): testSet = testSets[k] testSet.addContainer(testSetsM[k]) testSet.targetNum = map(utils.mapMouthLabels2Two, testSet.target) rf = classifierUtils.standardRF(max_features=40, min_split=12, max_depth=70) if mode in ["s", "v"]: print "Classifying with loaded classifier" _classifyWithOld(path, testSet, mode) elif mode in ["c"]: print "cross validation of data" rValues = classifierUtils.dissectedCV(rf, testSet) plt.title("Pose: {}, n: {}".format(k, len(testSet.data))) # pickle.dump(rValues,open('patches_pose_hog_{}'.format(k),'w')) elif mode in ["save"]: print "saving new classifier" _saveRF(testSet, rf, identifier=k)