load_url#

deepinv.utils.load_url(url, **kwargs)[source]#

Load URL to a buffer.

This can be used as the argument for other IO functions such as deepinv.utils.load_torch(), deepinv.utils.load_np() etc. to load data directly from a URL.

Downloaded content is cached under deepinv.utils.get_cache_home() so repeated calls for the same URL do not hit the network again. The cache layout mirrors the URL: a file fetched from https://huggingface.co/datasets/deepinv/images/resolve/main/celeba_example.jpg is stored at <cache_home>/url_cache/huggingface.co/datasets/deepinv/images/resolve/main/celeba_example.jpg. Two URLs that differ only in their query string share the same cache entry — fine for the ?download=true query used by HuggingFace.

The HTTP request uses a (connect, read) timeout of (10, 60) seconds; a hung connection or stalled stream raises a deepinv.utils.DownloadError rather than blocking indefinitely.

Parameters:

url (str) – URL of the file to load

Returns:

BytesIO buffer.

Raises:

deepinv.utils.DownloadError – if the file cannot be downloaded.

Return type:

BytesIO

Examples using load_url:#

Loading scientific images

Loading scientific images