diff options
| author | adamhrv <adam@ahprojects.com> | 2019-10-08 16:02:47 +0200 |
|---|---|---|
| committer | adamhrv <adam@ahprojects.com> | 2019-10-08 16:02:47 +0200 |
| commit | 27340ac4cd43f8eec7414495b541a65566ae2656 (patch) | |
| tree | cd43fcf1af026c75e6045d71d7d783ec460ba3ee /megapixels/app/models | |
| parent | a4ea2852f4b46566a61f988342aa04e4059ccef9 (diff) | |
update site, white
Diffstat (limited to 'megapixels/app/models')
| -rw-r--r-- | megapixels/app/models/bbox.py | 14 | ||||
| -rw-r--r-- | megapixels/app/models/dataset.py | 14 |
2 files changed, 25 insertions, 3 deletions
diff --git a/megapixels/app/models/bbox.py b/megapixels/app/models/bbox.py index 8ecc8971..c840ea1b 100644 --- a/megapixels/app/models/bbox.py +++ b/megapixels/app/models/bbox.py @@ -207,11 +207,21 @@ class BBox: # ----------------------------------------------------------------- # Convert to - def to_square(self, bounds): + def to_square(self): '''Forces bbox to square dimensions - :param bounds: (int, int) w, h of the image :returns (BBox) in square ratio ''' + if self._width > self._height: + delta = (self._width - self._height) / 2 + self._y1 -= delta + self._y2 += delta + elif self._height > self._width: + delta = (self._height - self._width) / 2 + self._x1 -= delta + self._x2 += delta + return BBox(self._x1, self._y1, self._x2, self._y2) + + def to_dim(self, dim): """scale is (w, h) is tuple of dimensions""" diff --git a/megapixels/app/models/dataset.py b/megapixels/app/models/dataset.py index a7227a70..c908da1b 100644 --- a/megapixels/app/models/dataset.py +++ b/megapixels/app/models/dataset.py @@ -152,6 +152,8 @@ class Dataset: image_records = [] # list of image matches w/identity if available # find most similar feature vectors indexes #match_idxs = self.similar(query_vec, n_results, threshold) + + # TODO: add cosine similarity sim_scores = np.linalg.norm(np.array([query_vec]) - np.array(self._face_vectors), axis=1) match_idxs = np.argpartition(sim_scores, range(n_results))[:n_results] @@ -180,7 +182,17 @@ class Dataset: s3_url = self.data_store_s3.face(ds_record.uuid) bbox_norm = BBox.from_xywh_norm_dim(ds_roi.x, ds_roi.y, ds_roi.w, ds_roi.h, dim) self.log.debug(f'bbox_norm: {bbox_norm}') - score = sim_scores[match_idx] + self.log.debug(f'match_idx: {match_idx}, record_idx: {record_idx}, roi_index: {roi_index}, len sim_scores: {len(sim_scores)}') + try: + score = sim_scores[match_idx] + except Exception as e: + self.log.error(e) + try: + score = sim_scores[record_idx] + except Exception as e: + self.log.error(e) + + if types.Metadata.IDENTITY in self._metadata.keys(): ds_id = df_identity.loc[df_identity['identity_key'] == ds_record.identity_key].iloc[0] |
