class CaffeServer(object): def __init__(self, caffe_root, feature_layers, gpu): self.extractor = CaffeExtractor(caffe_root=caffe_root, feature_layers=feature_layers, gpu=gpu) def getImageFeatures(self, image , image_shape): image = np.fromstring(snappy.uncompress(image), dtype=np.float32) image.resize(image_shape) feature_dic = self.extractor.getImageFeatures(image) feature_dic = {layer:snappy.compress(features) for layer,features in feature_dic.items()} return feature_dic def getImageLabels(self): labels = self.extractor.getImageLabels() return labels
def model_mobileface2(do_mirror): model_dir = './models/mobilefacenet/' model_proto = model_dir + 'model.prototxt' model_path = model_dir + 'model.caffemodel' image_size = (112, 112) extractor = CaffeExtractor(model_proto, model_path, do_mirror=do_mirror, featLayer='fc1') return extractor, image_size
def model_mobileface(do_mirror): model_dir = './models/mobilefacenet/' model_proto = model_dir + 'mobilefacenet-res2-6-10-2-dim128-opencv.prototxt' model_path = model_dir + 'mobilefacenet-res2-6-10-2-dim128.caffemodel' image_size = (112, 112) extractor = CaffeExtractor(model_proto, model_path, do_mirror=do_mirror, featLayer='fc1') return extractor, image_size
def model_arcface(do_mirror): model_dir = './models/arcface/' model_proto = model_dir + 'model.prototxt' model_path = model_dir + 'model-r50-am.caffemodel' image_size = (112, 112) extractor = CaffeExtractor(model_proto, model_path, do_mirror=do_mirror, featLayer='fc1') return extractor, image_size
def model_sphereface(do_mirror): model_dir = './models/sphereface/' model_proto = model_dir + 'sphereface_deploy.prototxt' model_path = model_dir + 'sphereface_model.caffemodel' image_size = (96, 112) extractor = CaffeExtractor(model_proto, model_path, do_mirror=do_mirror, featLayer='fc5') return extractor, image_size
def test_model(model, weight, dist_type='cosine', do_mirror=False, feat_layer='fc5'): extractor = CaffeExtractor(model, weight, do_mirror=do_mirror, featLayer=feat_layer) test_loss(extractor, weight, dist_type)
def model_yours(do_mirror): model_dir = '/path/to/your/model/' model_proto = model_dir + 'deploy.prototxt' model_path = model_dir + 'weights.caffemodel' image_size = (112, 112) extractor = CaffeExtractor(model_proto, model_path, do_mirror=do_mirror, featLayer='fc5') return extractor, image_size
def model_tzk(do_mirror): model_dir = '/home/ysten/tzk/fr/insightface/caffe/AMSoftmax/' model_proto = model_dir + 'deploy.prototxt' model_path = model_dir + 'tune_iter_20000.caffemodel' image_size = (112, 112) extractor = CaffeExtractor(model_proto, model_path, do_mirror=do_mirror, featLayer='fc5') return extractor, image_size
def model_AMSoftmax(do_mirror): model_dir = './models/AMSoftmax/' if do_mirror: model_proto = model_dir + 'face_deploy_mirror_normalize.prototxt' else: model_proto = model_dir + 'deploy.prototxt' model_path = model_dir + 'face_train_test_iter_30000.caffemodel' image_size = (96, 112) extractor = CaffeExtractor(model_proto, model_path, do_mirror=False, featLayer='fc5') return extractor, image_size
def __init__(self, caffe_root, feature_layers, gpu): self.extractor = CaffeExtractor(caffe_root=caffe_root, feature_layers=feature_layers, gpu=gpu)
# load model feat_layer = 'fc5' if config.get('model').feat_layer: featLayer = config.get('model').feat_layer if config.get(model_name).feat_layer != None: feat_layer = config.get(model_name).feat_layer model = config.get(model_name).model weights = config.get(model_name).weights suffix = config.get(model_name).suffix print('Test model:%s feat:%s suffix:%s' % (model_name, feat_layer, suffix)) extractor = CaffeExtractor(model, weights, featLayer=feat_layer, gpu_id=config.get('model').gpu_id) # devkit/templatelists templatelists_dir = config.get('devkit').templatelists_dir # Extract facescrub features facescrub_dir = config.get('facescrub').aligned_dir facescrub_feature_dir = config.get('facescrub').feature_dir extract_facescrub_uncropped(facescrub_dir, templatelists_dir, facescrub_feature_dir, suffix, extractor) # Extract MegaFace features mega_dir = config.get('megaface').aligned_dir mega_feature_dir = config.get('megaface').feature_dir extract_megaface_features(mega_dir, templatelists_dir, mega_feature_dir,
def test_model(model, weight, dist_type='cosine', do_mirror=False): extractor = CaffeExtractor(model, weight, do_mirror=do_mirror) test_loss(extractor, weight, dist_type)