1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
import click
from app.settings import types
from app.utils import click_utils
from app.settings import app_cfg as cfg
@click.command()
@click.option('-i', '--input', 'opt_fp_in', required=True,
help='Input directory')
@click.option('-r', '--records', 'opt_fp_records', required=True,
help='Input directory')
@click.option('-o', '--output', 'opt_fp_out', required=True,
help='Output JSON')
@click.option('-f', '--force', 'opt_force', is_flag=True,
help='Force overwrite file')
@click.pass_context
def cli(ctx, opt_fp_in, opt_fp_records, opt_fp_out,opt_force):
"""Merges ID with face vectors"""
import sys
import os
from os.path import join
from pathlib import Path
from tqdm import tqdm
import pandas as pd
from app.utils import logger_utils, file_utils
# -------------------------------------------------
# init here
log = logger_utils.Logger.getLogger()
df_vecs = pd.read_csv(opt_fp_in)
df_records = pd.read_csv(opt_fp_records)
nrows = len(df_vecs)
# face vecs
id_vecs = {}
for roi_idx, row in tqdm(df_vecs.iterrows(), total=nrows):
record_id = int(row['id'])
vec = row['vec'].split(',')
id_vecs[record_id] = vec
# save as JSON
file_utils.write_json(id_vecs, opt_fp_out, verbose=True)
|