Spaces:
Runtime error
Runtime error
File size: 816 Bytes
3b6f2f5 9c7338a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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
def load_image_path(path, required_size = (224,224), image_type = 'array'):
img = Image.open(path)
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
|