Skip to content
New issue

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

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

Already on GitHub? # to your account

Crash while classifying a list of images: isdir("list") raises exception #81

Open
Davidelanz opened this issue Jan 11, 2021 · 0 comments · May be fixed by #128
Open

Crash while classifying a list of images: isdir("list") raises exception #81

Davidelanz opened this issue Jan 11, 2021 · 0 comments · May be fixed by #128
Labels
bug Something isn't working prediction

Comments

@Davidelanz
Copy link

I am running Python 3.6.9 64-bit on a Ubuntu 18.04.5 docker container.

I spotted a bug for the "predict multiple images at once" feature:

# Predict multiple images at once
predict.classify(model, ['/Users/bedapudi/Desktop/2.jpg', '/Users/bedapudi/Desktop/6.jpg'])

The exception raised is:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/#########/nsfw_model/test_script.py in 
      25    '/Users/bedapudi/Desktop/6.jpg'])
      26 ]
----> 27 predict.classify(model, imglist)

//#########/nsfw_model/nsfw_detector/predict.py in classify(model, input_paths, image_dim)
     67 def classify(model, input_paths, image_dim=IMAGE_DIM):
     68     """ Classify given a model, input paths (could be single string), and image dimensionality...."""
---> 69     images, image_paths = load_images(input_paths, (image_dim, image_dim))
     70     probs = classify_nd(model, images)
     71     return dict(zip(image_paths, probs))

//#########/nsfw_model/nsfw_detector/predict.py in load_images(image_paths, image_size, verbose)
     33     #else:
     34     if True:
---> 35         if isdir(image_paths):
     36             parent = abspath(image_paths)
     37             image_paths = [join(parent, f) for f in listdir(

/usr/lib/python3.6/genericpath.py in isdir(s)
     40     """Return true if the pathname refers to an existing directory."""
     41     try:
---> 42         st = os.stat(s)
     43     except OSError:
     44         return False

TypeError: stat: path should be string, bytes, os.PathLike or integer, not list

I guess the problem was in

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]

I fixed it in the following way:

def load_images(image_paths, image_size, verbose=True):

    loaded_images = []
    loaded_image_paths = []

    if type(image_paths) == list:
        pass
    else:
        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]

Did I got something wrong or it is a legit fix?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working prediction
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants