コード例 #1
0
    def __init__(self, upsample_times=1, num_jitters=0, model='hog'):
        g.logger.debug('Initializing face recognition with model:{} upsample:{}, jitters:{}'
                       .format(model, upsample_times, num_jitters))

        self.upsample_times = upsample_times
        self.num_jitters = num_jitters
        self.model = model
        self.knn = None

        encoding_file_name = g.config['known_images_path']+'/faces.dat'
        try:
            if (os.path.isfile(g.config['known_images_path']+'/faces.pickle')):
                # old version, we no longer want it. begone
                g.logger.debug ('removing old faces.pickle, we have moved to clustering')
                os.remove (g.config['known_images_path']+'/faces.pickle')
        except Exception as e:
            g.logger.error('Error deleting old pickle file: {}'.format(e))
                

        # to increase performance, read encodings from  file
        if (os.path.isfile(encoding_file_name)):
            g.logger.debug ('pre-trained faces found, using that. If you want to add new images, remove: {}'.format(encoding_file_name))
          
            #self.known_face_encodings = data["encodings"]
            #self.known_face_names = data["names"]
        else:
            # no encodings, we have to read and train
            g.logger.debug ('trained file not found, reading from images and doing training...')
            g.logger.debug ('If you are using a GPU and run out of memory, do the training using zm_train_faces.py. In this case, other models like yolo may already take up a lot of GPU memory')
            
            train.train()
        with open(encoding_file_name, 'rb') as f:
            self.knn  = pickle.load(f)
コード例 #2
0
#!/usr/bin/python3
import argparse
import ssl
import zmes_hook_helpers.log as log
import zmes_hook_helpers.common_params as g
import zmes_hook_helpers.utils as utils
import zmes_hook_helpers.face_train as train

if __name__ == "__main__":
    g.ctx = ssl.create_default_context()
    ap = argparse.ArgumentParser()
    ap.add_argument('-c',
                    '--config',
                    default='/etc/zm/objectconfig.ini',
                    help='config file with path')

    args, u = ap.parse_known_args()
    args = vars(args)

    log.init(process_name='zm_train_faces', dump_console=True)
    utils.process_config(args, g.ctx)
    train.train()