Beispiel #1
0
 # Now read in the image data. Apply filters, scale to 128 x 128 pixel:
 [X, y] = read_images(sys.argv[1], yale_subset_0_40, sz=(64, 64))
 # Set up a handler for logging:
 handler = logging.StreamHandler(sys.stdout)
 formatter = logging.Formatter(
     '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
 handler.setFormatter(formatter)
 # Add handler to facerec modules, so we see what's going on inside:
 logger = logging.getLogger("facerec")
 logger.addHandler(handler)
 logger.setLevel(logging.INFO)
 # The models we want to evaluate:
 model0 = PredictableModel(
     feature=SpatialHistogram(lbp_operator=ExtendedLBP()),
     classifier=NearestNeighbor(dist_metric=ChiSquareDistance(), k=1))
 model1 = PredictableModel(feature=SpatialHistogram(lbp_operator=LPQ()),
                           classifier=NearestNeighbor(
                               dist_metric=ChiSquareDistance(), k=1))
 # The sigmas we'll apply for each run:
 sigmas = [0]
 print('The experiment will be run %s times!' % ITER_MAX)
 # Initialize experiments (with empty results):
 experiments = {}
 experiments['lbp_model'] = {
     'model': model0,
     'results': {},
     'color': 'r',
     'linestyle': '--',
     'marker': '*'
 }
 experiments['lpq_model'] = {
Beispiel #2
0
    test_faces = []
    for image, id in test_list:
        test_faces.append((id, utils.read_image(os.path.join(test_path, image))))

    # Then set up a handler for logging:
    handler = logging.StreamHandler(sys.stdout)
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    handler.setFormatter(formatter)
    # Add handler to facerec modules, so we see what's going on inside:
    logger = logging.getLogger("facerec")
    logger.addHandler(handler)
    logger.setLevel(logging.DEBUG)

    # ætla að prófa allar aðferðir
    # feature = Fisherfaces()
    m = (Fisherfaces(), PCA(), SpatialHistogram(), SpatialHistogram(LPQ()))

    classifiers = (
        # Define a 1-NN classifier with Euclidean Distance:
        NearestNeighbor(dist_metric=EuclideanDistance(), k=3),
        NearestNeighbor(dist_metric=CosineDistance(), k=3),
        NearestNeighbor(dist_metric=NormalizedCorrelation(), k=3),
        NearestNeighbor(dist_metric=ChiSquareDistance(), k=3),
        NearestNeighbor(dist_metric=HistogramIntersection(), k=3),
        NearestNeighbor(dist_metric=L1BinRatioDistance(), k=3),
        NearestNeighbor(dist_metric=ChiSquareBRD(), k=3),
    )

    def test_one(idx):
        tt, pt, res_list = test_one_method(input_faces, test_faces, m[idx], classifiers[idx], True)
        print tt, ",", pt
Beispiel #3
0
    def __init__(self,
                 database_folder,
                 feature_parameter="LPQ",
                 metric="chi",
                 k=3):
        self.model = None

        handler = logging.StreamHandler(sys.stdout)
        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        handler.setFormatter(formatter)
        logger = logging.getLogger("facerec")
        logger.addHandler(handler)
        logger.setLevel(logging.DEBUG)

        path = database_folder

        start = time.clock()
        input_faces = utils.read_images_from_single_folder(path)
        stop = time.clock()

        print("read {}, images from {} in {} seconds.".format(
            len(input_faces), path, stop - start))

        feature = None
        m = {
            "fisher": Fisherfaces,
            "fisher80": Fisherfaces,
            "pca": PCA,
            "pca10": PCA,
            "lda": LDA,
            "spatial": SpatialHistogram,
            "LPQ": SpatialHistogram
        }

        if feature_parameter in m:
            if feature_parameter == 'LPQ':
                feature = SpatialHistogram(LPQ())
                self.threshold = threshold_function(71.4, 70)
            elif feature_parameter == 'fisher80':
                feature = Fisherfaces(80)
                self.threshold = threshold_function(0.61, 0.5)
            elif feature_parameter == 'fisher':
                feature = Fisherfaces()
                self.threshold = threshold_function(0.61, 0.5)
            elif feature_parameter == 'pca80':
                feature = PCA(80)
            else:
                feature = m[feature_parameter]()

        metric_param = None
        d = {
            "euclid": EuclideanDistance,
            "cosine": CosineDistance,
            "normal": NormalizedCorrelation,
            "chi": ChiSquareDistance,
            "histo": HistogramIntersection,
            "l1b": L1BinRatioDistance,
            "chibrd": ChiSquareBRD
        }
        if metric in d:
            metric_param = d[metric]()
        else:
            metric_param = ChiSquareDistance()

        classifier = NearestNeighbor(dist_metric=metric_param, k=k)
        feature = ChainOperator(TanTriggsPreprocessing(), feature)
        # feature = ChainOperator(TanTriggsPreprocessing(0.1, 10.0, 1.0, 3.0), feature)
        self.model = PredictableModel(feature, classifier)

        # images in one list, id's on another
        id_list, face_list = zip(*input_faces)

        print "Train the model"
        start = time.clock()
        # model.compute(X, y)
        self.model.compute(face_list, id_list)
        stop = time.clock()
        print "Training done in", stop - start, " next...find a face"
Beispiel #4
0
     sys.exit()
 # Define filters for the Dataset:
 yale_subset_0_40 = YaleBaseFilter(0, 40, 0, 40)
 # Now read in the image data. Apply filters, scale to 128 x 128 pixel:
 [X,y] = read_images(sys.argv[1], yale_subset_0_40, sz=(64,64))
 # Set up a handler for logging:
 handler = logging.StreamHandler(sys.stdout)
 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
 handler.setFormatter(formatter)
 # Add handler to facerec modules, so we see what's going on inside:
 logger = logging.getLogger("facerec")
 logger.addHandler(handler)
 logger.setLevel(logging.INFO)
 # The models we want to evaluate:
 model0 = PredictableModel(feature=SpatialHistogram(lbp_operator=ExtendedLBP()), classifier=NearestNeighbor(dist_metric=ChiSquareDistance(), k=1))
 model1 = PredictableModel(feature=SpatialHistogram(lbp_operator=LPQ()), classifier=NearestNeighbor(dist_metric=ChiSquareDistance(), k=1))
 # The sigmas we'll apply for each run:
 sigmas = [0]
 print 'The experiment will be run %s times!' % ITER_MAX
 # Initialize experiments (with empty results):
 experiments = {}
 experiments['lbp_model'] = { 'model': model0, 'results' : {}, 'color' : 'r', 'linestyle' : '--', 'marker' : '*'} 
 experiments['lpq_model'] = { 'model': model1, 'results' : {}, 'color' : 'b', 'linestyle' : '--', 'marker' : 's'}
 # Loop to acquire the results for each experiment:
 for sigma in sigmas:
     print "Setting sigma=%s" % sigma
     for key, value in experiments.iteritems():
         print 'Running experiment for model=%s' % key
         # Define the validators for the model:
         cv0 = SimpleValidation(value['model'])
         for iteration in xrange(ITER_MAX):
Beispiel #5
0
    if len(sys.argv) > 2:
        feature_parameter = sys.argv[2]
        m = {
            "fisher": Fisherfaces,
            "fisher10": Fisherfaces,
            "pca": PCA,
            "pca10": PCA,
            "lda": LDA,
            "spatial": SpatialHistogram,
            "LPQ": SpatialHistogram
        }

        if feature_parameter in m:
            if feature_parameter == 'LPQ':
                feature = SpatialHistogram(LPQ())
            elif feature_parameter == 'fisher80':
                feature = Fisherfaces(80)
            elif feature_parameter == 'pca80':
                feature = PCA(80)
            else:
                feature = m[feature_parameter]()

    # Define a 1-NN classifier with Euclidean Distance:
    # classifier = NearestNeighbor(dist_metric=EuclideanDistance(), k=3) # þokkalegt, [1.7472255 ,  1.80661233,  1.89985602] bara fremsta rétt
    # classifier = NearestNeighbor(dist_metric=CosineDistance(), k=3) # þokkalegt, niðurstöður sem mínus tölur ([-0.72430667, -0.65913855, -0.61865271])
    # classifier = NearestNeighbor(dist_metric=NormalizedCorrelation(), k=3) # ágætt  0.28873109,  0.35998333,  0.39835315 (bara fremsta rétt)
    classifier = NearestNeighbor(dist_metric=ChiSquareDistance(
    ), k=3)  # gott, 32.49907228,  44.53673458,  45.39480197 bara síðasta rangt
    # classifier = NearestNeighbor(dist_metric=HistogramIntersection(), k=3) # sökkar
    # classifier = NearestNeighbor(dist_metric=L1BinRatioDistance(), k=3) # nokkuð gott,  36.77156378,  47.84164013,  52.63872497] - síðasta rangt