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 patches(): 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('/local/attale00/a_labels','mouth',labeledImages,cutoffSeq='.png',suffix='_face0.labels') fileNames = labeledImages; testSet = fg.dataContainer(labs) roi=(0,37,0,115) roi=None X=fg.getAllImagesFlat(path_ea,testSet.fileNames,(40,120),roi=roi) 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(fileNames)): testSet.data[i].extend(data[i,:]) fg.getHogFeature(testSet,roi,path=path_ea,ending='.png',extraMask = None,orientations = 5, pixels_per_cell=(24,8),cells_per_block=(3,3),maskFromAlpha=False) fg.getColorHistogram(testSet,roi,path=path_ea,ending='.png',colorspace='lab',bins=20) testSet.targetNum=map(utils.mapMouthLabels2Two,testSet.target) clfPath = '/home/attale00/Desktop/classifiers/patches/rfICAHogColor' f=file(clfPath,'r') print 'classifier used: '+ f.name clf = pickle.load(f) testSet.classifiedAs=clf.predict(testSet.data) testSet.probabilities=clf.predict_proba(testSet.data) return testSet
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 main(mode): path = '/local/attale00/extracted_pascal__4__Multi-PIE' path_ea = path+'/color256/' 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=(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) if mode in ['s','v']: print 'Classifying with loaded classifier' _classifyWithOld(path,testSet,'v') elif mode in ['c']: print 'cross validation of data' _cross_validate(testSet) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet) else: print 'not doing anything'
def texture(): 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('/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) 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,:]) 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) clfPath = '/home/attale00/Desktop/classifiers/ica/rf128ICAHOGCOLOR' f=file(clfPath,'r') print 'classifier used: '+ f.name clf = pickle.load(f) testSet.classifiedAs=clf.predict(testSet.data) testSet.probabilities=clf.predict_proba(testSet.data) return testSet
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')) # # 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 #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 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,roi,path=path_ea,ending='.png',extraMask = None,orientations = 5, pixels_per_cell=(24,8),cells_per_block=(3,3),maskFromAlpha=False) fg.getColorHistogram(testSet,roi,path=path_ea,ending='.png',colorspace='lab',bins=20) #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' classifierUtils.classifyWithOld(path,testSet,mode,clfPath = '/home/attale00/Desktop/classifiers/patches/rfICAHogColor') 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=None 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.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_combined'.format(orientations),'w')) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf,filters=filters,meanI=meanI) 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); 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 components = 35 #100 #150 bins=40 orientations = 9 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,:]) #strel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) 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.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 = 40,min_split=15,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_combined','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_mp = '/local/attale00/extracted_pascal__4__Multi-PIE' path_eamp = path_mp+'/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') labsmp=utils.parseLabelFiles('/local/attale00/a_labels','mouth',labeledImages,cutoffSeq='.png',suffix='_face0.labels') 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) testSetmp = fg.dataContainer(labsmp) 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; X=fg.getAllImagesFlat(path_ea,testSet.fileNames,(128,256),roi=roi) Y=fg.getAllImagesFlat(path_eamp,testSetmp.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) datamp = ica.transform(Y1) filters=ica.components_ for i in range(len(testSet.fileNames)): testSet.data[i].extend(data[i,:]) for i in range(len(testSetmp.fileNames)): testSetmp.data[i].extend(datamp[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) fg.getHogFeature(testSetmp,roi,path=path_eamp,ending='.png',extraMask = None,orientations = 3, cells_per_block=(6,2),maskFromAlpha=False) fg.getColorHistogram(testSetmp,roi,path=path_eamp,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(testSetmp) 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/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') withColor={} for k in labs: f_name = path_ea+k im = cv2.imread(f_name,-1) c=np.shape(im) if len(c)== 3 and c[2]>=3: withColor[k]=labs[k] labs = withColor 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; # 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=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/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,:]) bins = 40 #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.getPoseLabel(testSet,pathToPoseFiles='/local/attale00/poseLabels/aflw/') #fg.getColorHistogram(testSet,(0,40,0,120),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=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_color_{}'.format(bins),'w')) elif mode in ['save']: print 'saving new classifier' _saveRF(testSet,rf,filters=None,meanI=None) 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