File size: 1,028 Bytes
232568e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import numpy as np
from PIL import Image
import requests
import functools
from tqdm.notebook import tqdm
import shutil

def image_to_array(image: Image) -> np.ndarray:
    """Convert Image to array"""
    return np.asarray(image).astype('uint8')


def load_image(img_path: str) -> Image:
    """Load image to array"""
    return Image.open(img_path)


def download_data(url, save_path, file_size=None):
    """Downloads data from `url` to `save_path`"""
    r = requests.get(url, stream=True, allow_redirects=True)
    if r.status_code != 200:
        r.raise_for_status()
        raise RuntimeError(f'Request to {url} returned status code {r.status_code}')

    if file_size is None:
        file_size = int(r.headers.get('content-length', 0))

    r.raw.read = functools.partial(r.raw.read, decode_content=True)  # Decompress if needed
    with tqdm.wrapattr(r.raw, 'read', total=file_size, desc='') as r_raw:
        with open(save_path, 'wb') as f:
            shutil.copyfileobj(r_raw, f)

def plot_image_triple():
    pass