─░├žeri─če ge├ž

Referans i├žin ultralytics/utils/patches.py

Not

Bu dosya https://github.com/ultralytics/ultralytics/blob/main/ ultralytics/utils/patches .py adresinde mevcuttur. Bir sorun tespit ederseniz l├╝tfen bir ├çekme ─░ste─či ­čŤá´ŞĆ ile katk─▒da bulunarak d├╝zeltilmesine yard─▒mc─▒ olun. Te┼čekk├╝rler ­čÖĆ!



ultralytics.utils.patches.imread(filename, flags=cv2.IMREAD_COLOR)

Dosyadan bir g├Âr├╝nt├╝ okuyun.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
filename str

Okunacak dosyan─▒n yolu.

gerekli
flags int

cv2.IMREAD_* de─čerlerini alabilen bayrak. Varsay─▒lan de─čer cv2.IMREAD_COLOR'dur.

IMREAD_COLOR

─░ade:

Tip A├ž─▒klama
ndarray

Okunan g├Âr├╝nt├╝.

Kaynak kodu ultralytics/utils/patches.py
def imread(filename: str, flags: int = cv2.IMREAD_COLOR):
    """
    Read an image from a file.

    Args:
        filename (str): Path to the file to read.
        flags (int, optional): Flag that can take values of cv2.IMREAD_*. Defaults to cv2.IMREAD_COLOR.

    Returns:
        (np.ndarray): The read image.
    """
    return cv2.imdecode(np.fromfile(filename, np.uint8), flags)



ultralytics.utils.patches.imwrite(filename, img, params=None)

Bir dosyaya g├Âr├╝nt├╝ yaz─▒n.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
filename str

Yaz─▒lacak dosyan─▒n yolu.

gerekli
img ndarray

Yaz─▒lacak resim.

gerekli
params list of ints

Ek parametreler. OpenCV belgelerine bak─▒n.

None

─░ade:

Tip A├ž─▒klama
bool

Dosya yaz─▒ld─▒ysa True, aksi takdirde False.

Kaynak kodu ultralytics/utils/patches.py
def imwrite(filename: str, img: np.ndarray, params=None):
    """
    Write an image to a file.

    Args:
        filename (str): Path to the file to write.
        img (np.ndarray): Image to write.
        params (list of ints, optional): Additional parameters. See OpenCV documentation.

    Returns:
        (bool): True if the file was written, False otherwise.
    """
    try:
        cv2.imencode(Path(filename).suffix, img, params)[1].tofile(filename)
        return True
    except Exception:
        return False



ultralytics.utils.patches.imshow(winname, mat)

Belirtilen pencerede bir g├Âr├╝nt├╝ g├Âr├╝nt├╝ler.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
winname str

Pencerenin ad─▒.

gerekli
mat ndarray

G├Âsterilecek resim.

gerekli
Kaynak kodu ultralytics/utils/patches.py
def imshow(winname: str, mat: np.ndarray):
    """
    Displays an image in the specified window.

    Args:
        winname (str): Name of the window.
        mat (np.ndarray): Image to be shown.
    """
    _imshow(winname.encode("unicode_escape").decode(), mat)



ultralytics.utils.patches.torch_save(*args, use_dill=True, **kwargs)

─░ste─če ba─čl─▒ olarak, pickle'─▒n yapmad─▒─č─▒ lambda i┼člevlerini serile┼čtirmek i├žin dill kullan─▒n, 3 yeniden deneme ile sa─člaml─▒k ekleyin ve kaydetme hatas─▒ durumunda ├╝stel uzakla┼čma.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
*args tuple

torch.save adresine iletilecek konumsal arg├╝manlar.

()
use_dill bool

Varsa serile┼čtirme i├žin dill kullanmay─▒ deneyip denemeyece─činiz. Varsay─▒lan de─čer True'dur.

True
**kwargs any

torch.save adresine iletilecek anahtar kelime arg├╝manlar─▒.

{}
Kaynak kodu ultralytics/utils/patches.py
def 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.

    Args:
        *args (tuple): Positional arguments to pass to torch.save.
        use_dill (bool): Whether to try using dill for serialization if available. Defaults to True.
        **kwargs (any): Keyword arguments to pass to torch.save.
    """
    try:
        assert use_dill
        import dill as pickle
    except (AssertionError, ImportError):
        import pickle

    if "pickle_module" not in kwargs:
        kwargs["pickle_module"] = pickle

    for i in range(4):  # 3 retries
        try:
            return _torch_save(*args, **kwargs)
        except RuntimeError as e:  # unable to save, possibly waiting for device to flush or antivirus scan
            if i == 3:
                raise e
            time.sleep((2**i) / 2)  # exponential standoff: 0.5s, 1.0s, 2.0s





Created 2023-11-12, Updated 2024-06-02
Authors: glenn-jocher (5), Burhan-Q (1), Laughing-q (1)