dump(dataRowsTestValid[0:10],f) print "Finished dumping to testSetMini.pickle" if 'testSetHD5' in STEPS: writeHD5(dataRowsTestValid, ROOT+'/caffeData/hd5/test.hd5', ROOT+'/caffeData/test.txt', MEAN_TRAIN_SET, STD_TRAIN_SET) print "Finished writing test to caffeData/test.txt" DEBUG = True if 'testErrorMini' in STEPS: with open('testSetMini.pickle','r') as f: dataRowsTrainValid = load(f) testErrorMini=ErrorAcum() predictor = Predictor(protoTXTPath=PATH_TO_DEPLOY_TXT, weightsPath=PATH_TO_WEIGHTS) for i, dataRow in enumerate(dataRowsTrainValid): dataRow40 = dataRow.copyCroppedByBBox(dataRow.fbbox).copyMirrored() image, lm_0_5 = predictor.preprocess(dataRow40.image, dataRow40.landmarks()) prediction = predictor.predict(image) testErrorMini.add(lm_0_5, prediction) dataRow40.prediction = (prediction+0.5)*40. # Scale -0.5..+0.5 to 0..40 if DEBUG: dataRow.prediction = dataRow40.inverseScaleAndOffset(dataRow40.prediction) # Scale up to the original image scale dataRow.show() if i>40: print "Debug breaked after %d rows:" % i print "Test Error mini:", testErrorMini
########################### STEPS TO RUN #################### STEPS = ['testErro'] ########################################## SCRIPT STEPS ################################################## if 'testErro' in STEPS: print "Loading image set....." dataRowsTest_CSV = createDataRowsFromCSV(CSV_TEST , DataRow.DataRowFromNameBoxInterlaved_68, DATA_PATH) print "Finished reading %d rows from image" % len(dataRowsTest_CSV) dataRowsTestValid,R = getValidWithBBox_68(dataRowsTest_CSV) print "Original image:",len(dataRowsTest_CSV), "Valid Rows:", len(dataRowsTestValid), " noFacesAtAll", R.noFacesAtAll, " outside:", R.outsideLandmarks, " couldNotMatch:", R.couldNotMatch # Best models - yubing 20160718 ROOT_DEPLOY_TXT = '/data/b0216.yu/LD_Train/68Data/Models60/vanilla_deploy_60x60.prototxt' ROOT_MODEL = '/data/b0216.yu/LD_Train/68Data/Models60/LD_usc_iter_90000.caffemodel' root_predictor = Predictor(protoTXTPath=ROOT_DEPLOY_TXT, weightsPath=ROOT_MODEL, meanPath=MEAN_TRAIN_SET, stdPath=STD_TRAIN_SET) MEAN_TRAIN_LE_BEST = os.path.join('/data/b0216.yu/LD_Train/Parts/Models/LeftEye/', 'MeanFace.png') STD_TRAIN_LE_BEST = os.path.join('/data/b0216.yu/LD_Train/Parts/Models/LeftEye/', 'StdVar.png') MEAN_TRAIN_RE_BEST = os.path.join('/data/b0216.yu/LD_Train/Parts/Models/RightEye/', 'MeanFace.png') STD_TRAIN_RE_BEST = os.path.join('/data/b0216.yu/LD_Train/Parts/Models/RightEye/', 'StdVar.png') MEAN_TRAIN_Mo_BEST = os.path.join('/data/b0216.yu/LD_Train/Parts/Models/Mouth/', 'MeanFace.png') STD_TRAIN_Mo_BEST = os.path.join('/data/b0216.yu/LD_Train/Parts/Models/Mouth/', 'StdVar.png') MEAN_TRAIN_No_BEST = os.path.join('/data/b0216.yu/LD_Train/Parts/Models/Nose/', 'MeanFace.png') STD_TRAIN_No_BEST = os.path.join('/data/b0216.yu/LD_Train/Parts/Models/Nose/', 'StdVar.png') MEAN_TRAIN_Co_BEST = os.path.join('/data/b0216.yu/LD_Train/Parts/Models/Contour/', 'MeanFace.png') STD_TRAIN_Co_BEST = os.path.join('/data/b0216.yu/LD_Train/Parts/Models/Contour/', 'StdVar.png')
if i>40: print "Debug breaked after %d rows:" % i print "Test Error mini:", testErrorMini ''' # Run the same caffe test set using python DEBUG = False # Set this to true if you wish to plot the images if 'testError' in STEPS: with open('testSet.pickle','r') as f: dataRowsTrainValid = load(f) testError=ErrorAcum() predictor = Predictor(protoTXTPath=PATH_TO_DEPLOY_TXT, weightsPath=PATH_TO_WEIGHTS) for i, dataRow in enumerate(dataRowsTrainValid): dataRow40 = dataRow.copyCroppedByBBox(dataRow.fbbox) image, lm40 = predictor.preprocess(dataRow40.image, dataRow40.landmarks()) prediction = predictor.predict(image) testError.add(lm40, prediction) dataRow40.prediction = (prediction+0.5)*40. if DEBUG and i%40 ==0: dataRow.prediction = dataRow40.inverseScaleAndOffset(dataRow40.prediction) dataRow.show() break print "Test Error:", testError
sys.path.append(os.path.join('/home/ly/workspace/Vanilla-40', 'python')) # Assume git root directory ########################### PATHS TO SET #################### # Either define CAFFE_ROOT in your enviroment variables or set it here CAFFE_ROOT = os.environ.get('CAFFE_ROOT','~/caffe/distribute') sys.path.append(CAFFE_ROOT+'/python') # Add caffe python path so we can import it import caffe #Import helper functions from DataRow import DataRow, BBox, Predictor PATH_TO_WEIGHTS = os.path.join('/home/ly/workspace/Vanilla-40', 'caffeData', 'snapshots_60_medium_ibug_0.04c_0.04s', 'snap_iter_80000.caffemodel') #PATH_TO_WEIGHTS = os.path.join('/home/ly/workspace/Vanilla-40', 'caffeData', 'snapshots-40-unit-cvt1-inner', 'snap_iter_670000.caffemodel') PATH_TO_DEPLOY_TXT = os.path.join('/home/ly/workspace/Vanilla-40', 'ZOO', 'vanilla_deploy_60_medium.prototxt') predictor = Predictor(protoTXTPath=PATH_TO_DEPLOY_TXT, weightsPath=PATH_TO_WEIGHTS) # Make sure dlib python path exists on PYTHONPATH else "pip install dlib" if needed. import dlib detector=dlib.get_frontal_face_detector() # Load dlib's face detector img_path = os.path.join('/home/ly/workspace/Vanilla-40/TestSet','helen_3139620200_1.jpg') img = cv2.imread(img_path) #dets = detector( np.array(img, dtype = 'uint8' ), 1) dets = [[1]] for det in dets: