─░├žeri─če ge├ž

Referans i├žin hub_sdk/modules/datasets.py

Not

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



hub_sdk.modules.datasets.Datasets

├ťsler: CRUDClient

CRUD i┼člemleri arac─▒l─▒─č─▒yla Veri K├╝meleri ile etkile┼čim i├žin bir istemciyi temsil eden bir s─▒n─▒f. Bu s─▒n─▒f CRUDClient s─▒n─▒f─▒ ve Veri K├╝meleri ile ├žal─▒┼čmak i├žin ├Âzel y├Ântemler sa─člar.

Nitelikler:

─░sim Tip A├ž─▒klama
hub_client DatasetUpload

Model y├╝klemeleriyle etkile┼čim i├žin kullan─▒lan bir DatasetUpload ├Ârne─či.

id (str, None)

Varsa, veri k├╝mesinin benzersiz tan─▒mlay─▒c─▒s─▒.

data dict

Veri k├╝mesi verilerini depolamak i├žin bir s├Âzl├╝k.

Not

'id' ├Âzniteli─či ba┼člatma s─▒ras─▒nda ayarlan─▒r ve bir veri k├╝mesini benzersiz bir ┼čekilde tan─▒mlamak i├žin kullan─▒labilir. 'data' ├Âzniteli─či, API'den al─▒nan veri k├╝mesi verilerini saklamak i├žin kullan─▒l─▒r.

Kaynak kodu hub_sdk/modules/datasets.py
class Datasets(CRUDClient):
    """
    A class representing a client for interacting with Datasets through CRUD operations. This class extends the
    CRUDClient class and provides specific methods for working with Datasets.

    Attributes:
        hub_client (DatasetUpload): An instance of DatasetUpload used for interacting with model uploads.
        id (str, None): The unique identifier of the dataset, if available.
        data (dict): A dictionary to store dataset data.

    Note:
        The 'id' attribute is set during initialization and can be used to uniquely identify a dataset.
        The 'data' attribute is used to store dataset data fetched from the API.
    """

    def __init__(self, dataset_id: Optional[str] = None, headers: Optional[Dict[str, Any]] = None):
        """
        Initialize a Datasets client.

        Args:
            dataset_id (str): Unique id of the dataset.
            headers (dict, optional): Headers to include in HTTP requests.
        """
        super().__init__("datasets", "dataset", headers)
        self.hub_client = DatasetUpload(headers)
        self.id = dataset_id
        self.data = {}
        if dataset_id:
            self.get_data()

    def get_data(self) -> None:
        """
        Retrieves data for the current dataset instance.

        If a valid dataset ID has been set, it sends a request to fetch the dataset data and stores it in the instance.
        If no dataset ID has been set, it logs an error message.

        Returns:
            (None): The method does not return a value.
        """
        if not self.id:
            self.logger.error("No dataset id has been set. Update the dataset id or create a dataset.")
            return

        try:
            response = super().read(self.id)

            if response is None:
                self.logger.error(f"Received no response from the server for dataset ID: {self.id}")
                return

            # Check if the response has a .json() method (it should if it's a response object)
            if not hasattr(response, "json"):
                self.logger.error(f"Invalid response object received for dataset ID: {self.id}")
                return

            resp_data = response.json()
            if resp_data is None:
                self.logger.error(f"No data received in the response for dataset ID: {self.id}")
                return

            self.data = resp_data.get("data", {})
            self.logger.debug(f"Dataset data retrieved for ID: {self.id}")

        except Exception as e:
            self.logger.error(f"An error occurred while retrieving data for dataset ID: {self.id}, {e}")

    def create_dataset(self, dataset_data: dict) -> None:
        """
        Creates a new dataset with the provided data and sets the dataset ID for the current instance.

        Args:
            dataset_data (dict): A dictionary containing the data for creating the dataset.

        Returns:
            (None): The method does not return a value.
        """
        resp = super().create(dataset_data).json()
        self.id = resp.get("data", {}).get("id")
        self.get_data()

    def delete(self, hard: bool = False) -> Optional[Response]:
        """
        Delete the dataset resource represented by this instance.

        Args:
            hard (bool, optional): If True, perform a hard delete.

        Note:
            The 'hard' parameter determines whether to perform a soft delete (default) or a hard delete.
            In a soft delete, the dataset might be marked as deleted but retained in the system.
            In a hard delete, the dataset is permanently removed from the system.

        Returns:
            (Optional[Response]): Response object from the delete request, or None if delete fails.
        """
        return super().delete(self.id, hard)

    def update(self, data: dict) -> Optional[Response]:
        """
        Update the dataset resource represented by this instance.

        Args:
            data (dict): The updated data for the dataset resource.

        Returns:
            (Optional[Response]): Response object from the update request, or None if update fails.
        """
        return super().update(self.id, data)

    def upload_dataset(self, file: str = None) -> Optional[Response]:
        """
        Uploads a dataset file to the hub.

        Args:
            file (str, optional): The path to the dataset file to upload.

        Returns:
            (Optional[Response]): Response object from the upload request, or None if upload fails.
        """
        return self.hub_client.upload_dataset(self.id, file)

    def get_download_link(self) -> Optional[str]:
        """
        Get dataset download link.

        Returns:
            (Optional[str]): Return download link or None if the link is not available.
        """
        return self.data.get("url")

__init__(dataset_id=None, headers=None)

Bir Datasets istemcisini ba┼člat─▒n.

Parametreler:

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

Veri k├╝mesinin benzersiz kimli─či.

None
headers dict

HTTP isteklerine eklenecek ba┼čl─▒klar.

None
Kaynak kodu hub_sdk/modules/datasets.py
def __init__(self, dataset_id: Optional[str] = None, headers: Optional[Dict[str, Any]] = None):
    """
    Initialize a Datasets client.

    Args:
        dataset_id (str): Unique id of the dataset.
        headers (dict, optional): Headers to include in HTTP requests.
    """
    super().__init__("datasets", "dataset", headers)
    self.hub_client = DatasetUpload(headers)
    self.id = dataset_id
    self.data = {}
    if dataset_id:
        self.get_data()

create_dataset(dataset_data)

Sa─članan verilerle yeni bir veri k├╝mesi olu┼čturur ve ge├žerli ├Ârnek i├žin veri k├╝mesi kimli─čini ayarlar.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
dataset_data dict

Veri k├╝mesini olu┼čturmak i├žin verileri i├žeren bir s├Âzl├╝k.

gerekli

─░ade:

Tip A├ž─▒klama
None

Y├Ântem bir de─čer d├Ând├╝rmez.

Kaynak kodu hub_sdk/modules/datasets.py
def create_dataset(self, dataset_data: dict) -> None:
    """
    Creates a new dataset with the provided data and sets the dataset ID for the current instance.

    Args:
        dataset_data (dict): A dictionary containing the data for creating the dataset.

    Returns:
        (None): The method does not return a value.
    """
    resp = super().create(dataset_data).json()
    self.id = resp.get("data", {}).get("id")
    self.get_data()

delete(hard=False)

Bu ├Ârnek taraf─▒ndan temsil edilen veri k├╝mesi kayna─č─▒n─▒ siler.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
hard bool

True ise, sert bir silme i┼člemi ger├žekle┼čtirin.

False
Not

'hard' parametresi yumu┼čak silme mi (varsay─▒lan) yoksa sert silme mi yap─▒laca─č─▒n─▒ belirler. Yumu┼čak silme i┼čleminde, veri k├╝mesi silinmi┼č olarak i┼čaretlenebilir ancak sistemde tutulabilir. Sert silme i┼čleminde, veri k├╝mesi sistemden kal─▒c─▒ olarak kald─▒r─▒l─▒r.

─░ade:

Tip A├ž─▒klama
Optional[Response]

Silme iste─činden gelen yan─▒t nesnesi veya silme ba┼čar─▒s─▒z olursa Yok.

Kaynak kodu hub_sdk/modules/datasets.py
def delete(self, hard: bool = False) -> Optional[Response]:
    """
    Delete the dataset resource represented by this instance.

    Args:
        hard (bool, optional): If True, perform a hard delete.

    Note:
        The 'hard' parameter determines whether to perform a soft delete (default) or a hard delete.
        In a soft delete, the dataset might be marked as deleted but retained in the system.
        In a hard delete, the dataset is permanently removed from the system.

    Returns:
        (Optional[Response]): Response object from the delete request, or None if delete fails.
    """
    return super().delete(self.id, hard)

get_data()

Ge├žerli veri k├╝mesi ├Ârne─či i├žin verileri al─▒r.

Ge├žerli bir veri k├╝mesi kimli─či ayarlanm─▒┼čsa, veri k├╝mesi verilerini almak i├žin bir istek g├Ânderir ve bunu ├Ârnekte depolar. Herhangi bir veri k├╝mesi kimli─či ayarlanmam─▒┼čsa, bir hata mesaj─▒ g├╝nl├╝─če kaydeder.

─░ade:

Tip A├ž─▒klama
None

Y├Ântem bir de─čer d├Ând├╝rmez.

Kaynak kodu hub_sdk/modules/datasets.py
def get_data(self) -> None:
    """
    Retrieves data for the current dataset instance.

    If a valid dataset ID has been set, it sends a request to fetch the dataset data and stores it in the instance.
    If no dataset ID has been set, it logs an error message.

    Returns:
        (None): The method does not return a value.
    """
    if not self.id:
        self.logger.error("No dataset id has been set. Update the dataset id or create a dataset.")
        return

    try:
        response = super().read(self.id)

        if response is None:
            self.logger.error(f"Received no response from the server for dataset ID: {self.id}")
            return

        # Check if the response has a .json() method (it should if it's a response object)
        if not hasattr(response, "json"):
            self.logger.error(f"Invalid response object received for dataset ID: {self.id}")
            return

        resp_data = response.json()
        if resp_data is None:
            self.logger.error(f"No data received in the response for dataset ID: {self.id}")
            return

        self.data = resp_data.get("data", {})
        self.logger.debug(f"Dataset data retrieved for ID: {self.id}")

    except Exception as e:
        self.logger.error(f"An error occurred while retrieving data for dataset ID: {self.id}, {e}")

Veri seti indirme ba─člant─▒s─▒n─▒ al─▒n.

─░ade:

Tip A├ž─▒klama
Optional[str]

─░ndirme ba─člant─▒s─▒n─▒ veya ba─člant─▒ mevcut de─čilse Hi├žbirini d├Ând├╝r.

Kaynak kodu hub_sdk/modules/datasets.py
def get_download_link(self) -> Optional[str]:
    """
    Get dataset download link.

    Returns:
        (Optional[str]): Return download link or None if the link is not available.
    """
    return self.data.get("url")

update(data)

Bu ├Ârnek taraf─▒ndan temsil edilen veri k├╝mesi kayna─č─▒n─▒ g├╝ncelleyin.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
data dict

Veri k├╝mesi kayna─č─▒ i├žin g├╝ncellenmi┼č veriler.

gerekli

─░ade:

Tip A├ž─▒klama
Optional[Response]

G├╝ncelleme iste─činden gelen yan─▒t nesnesi veya g├╝ncelleme ba┼čar─▒s─▒z olursa Yok.

Kaynak kodu hub_sdk/modules/datasets.py
def update(self, data: dict) -> Optional[Response]:
    """
    Update the dataset resource represented by this instance.

    Args:
        data (dict): The updated data for the dataset resource.

    Returns:
        (Optional[Response]): Response object from the update request, or None if update fails.
    """
    return super().update(self.id, data)

upload_dataset(file=None)

Veri k├╝mesi dosyas─▒n─▒ hub'a y├╝kler.

Parametreler:

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

Y├╝klenecek veri k├╝mesi dosyas─▒n─▒n yolu.

None

─░ade:

Tip A├ž─▒klama
Optional[Response]

Kar┼č─▒ya y├╝kleme iste─činden gelen yan─▒t nesnesi veya kar┼č─▒ya y├╝kleme ba┼čar─▒s─▒z olursa Yok.

Kaynak kodu hub_sdk/modules/datasets.py
def upload_dataset(self, file: str = None) -> Optional[Response]:
    """
    Uploads a dataset file to the hub.

    Args:
        file (str, optional): The path to the dataset file to upload.

    Returns:
        (Optional[Response]): Response object from the upload request, or None if upload fails.
    """
    return self.hub_client.upload_dataset(self.id, file)



hub_sdk.modules.datasets.DatasetList

├ťsler: PaginatedList

Kaynak kodu hub_sdk/modules/datasets.py
class DatasetList(PaginatedList):
    def __init__(self, page_size=None, public=None, headers=None):
        """
        Initialize a Dataset instance.

        Args:
            page_size (int, optional): The number of items to request per page.
            public (bool, optional): Whether the items should be publicly accessible.
            headers (dict, optional): Headers to be included in API requests.
        """
        base_endpoint = "datasets"
        super().__init__(base_endpoint, "dataset", page_size, public, headers)

__init__(page_size=None, public=None, headers=None)

Bir Veri K├╝mesi ├Ârne─čini ba┼člat─▒n.

Parametreler:

─░sim Tip A├ž─▒klama Varsay─▒lan
page_size int

Sayfa ba┼č─▒na talep edilecek ├Â─če say─▒s─▒.

None
public bool

├ľ─čelerin kamu eri┼čimine a├ž─▒k olup olmamas─▒.

None
headers dict

API isteklerine dahil edilecek ba┼čl─▒klar.

None
Kaynak kodu hub_sdk/modules/datasets.py
def __init__(self, page_size=None, public=None, headers=None):
    """
    Initialize a Dataset instance.

    Args:
        page_size (int, optional): The number of items to request per page.
        public (bool, optional): Whether the items should be publicly accessible.
        headers (dict, optional): Headers to be included in API requests.
    """
    base_endpoint = "datasets"
    super().__init__(base_endpoint, "dataset", page_size, public, headers)