MCPcopy Create free account
hub / github.com/NVIDIA/DALI / _imread_impl

Function _imread_impl

dali/python/nvidia/dali/experimental/dynamic/_imread.py:25–127  ·  view source on GitHub ↗

Reads and decodes an image (or batch of images) from file path(s). Parameters ---------- filepaths : str, pathlib.Path, list of str/pathlib.Path, Tensor, or Batch Path(s) to image file(s) to read. Can be: - A single string or pathlib.Path filepath - A list

(filepaths: Union[str, List[str], Tensor, Batch], device: str = "cpu", **kwargs)

Source from the content-addressed store, hash-verified

23
24
25def _imread_impl(filepaths: Union[str, List[str], Tensor, Batch], device: str = "cpu", **kwargs):
26 """
27 Reads and decodes an image (or batch of images) from file path(s).
28
29 Parameters
30 ----------
31 filepaths : str, pathlib.Path, list of str/pathlib.Path, Tensor, or Batch
32 Path(s) to image file(s) to read. Can be:
33
34 - A single string or pathlib.Path filepath
35 - A list of string or pathlib.Path filepaths (returns a Batch)
36 - A Tensor containing encoded filepath bytes
37 - A Batch containing encoded filepath bytes
38
39 device : str, optional
40 Device to decode the image on. Can be "cpu" or "gpu"
41 Default is "cpu".
42
43 <DECODERS_IMAGE_KWARGS_PLACEHOLDER>
44
45 Returns
46 -------
47 Tensor or Batch
48 Decoded image(s). Returns a Tensor for a single image, or a Batch
49 for multiple images.
50
51 Note
52 ----
53 This function is currently implemented by combining :func:`io.file.read` and
54 :func:`decoders.image`, providing a simple interface for loading images
55 from disk. This may change in the future to provide a more efficient implementation.
56
57 Examples
58 --------
59 Read a single image:
60
61 >>> import nvidia.dali.experimental.dynamic as ndd
62 >>> img = ndd.imread("/path/to/image.jpg")
63
64 Read multiple images as a batch:
65
66 >>> imgs = ndd.imread(["/path/to/img1.jpg", "/path/to/img2.jpg"])
67
68 Supports pathlib.Path objects:
69
70 >>> from pathlib import Path
71 >>> img = ndd.imread(Path("/path/to/image.jpg"))
72 >>> imgs = ndd.imread([Path("/path/to/img1.jpg"), Path("/path/to/img2.jpg")])
73
74 Decode on GPU:
75
76 >>> img = ndd.imread("/path/to/image.jpg", device="gpu")
77
78 Decode to grayscale:
79
80 >>> from nvidia.dali import types
81 >>> img = ndd.imread("/path/to/image.jpg", output_type=types.GRAY)
82

Callers 1

imread_wrapperFunction · 0.85

Calls 6

batchFunction · 0.85
readMethod · 0.80
tensorFunction · 0.70
typeFunction · 0.50
copyMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected