Reference for ultralytics/utils/patches.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/patches.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.utils.patches.imread(filename, flags=cv2.IMREAD_COLOR)
Read an image from a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
Path to the file to read. |
required |
flags |
int
|
Flag that can take values of cv2.IMREAD_*. Defaults to cv2.IMREAD_COLOR. |
IMREAD_COLOR
|
Returns:
Type | Description |
---|---|
ndarray
|
The read image. |
Source code in ultralytics/utils/patches.py
ultralytics.utils.patches.imwrite(filename, img, params=None)
Write an image to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
Path to the file to write. |
required |
img |
ndarray
|
Image to write. |
required |
params |
list of ints
|
Additional parameters. See OpenCV documentation. |
None
|
Returns:
Type | Description |
---|---|
bool
|
True if the file was written, False otherwise. |
Source code in ultralytics/utils/patches.py
ultralytics.utils.patches.imshow(winname, mat)
Displays an image in the specified window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
winname |
str
|
Name of the window. |
required |
mat |
ndarray
|
Image to be shown. |
required |
ultralytics.utils.patches.torch_save(*args, use_dill=True, **kwargs)
Optionally use dill to serialize lambda functions where pickle does not, adding robustness with 3 retries and exponential standoff in case of save failure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
tuple
|
Positional arguments to pass to torch.save. |
()
|
use_dill |
bool
|
Whether to try using dill for serialization if available. Defaults to True. |
True
|
**kwargs |
any
|
Keyword arguments to pass to torch.save. |
{}
|