Local image input?
#1
by
sukays
- opened
Hi there! Thanks for the hot update! I am wondering if I can pass local image path through PIL to load them as I would like to do a batch evaluation locally. Thank you!
I've tried it, and loading images locally works fine. You can refer to my code.
def load_image_from_url_or_path(path_or_url):
if os.path.isfile(path_or_url):
# local path
try:
image = Image.open(path_or_url).convert('RGB')
return image
except Exception as e:
print(f"Unable to load image from path: {e}")
return None
else:
# url path
try:
response = requests.get(path_or_url)
response.raise_for_status()
image = Image.open(BytesIO(response.content)).convert('RGB')
return image
except Exception as e:
print(f"Unable to load image from path: {e}")
return None