summaryrefslogtreecommitdiff
path: root/megapixels/commands
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-12-16 01:14:40 +0100
committerJules Laplace <julescarbon@gmail.com>2018-12-16 01:14:40 +0100
commitf9616b08ce0fa8ab5d60b544b5c0ad1212f201b8 (patch)
treedf2036f710122c9f4979785c643b76622b7c5989 /megapixels/commands
parent63335120a5800142ebe827bd10a1a0106c24b8d8 (diff)
parent10f467b64e3be528ac246d5cf664d675aca3e7f3 (diff)
Merge branch 'master' of github.com:adamhrv/megapixels_dev
Diffstat (limited to 'megapixels/commands')
-rw-r--r--megapixels/commands/cv/cluster.py47
-rw-r--r--megapixels/commands/datasets/lookup.py62
2 files changed, 89 insertions, 20 deletions
diff --git a/megapixels/commands/cv/cluster.py b/megapixels/commands/cv/cluster.py
new file mode 100644
index 00000000..94334133
--- /dev/null
+++ b/megapixels/commands/cv/cluster.py
@@ -0,0 +1,47 @@
+import click
+
+from app.settings import types
+from app.utils import click_utils
+from app.settings import app_cfg as cfg
+from app.utils.logger_utils import Logger
+
+@click.command()
+@click.option('--data_store', 'opt_data_store',
+ type=cfg.DataStoreVar,
+ default=click_utils.get_default(types.DataStore.NAS),
+ show_default=True,
+ help=click_utils.show_help(types.Dataset))
+@click.option('--dataset', 'opt_dataset',
+ type=cfg.DatasetVar,
+ required=True,
+ show_default=True,
+ help=click_utils.show_help(types.Dataset))
+@click.option('--metadata', 'opt_metadata', required=True,
+ type=cfg.MetadataVar,
+ show_default=True,
+ help=click_utils.show_help(types.Metadata))
+@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))
+ # 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
+ cv.destroyAllWindows()
+ sys.exit()
+ elif k != 255:
+ # any key to continue
+ break \ No newline at end of file
diff --git a/megapixels/commands/datasets/lookup.py b/megapixels/commands/datasets/lookup.py
index 11f54957..e84bdf3e 100644
--- a/megapixels/commands/datasets/lookup.py
+++ b/megapixels/commands/datasets/lookup.py
@@ -1,44 +1,66 @@
import click
from app.settings import types
+from app.models.dataset import Dataset
from app.utils import click_utils
from app.settings import app_cfg as cfg
from app.utils.logger_utils import Logger
-log = Logger.getLogger()
-
-lookup_types = ['image', 'identity']
-
@click.command()
-@click.option('-i', '--input', 'opt_fp_in', required=True,
- help='Input CSV file')
-@click.option('-t', '--type', 'opt_type', default='image',
- type=click.Choice(lookup_types),
- help='Type of lookup')
-@click.option('-d', '--dataset', 'opt_dataset', required=True,
+@click.option('--index', 'opt_index', type=int,
+ help='Vector index to lookup')
+@click.option('--data_store', 'opt_data_store',
+ type=cfg.DataStoreVar,
+ default=click_utils.get_default(types.DataStore.NAS),
+ show_default=True,
+ help=click_utils.show_help(types.Dataset))
+@click.option('--dataset', 'opt_dataset',
type=cfg.DatasetVar,
- default=click_utils.get_default(types.Dataset.LFW),
+ required=True,
show_default=True,
help=click_utils.show_help(types.Dataset))
-@click.option('--index', 'opt_index', required=True,
- help='Index to lookup')
+@click.option('--metadata', 'opt_metadata_type', required=True,
+ type=cfg.MetadataVar,
+ show_default=True,
+ help=click_utils.show_help(types.Metadata))
@click.pass_context
-def cli(ctx, opt_fp_in, opt_fp_out, opt_index):
+def cli(ctx, opt_index, opt_data_store, opt_dataset, opt_metadata_type):
"""Display image info"""
+ import sys
from glob import glob
from os.path import join
from pathlib import Path
import time
import pandas as pd
+ import cv2 as cv
from tqdm import tqdm
- from app.utils import file_utils, im_utils
-
- # lookup and index and display all information
- df = pd.read_csv(opt_fp_in).set_index('index')
+ from app.utils import file_utils, im_utils, path_utils
+ log = Logger.getLogger()
-
- \ No newline at end of file
+ log.info(f'creating dataset: {opt_dataset}')
+ dataset = Dataset(opt_dataset)
+ # loads all CSV files, may take a while
+ log.info(f'loading dataset...')
+ dataset.load(opt_data_store)
+ # find image records
+ image_record = dataset.roi_idx_to_record(opt_index)
+ # debug
+ image_record.summarize()
+ # load image
+ fp_im = image_record.filepath
+ im = cv.imread(fp_im)
+ # display
+ cv.imshow('', im)
+ # cv gui
+ while True:
+ k = cv.waitKey(1) & 0xFF
+ if k == 27 or k == ord('q'): # ESC
+ cv.destroyAllWindows()
+ sys.exit()
+ elif k != 255:
+ # any key to continue
+ break \ No newline at end of file