summaryrefslogtreecommitdiff
path: root/megapixels/commands/cv
diff options
context:
space:
mode:
authoradamhrv <adam@ahprojects.com>2018-12-17 01:37:31 +0100
committeradamhrv <adam@ahprojects.com>2018-12-17 01:37:31 +0100
commit88ec48e1c4d93ba9cd3aa186c068ef2aa4c27c56 (patch)
tree506075c0c8f0d4bbf15e97c6db50b6e055c5bd4e /megapixels/commands/cv
parent23e9fef5dce8b0b15dd94713816b9d7d45f12356 (diff)
fixing dataset procesosrs
Diffstat (limited to 'megapixels/commands/cv')
-rw-r--r--megapixels/commands/cv/cluster.py22
-rw-r--r--megapixels/commands/cv/face_pose.py (renamed from megapixels/commands/cv/gen_pose.py)17
-rw-r--r--megapixels/commands/cv/face_roi.py (renamed from megapixels/commands/cv/gen_rois.py)17
-rw-r--r--megapixels/commands/cv/face_vector.py (renamed from megapixels/commands/cv/gen_face_vec.py)18
4 files changed, 37 insertions, 37 deletions
diff --git a/megapixels/commands/cv/cluster.py b/megapixels/commands/cv/cluster.py
index 94334133..419091a0 100644
--- a/megapixels/commands/cv/cluster.py
+++ b/megapixels/commands/cv/cluster.py
@@ -23,20 +23,20 @@ from app.utils.logger_utils import Logger
@click.pass_context
def cli(ctx, opt_data_store, opt_dataset, opt_metadata):
"""Display image info"""
-
- # cluster the embeddings
-print("[INFO] clustering...")
-clt = DBSCAN(metric="euclidean", n_jobs=args["jobs"])
-clt.fit(encodings)
-
-# determine the total number of unique faces found in the dataset
-labelIDs = np.unique(clt.labels_)
-numUniqueFaces = len(np.where(labelIDs > -1)[0])
-print("[INFO] # unique faces: {}".format(numUniqueFaces))
+
+ # cluster the embeddings
+ print("[INFO] clustering...")
+ clt = DBSCAN(metric="euclidean", n_jobs=args["jobs"])
+ clt.fit(encodings)
+
+ # determine the total number of unique faces found in the dataset
+ labelIDs = np.unique(clt.labels_)
+ numUniqueFaces = len(np.where(labelIDs > -1)[0])
+ print("[INFO] # unique faces: {}".format(numUniqueFaces))
# load and display image
im = cv.imread(fp_im)
cv.imshow('', im)
-
+
while True:
k = cv.waitKey(1) & 0xFF
if k == 27 or k == ord('q'): # ESC
diff --git a/megapixels/commands/cv/gen_pose.py b/megapixels/commands/cv/face_pose.py
index aefadb00..e7ffb7ac 100644
--- a/megapixels/commands/cv/gen_pose.py
+++ b/megapixels/commands/cv/face_pose.py
@@ -76,27 +76,26 @@ def cli(ctx, opt_fp_in, opt_fp_out, opt_dir_media, opt_data_store, opt_dataset,
face_landmarks = LandmarksDLIB()
# load filepath data
- fp_filepath = data_store.metadata(types.Metadata.FILEPATH)
- df_filepath = pd.read_csv(fp_filepath)
+ fp_record = data_store.metadata(types.Metadata.FILE_RECORD)
+ df_record = pd.read_csv(fp_record).set_index('index')
# load ROI data
fp_roi = data_store.metadata(types.Metadata.FACE_ROI)
- df_roi = pd.read_csv(fp_roi)
+ df_roi = pd.read_csv(fp_roi).set_index('index')
# slice if you want
if opt_slice:
df_roi = df_roi[opt_slice[0]:opt_slice[1]]
# group by image index (speedup if multiple faces per image)
- df_img_groups = df_roi.groupby('image_index')
+ df_img_groups = df_roi.groupby('record_index')
log.debug('processing {:,} groups'.format(len(df_img_groups)))
# store poses and convert to DataFrame
poses = []
# iterate
- for image_index, df_img_group in tqdm(df_img_groups):
+ for record_index, df_img_group in tqdm(df_img_groups):
# make fp
- ds_file = df_filepath.iloc[image_index]
- fp_im = data_store.face_image(ds_file.subdir, ds_file.fn, ds_file.ext)
- #fp_im = join(opt_dir_media, ds_file.subdir, '{}.{}'.format(ds_file.fn, ds_file.ext))
+ ds_record = df_record.iloc[record_index]
+ fp_im = data_store.face_image(ds_record.subdir, ds_record.fn, ds_record.ext)
im = cv.imread(fp_im)
# get bbox
x = df_img_group.x.values[0]
@@ -130,7 +129,7 @@ def cli(ctx, opt_fp_in, opt_fp_out, opt_dir_media, opt_data_store, opt_dataset,
break
# add image index and append to result CSV data
- pose_degrees['image_index'] = image_index
+ pose_degrees['record_index'] = record_index
poses.append(pose_degrees)
diff --git a/megapixels/commands/cv/gen_rois.py b/megapixels/commands/cv/face_roi.py
index 20dd598a..d7248aee 100644
--- a/megapixels/commands/cv/gen_rois.py
+++ b/megapixels/commands/cv/face_roi.py
@@ -103,20 +103,19 @@ def cli(ctx, opt_fp_in, opt_dir_media, opt_fp_out, opt_data_store, opt_dataset,
# get list of files to process
- fp_in = data_store.metadata(types.Metadata.FILEPATH) if opt_fp_in is None else opt_fp_in
- df_files = pd.read_csv(fp_in).set_index('index')
+ fp_in = data_store.metadata(types.Metadata.FILE_RECORD) if opt_fp_in is None else opt_fp_in
+ df_records = pd.read_csv(fp_in).set_index('index')
if opt_slice:
- df_files = df_files[opt_slice[0]:opt_slice[1]]
- log.debug('processing {:,} files'.format(len(df_files)))
+ df_records = df_records[opt_slice[0]:opt_slice[1]]
+ log.debug('processing {:,} files'.format(len(df_records)))
# filter out grayscale
color_filter = color_filters[opt_color_filter]
data = []
- for df_file in tqdm(df_files.itertuples(), total=len(df_files)):
- fp_im = data_store.face_image(str(df_file.subdir), str(df_file.fn), str(df_file.ext))
- #fp_im = join(opt_dir_media, str(df_file.subdir), f'{df_file.fn}.{df_file.ext}')
+ for df_record in tqdm(df_records.itertuples(), total=len(df_records)):
+ fp_im = data_store.face_image(str(df_record.subdir), str(df_record.fn), str(df_record.ext))
im = cv.imread(fp_im)
# filter out color or grayscale iamges
@@ -139,7 +138,7 @@ def cli(ctx, opt_fp_in, opt_dir_media, opt_fp_out, opt_data_store, opt_dataset,
for bbox in bboxes:
roi = {
- 'image_index': int(df_file.Index),
+ 'record_index': int(df_record.Index),
'x': bbox.x,
'y': bbox.y,
'w': bbox.w,
@@ -169,4 +168,4 @@ def cli(ctx, opt_fp_in, opt_dir_media, opt_fp_out, opt_data_store, opt_dataset,
file_utils.mkdirs(fp_out)
df = pd.DataFrame.from_dict(data)
df.index.name = 'index'
- df.to_csv(opt_fp_out) \ No newline at end of file
+ df.to_csv(fp_out) \ No newline at end of file
diff --git a/megapixels/commands/cv/gen_face_vec.py b/megapixels/commands/cv/face_vector.py
index 83e1460d..203f73eb 100644
--- a/megapixels/commands/cv/gen_face_vec.py
+++ b/megapixels/commands/cv/face_vector.py
@@ -76,15 +76,17 @@ def cli(ctx, opt_fp_out, opt_dir_media, opt_data_store, opt_dataset, opt_size,
facerec = face_recognition.RecognitionDLIB()
# load data
- df_file = pd.read_csv(data_store.metadata(types.Metadata.FILEPATH)).set_index('index')
- df_roi = pd.read_csv(data_store.metadata(types.Metadata.FACE_ROI)).set_index('index')
+ fp_record = data_store.metadata(types.Metadata.FILE_RECORD)
+ df_record = pd.read_csv(fp_record).set_index('index')
+ fp_roi = data_store.metadata(types.Metadata.FACE_ROI)
+ df_roi = pd.read_csv(fp_roi).set_index('index')
if opt_slice:
df_roi = df_roi[opt_slice[0]:opt_slice[1]]
# -------------------------------------------------
# process here
- df_img_groups = df_roi.groupby('image_index')
+ df_img_groups = df_roi.groupby('record_index')
log.debug('processing {:,} groups'.format(len(df_img_groups)))
vecs = []
@@ -92,9 +94,9 @@ def cli(ctx, opt_fp_out, opt_dir_media, opt_data_store, opt_dataset, opt_size,
for image_index, df_img_group in tqdm(df_img_groups):
# make fp
roi_index = df_img_group.index.values[0]
- log.debug(f'roi_index: {roi_index}, image_index: {image_index}')
- ds_file = df_file.loc[roi_index] # locate image meta
- #ds_file = df_file.loc['index', image_index] # locate image meta
+ # log.debug(f'roi_index: {roi_index}, image_index: {image_index}')
+ ds_file = df_record.loc[roi_index] # locate image meta
+ #ds_file = df_record.loc['index', image_index] # locate image meta
fp_im = data_store.face_image(str(ds_file.subdir), str(ds_file.fn), str(ds_file.ext))
im = cv.imread(fp_im)
@@ -119,5 +121,5 @@ def cli(ctx, opt_fp_out, opt_dir_media, opt_data_store, opt_dataset, opt_size,
# save date
df = pd.DataFrame.from_dict(vecs)
df.index.name = 'index'
- #file_utils.mkdirs(fp_out)
- #df.to_csv(fp_out) \ No newline at end of file
+ file_utils.mkdirs(fp_out)
+ df.to_csv(fp_out) \ No newline at end of file