def Vanilla_Cmc(q_features, q_db_txt, g_features, g_db_txt, rank_size, dist_mat=None, dist_type='eucl'): q_db = utils.parse_db(q_db_txt, ['label', 'cam']) g_db = utils.parse_db(g_db_txt, ['label', 'cam']) q_data = {'feature': q_features, 'id': q_db['label'], 'cam': q_db['cam']} g_data = {'feature': g_features, 'id': g_db['label'], 'cam': g_db['cam']} CMC, mAP = Vanilla_Cmc_dict(q_data, g_data, rank_size, dist_mat, dist_type) return CMC, mAP
def build_img_db(db_txt, model_path, cam_seq_dict=None): """Build image db""" if args.target == 'Market': db = utils.parse_db( db_txt, ['img', 'cam', 'frame_id', 'track_id', 'label', 'seq_id']) db['hash_cam'] = hash_cam_seq(db['cam'], db['seq_id'], cam_seq_dict) else: db = utils.parse_db(db_txt, ['img', 'cam', 'frame_id', 'track_id', 'label']) db['hash_cam'] = db['cam'] db['track_uuid'] = get_track_uuid(db['label'], db['track_id']) db['start_frame'] = db['frame_id'] db['end_frame'] = db['frame_id'] db['feature'] = inference.inference_db(db_txt, model_path) db['id'] = db['label'] return db
def add_contactor(**kwargs): db = parse_db(**kwargs) name = kwargs['name'] phone = kwargs['phone'] verify_flag = verify(phone) if not verify_flag: return 0 with open(db, 'r') as fr: data = json.load(fr) data.append({name: str(phone)}) with open(db, 'w+') as fw: data = json.dumps(data, ensure_ascii=False, indent=4) fw.write(data) return 1
def search_contactor(**kwargs): search_result = [] db = parse_db(**kwargs) search_name = kwargs.get('search_name', '') if not search_name: return "Empty search key" with open(db, 'r') as fr: data = json.load(fr) keys = [item.keys()[0] for item in data] if search_name not in keys: return 'Not found contactor' for item in data: if item.keys()[0] == search_name: result = search_name + ': ' + item[search_name] search_result.append(result) return ['search down', search_result]
def delete_contactor(**kwargs): db = parse_db(**kwargs) delete_name = kwargs.get('delete_name', '') if not delete_name: return "Empty delete key" with open(db, 'r') as fr: data = json.load(fr) keys = [item.keys()[0] for item in data] if delete_name not in keys: return 'Not found contactor to delete' for item in data: if item.keys()[0] == delete_name: item.clear() while {} in data: data.remove({}) with open(db, 'w+') as fw: data = json.dumps(data, ensure_ascii=False, indent=4) fw.write(data) return 'delete success'
def update_contactor(**kwargs): db = parse_db(**kwargs) update_name = kwargs.get('update_name', '') update_phone = kwargs.get('update_phone', '') if not update_name: return 'Empty contactor' with open(db, 'r') as fr: data = json.load(fr) keys = [item.keys()[0] for item in data] if update_name not in keys: return 'Not found contactor to update' verify_flag = verify(update_phone) if not verify_flag: return 'Wrong phone format' for item in data: if item.keys()[0] == update_name: item[update_name] = str(update_phone) with open(db, 'w+') as fw: data = json.dumps(data, ensure_ascii=False, indent=4) fw.write(data) return 'update success'
def read_images(db_txt): """Read image data, extract all image info""" db = utils.parse_db(db_txt, ['img', 'label', 'cam', 'frame_id', 'track_id']) return db
def Self_Cmc(features, db_txt, rank_size, dist_mat=None, dist_type='eucl'): db = utils.parse_db(db_txt, ['label', 'cam']) data = {'feature': features, 'id': db['label'], 'cam': db['cam']} CMC, mAP = Self_Cmc_dict(data, rank_size, dist_mat, dist_type) return CMC, mAP
def list_contactors(**kwargs): db = parse_db(**kwargs) with open(db, 'r') as fr: data = json.load(fr) return data