def main_multicard(spath, cutno, total_num): #model = builders.build_arch() model = builders.MetricModel() print(model) load_checkpoint(MODEL_WEIGHTS, model) if torch.cuda.is_available(): model.cuda() model.eval() feadic = {} for index, imgfile in enumerate(walkfile(spath)): if index % total_num != cutno - 1: continue ext = os.path.splitext(imgfile)[-1] name = os.path.basename(imgfile) if ext.lower() in ['.jpg', '.jpeg', '.bmp', '.png', '.pgm']: embedding = extract(imgfile, model) feadic[name] = embedding #print(feadic) if index % 5000 == cutno - 1: print(index, embedding.shape) with open( COMBINE_DIR + spath.split("/")[-1] + "fea.pickle" + '_%d' % cutno, "wb") as fout: pickle.dump(feadic, fout, protocol=2)
def main(spath): model = setup_model() feadic = {} for index, imgfile in enumerate(walkfile(spath)): ext = os.path.splitext(imgfile)[-1] name = os.path.basename(imgfile) print(index, name) if ext.lower() in ['.jpg', '.jpeg', '.bmp', '.png', '.pgm']: im = cv2.imread(imgfile) im = im.astype(np.float32, copy=False) data = delg_extract(im, model) feadic[name] = data with open(spath.split("/")[-2] + "localfea.pickle", "wb") as fout: pickle.dump(feadic, fout, protocol=2)
def main_multicard(spath, cutno, total_num): model = setup_model() feadic = {} for index, imgfile in enumerate(walkfile(spath)): if index % total_num != cutno - 1: continue ext = os.path.splitext(imgfile)[-1] name = os.path.basename(imgfile) print(index, name) if ext.lower() in ['.jpg', '.jpeg', '.bmp', '.png', '.pgm']: im = cv2.imread(imgfile) im = im.astype(np.float32, copy=False) data = delg_extract(im, model) print(data['locations'].shape, data['descriptors'].shape) feadic[name] = data with open(COMBINE_DIR + "localfea.pickle" + '_%d' % cutno, "wb") as fout: pickle.dump(feadic, fout, protocol=2)
def main(spath): model = builders.MetricModel() print(model) load_checkpoint(MODEL_WEIGHTS, model) if torch.cuda.is_available(): model.cuda() model.eval() result = {} for index, imgfile in enumerate(walkfile(spath)): ext = os.path.splitext(imgfile)[-1] name = os.path.basename(imgfile) if ext.lower() in ['.jpg', '.jpeg', '.bmp', '.png', '.pgm']: label = extract(imgfile, model) result[name] = label if index % 5000 == 0: print(index, name, label) with open(spath.split("/")[-1] + "label.pickle", "wb") as fout: pickle.dump(result, fout, protocol=2)