示例#1
0
    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

  
    
# AFW test - Make the pickle data set
if 'createAFW_TestSet' in STEPS:
示例#2
0
    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

  
  
if 'trainSetHD5' in STEPS:
 PATH_TO_DEPLOY_TXT_DM = os.path.join('/data/b0216.yu/LD_Train/Parts/DownMouth/', 'parts_40x40.prototxt') 
 predictorDM = Predictor(protoTXTPath=PATH_TO_DEPLOY_TXT_DM, weightsPath=PATH_TO_WEIGHTS_DM, meanPath=MEAN_TRAIN_DM, stdPath=STD_TRAIN_DM) 
 '''
 testError=ErrorAcum()
 
 ttime = 0.0
 
 for i, dataRow in enumerate(dataRowsTestValid):
 
   start_time = time.time()
   
   fbbox = BBox(dataRow.fbbox.left,dataRow.fbbox.top,dataRow.fbbox.right,dataRow.fbbox.bottom)      
   
   dataRow40 = dataRow.copyCroppedByBBox_68(fbbox)
   image, lm40 = root_predictor.preprocess(dataRow40.image, dataRow40.landmarks_68())
   prediction = root_predictor.predict(image)
   prediction = dataRow40.inverseScaleAndOffset((prediction + 0.5) * GLOBAL_IMAGE_SIZE)
   
   # Rotate & refine - yubing 20160727
   dataRowRot, rotangleT = dataRow.copyCropped_68_rot(prediction,fbbox)
   imageRot, lmRot = root_predictor.preprocess(dataRowRot.image, dataRow40.landmarks_68())
   predictionRot = root_predictor.predict(imageRot)
   predictionRot = dataRowRot.inverseScaleAndOffset((predictionRot + 0.5) * GLOBAL_IMAGE_SIZE)
   prediction = dataRow.reverseRotate(predictionRot, -rotangleT)
   
   # Local part refine - yubing 20160701
   # Left Eye
   dataRowLE, rotangle = dataRow.copyCropped_patch(prediction,'LE',rotangleT)
   imageLE, lm40 = predictorLE.preprocess(dataRowLE.image, dataRow40.landmarks_68())
   predictionLE = predictorLE.predict(imageLE)
   predictionLE = dataRowLE.inverseScaleAndOffset((predictionLE + 0.5) * 40)