Spaces:
Sleeping
Sleeping
Download src/util/image.py from NarendraMall/Image-Similarity: direct link, hf CLI and curl.
- Browser
- Download file 476 Bytes
-
https://huggingface.co/spaces/NarendraMall/Image-Similarity/resolve/main/src/util/image.py
- Command line
-
hf download hf://spaces/NarendraMall/Image-Similarity/src/util/image.py
-
curl -L -o image.py https://huggingface.co/spaces/NarendraMall/Image-Similarity/resolve/main/src/util/image.py
476 Bytes
| from PIL import Image | |
| import numpy as np | |
| import requests | |
| def load_image_url(url, required_size = (224,224), image_type = 'array'): | |
| print(f'downloading.. {url}, type: {image_type}') | |
| img = Image.open(requests.get(url, stream=True).raw) | |
| img = Image.fromarray(np.array(img)) | |
| if required_size is not None: | |
| img = img.resize(required_size) | |
| if image_type == 'array': | |
| img = (np.expand_dims(np.array(img), 0)/255).astype(np.float32) | |
| return img | |