Skip to content

Commit

Permalink
Allow to flip or mirror images before computing image features
Browse files Browse the repository at this point in the history
  • Loading branch information
woctezuma committed Jan 21, 2021
1 parent 428b13a commit 4a2a7a0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions build_feature_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy as np
from generic_utils import load_image
from PIL import Image as pil_image

from app_id_utils import freeze_app_ids, list_app_ids, app_id_to_image_filename
from data_utils import get_label_database_filename
Expand All @@ -14,7 +15,9 @@
)


def build_feature_index(is_horizontal_banner=False, resolution=None):
def build_feature_index(
is_horizontal_banner=False, resolution=None, apply_flip=False, apply_mirror=False
):
pooling = "avg"
feature_filename = get_label_database_filename(pooling)

Expand Down Expand Up @@ -44,6 +47,10 @@ def build_feature_index(is_horizontal_banner=False, resolution=None):

image_filename = app_id_to_image_filename(app_id, is_horizontal_banner)
image = load_image(image_filename, target_size=target_model_size)
if apply_flip:
image = pil_image.flip(image)
if apply_mirror:
image = pil_image.mirror(image)
features = convert_image_to_features(image, model, preprocess=preprocess)

Y_hat[counter, :] = features
Expand All @@ -58,4 +65,9 @@ def build_feature_index(is_horizontal_banner=False, resolution=None):


if __name__ == "__main__":
build_feature_index(is_horizontal_banner=False, resolution=None)
build_feature_index(
is_horizontal_banner=False,
resolution=None,
apply_flip=False,
apply_mirror=False,
)

0 comments on commit 4a2a7a0

Please sign in to comment.