I am trying to use Images stored inside the directory by using this code,
import random
path = "/content/drive/MyDrive/Colab Notebooks/Low Images/*.png"
low_light_images = glob(path)
for image_path in random.choice(low_light_images):
original_image, output_image = inferer.infer(image_path)
plot_result(original_image, output_image)
But getting this error,
---------------------------------------------------------------------------
IsADirectoryError Traceback (most recent call last)
<ipython-input-62-668719a88426> in <module>()
4 low_light_images = glob(path)
5 for image_path in random.choice(low_light_images):
----> 6 original_image, output_image = inferer.infer(image_path)
7 plot_result(original_image, output_image)
1 frames
/usr/local/lib/python3.7/dist-packages/PIL/Image.py in open(fp, mode)
2841
2842 if filename:
-> 2843 fp = builtins.open(filename, "rb")
2844 exclusive_fp = True
2845
IsADirectoryError: [Errno 21] Is a directory: '/'
How can I resolve this? Full Code Link: here
The line
is grabbing a random filepath such as
And when the for loop starts
image_pathwill end up containing the first character which is a/, and you can see the problem.To randomly loop over all the data use
random.shuffle. (there is alsorandom.choiceswith an s at the end andrandom.samplethat will grab a random subset of all your images).It's easiest to debug stuff if you can simplify the problem to a short MVCE. When using random functions, I will replace the random function with an example of something that it outputs that creates the error condition, like I showed above. Another thing I do is sometimes I will need a sanity check that my variables contain the data I think they contain, and so I will print them out (or you can use a debugger). Doing that we would see that
image_pathcontains a/instead of the expected file path.