Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enables predictor to load a list of files as a list of strings #128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions nsfw_detector/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def load_images(image_paths, image_size, verbose=True):
'''
Function for loading images into numpy arrays for passing to model.predict
inputs:
image_paths: list of image paths to load
image_paths: image paths to load as one file or one directory as a string, or a list of files as strings
image_size: size into which images should be resized
verbose: show all of the image path and sizes loaded

Expand All @@ -29,11 +29,12 @@ def load_images(image_paths, image_size, verbose=True):
loaded_images = []
loaded_image_paths = []

if isdir(image_paths):
parent = abspath(image_paths)
image_paths = [join(parent, f) for f in listdir(image_paths) if isfile(join(parent, f))]
elif isfile(image_paths):
image_paths = [image_paths]
if type(image_paths) is str:
if isdir(image_paths):
parent = abspath(image_paths)
image_paths = [join(parent, f) for f in listdir(image_paths) if isfile(join(parent, f))]
elif isfile(image_paths):
image_paths = [image_paths]

for img_path in image_paths:
try:
Expand Down