o
    oi                     @   s   U d dl Z d dlZd dlmZmZmZmZmZ d dlZd dl	m
Z
mZ d dlmZ d dlmZ d dlmZ dgZg dZee ed	< d
ededdfddZdeddddfdeeeef  dee dedee dee dee dedee
ee
 f fddZdS )    N)AnyListOptionalTupleUnion)Tensorstack)PILImage)requests)
load_imageget_sample_images)z<https://raw.githubusercontent.com/kornia/data/main/panda.jpgz<https://raw.githubusercontent.com/kornia/data/main/simba.pngz=https://raw.githubusercontent.com/kornia/data/main/girona.pngzChttps://raw.githubusercontent.com/kornia/data/main/baby_giraffe.pngzKhttps://raw.githubusercontent.com/kornia/data/main/persistencia_memoria.jpgz?https://raw.githubusercontent.com/kornia/data/main/delorean.png
IMAGE_URLSurlsave_toreturnc                 C   s&   t tj| dddj}|| dS )zDownload an image from a given URL and save it to a specified file path.

    Args:
        url: The URL of the image to download.
        save_to: The file path where the downloaded image will be saved.

    T   )streamtimeoutN)Imageopenr
   getrawsave)r   r   im r   G/home/ubuntu/.local/lib/python3.10/site-packages/kornia/utils/sample.pydownload_image*   s   r   Tresizepathsdownload	cache_diras_listdivisible_factorkwargsc                 K   s  |du rd}t j|dd g }|D ]m}|drTt j|}	t j||	}
t j|
s?|r?td| d|
 d t	||
 nt j|
sS|sSt
d	| d
|
 d n|}
t|
}| duritjj|| fi |}|durytjjj||fi |}|| q|s| durt|S |S )ah  Load multiple images from the given URLs.

    Optionally download them, resize them if specified, and return them as a batch of tensors or a list of tensors.

    Args:
        paths: A list of path or URL from which to load or download images.
              Defaults to a pre-defined constant `IMAGE_URLS` if not provided.
        resize: Optional target size for resizing all images as a tuple (height, width).
            If not provided, the images will not be resized, and their original sizes will be retained.
        download: Whether to download the images if they are not already cached. Defaults to True.
        cache_dir: The directory where the downloaded images will be cached.
            Defaults to ".kornia_hub/images".
        as_list: if to keep the output as a list. If None and `resize` is None, the output will be a list.
            If None and `resize` is not None, the output will be a single tensor.
        divisible_factor:
            If not None, the images will be resized to the nearest multiple of `divisible_factor`.
        **kwargs: Additional keyword arguments to pass to `kornia.geometry.resize`.

    Returns:
        torch.Tensor | list[torch.Tensor]:
            If `resize` is provided, returns a single stacked tensor with shape (B, C, H, W).
            Otherwise, returns a list of tensors, each with its original shape (C, H, W).

    Nz.kornia_hub/imagesT)exist_okhttpzDownloading `z` to `z`.zImage `z` not found at `z6`. You may want to set `download=True` to download it.)osmakedirs
startswithpathbasenamejoinexistslogginginfor   errorr   korniageometryr   	transformresize_to_be_divisibleappendr   )r   r   r   r    r!   r"   r#   tensorsr)   namefname
img_tensorr   r   r   r   6   s4   !
)r-   r&   typingr   r   r   r   r   r0   kornia.corer   r   kornia.core.externalr	   r   r
   	kornia.ior   __all__r   str__annotations__r   intboolr   r   r   r   r   <module>   sF   

