Skip to content

Commit

Permalink
Merge pull request ml4a#28 from fchtngr/discover-image-candidates
Browse files Browse the repository at this point in the history
fix discovery of candidate images in sub-folders
  • Loading branch information
genekogan authored Mar 14, 2018
2 parents 661db7b + c0c3ed2 commit e4cc9b6
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion scripts/tSNE-images.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,28 @@ def get_image(path, input_shape):
x = preprocess_input(x)
return x

def find_candidate_images(images_path):
"""
Finds all candidate images in the given folder and its sub-folders.
Returns:
images: a list of absolute paths to the discovered images.
"""
images = []
for root, dirs, files in os.walk(images_path):
for name in files:
file_path = os.path.abspath(os.path.join(root, name))
if ((os.path.splitext(name)[1]).lower() in ['.jpg','.png','.jpeg']):
images.append(file_path)
return images

def analyze_images(images_path):
# make feature_extractor
model = keras.applications.VGG16(weights='imagenet', include_top=True)
feat_extractor = Model(inputs=model.input, outputs=model.get_layer("fc2").output)
input_shape = model.input_shape[1:3]
# get images
candidate_images = [f for f in os.listdir(images_path) if os.path.splitext(f)[1].lower() in ['.jpg','.png','.jpeg']]
candidate_images = find_candidate_images(images_path)
# analyze images and grab activations
activations = []
images = []
Expand Down

0 comments on commit e4cc9b6

Please sign in to comment.