Tous les produits
Search
Centre de documentation

Intelligent Media Management:Create a dataset

Dernière mise à jour :Aug 10, 2026

Un dataset est un conteneur permettant de stocker et de gérer des métadonnées. Cette rubrique explique comment créer un dataset.

Notes d'utilisation

  • Stockez les fichiers non liés dans des datasets distincts et les fichiers connexes dans le même dataset.

  • Le nombre de datasets dans un projet ne peut pas dépasser la limite du projet.

  • Le nombre de fichiers dans un dataset ne peut pas dépasser sa limite. Le nombre total de fichiers dans tous les datasets d'un projet ne peut pas dépasser la limite du projet.

  • Le nombre de buckets OSS liés à un dataset ne peut pas dépasser sa limite. Le nombre total de buckets liés à tous les datasets d'un projet ne peut pas dépasser la limite du projet.

  • Lors de la construction d'un index de métadonnées, le modèle de flux de travail (workflow template) du dataset prime sur celui du projet. Si le dataset ne dispose pas de modèle de flux de travail, IMM utilise le modèle du projet. Pour plus d'informations sur les modèles de flux de travail, consultez Modèles de flux de travail et opérateurs.

Prérequis

  • Créez une paire AccessKey. Pour plus d'informations, consultez Créer une paire AccessKey.

  • Activez OSS, créez un bucket et téléchargez-y des fichiers. Pour plus d'informations, consultez Télécharger des fichiers.

  • Activez IMM. Pour plus d'informations, consultez Activer IMM.

  • Créez un projet dans la console IMM. Pour plus d'informations, consultez Créer un projet.

    Remarque
    • Vous pouvez également appeler l'opération CreateProject pour créer un projet. Pour plus d'informations, consultez Créer un projet.

    • Appelez l'opération ListProjects pour répertorier tous les projets d'une région spécifiée.

Procédure

Étape 1 : Créer un dataset

Cet exemple appelle l'opération CreateDataset pour créer un dataset nommé test-dataset avec la description Dataset 1 et le modèle Official:ImageManagement dans le projet test-project.

  • Exemple de requête

    {
     "ProjectName": "test-project",
     "DatasetName": "test-dataset",
     "Description": "Dataset 1",
     "TemplateId": "Official:ImageManagement"
    }
  • Exemple de réponse

    {
        "RequestId": "9AB4BD43-C4E5-06AA-A7AB-****",
        "Dataset": {
            "FileCount": 0,
            "BindCount": 0,
            "ProjectName": "test-project",
            "CreateTime": "2022-07-05T10:43:32.429344821+08:00",
            "DatasetMaxTotalFileSize": 90000000000000000,
            "DatasetMaxRelationCount": 100000000000,
            "DatasetMaxFileCount": 100000000,
            "DatasetName": "test-dataset",
            "DatasetMaxBindCount": 10,
            "UpdateTime": "2022-07-05T10:43:32.429344821+08:00",
            "DatasetMaxEntityCount": 10000000000,
            "TotalFileSize": 0,
            "TemplateId": "Official:ImageManagement"
        }
    }
  • Exemple de code complet (SDK Python v1.27.3)

    # -*- coding: utf-8 -*-
    
    import os
    from alibabacloud_imm20200930.client import Client as imm20200930Client
    from alibabacloud_tea_openapi import models as open_api_models
    from alibabacloud_imm20200930 import models as imm_20200930_models
    from alibabacloud_tea_util import models as util_models
    from alibabacloud_tea_util.client import Client as UtilClient
    
    class Sample:
        def __init__(self):
            pass
    
        @staticmethod
        def create_client(
            access_key_id: str,
            access_key_secret: str,
        ) -> imm20200930Client:
            """
            Use your AccessKey ID and AccessKey secret to initialize the client.
            @param access_key_id:
            @param access_key_secret:
            @return: Client
            @throws Exception
            """
            config = open_api_models.Config(
                access_key_id=access_key_id,
                access_key_secret=access_key_secret
            )
            # Specify the endpoint.
            config.endpoint = f'imm.cn-shenzhen.aliyuncs.com'
            return imm20200930Client(config)
    
        @staticmethod
        def main() -> None:
            # An Alibaba Cloud account AccessKey pair can perform all API operations. For security, we recommend using a RAM user for API access or routine O&M.
            # Do not hard-code your AccessKey ID and AccessKey secret in the code. This practice can lead to security risks if the keys are leaked.
            # This example retrieves an AccessKey pair from environment variables for authentication. For more information about how to configure environment variables, see https://www.alibabacloud.com/help/document_detail/2361894.html.
            imm_access_key_id = os.getenv("AccessKeyId")
            imm_access_key_secret = os.getenv("AccessKeySecret")
            client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
            create_dataset_request = imm_20200930_models.CreateDatasetRequest(
                project_name='test-project',
                dataset_name='test-dataset',
                description='Dataset 1',
                template_id='Official:ImageManagement'
            )
            runtime = util_models.RuntimeOptions()
            try:
                # Print the response of the API operation.
                response = client.create_dataset_with_options(create_dataset_request, runtime)
                print(response.body.to_map())
            except Exception as error:
                # Print the error message if an error occurs.
                UtilClient.assert_as_string(error.message)
                print(error)
    
    if __name__ == '__main__':
        Sample.main()

(Facultatif) Étape 2 : Interroger un dataset

Cet exemple appelle l'opération GetDataset pour interroger le dataset nommé test-dataset dans le projet test-project.

  • Exemple de requête

    {
     "ProjectName": "test-project",
     "DatasetName": "test-dataset"
    }
  • Exemple de réponse

    {
        "RequestId": "9AB4BD43-C4E5-06AA-E4B2-****",
        "Dataset": {
            "FileCount": 0,
            "BindCount": 0,
            "ProjectName": "test-project",
            "CreateTime": "2022-07-05T10:43:32.429344821+08:00",
            "DatasetMaxTotalFileSize": 90000000000000000,
            "DatasetMaxRelationCount": 100000000000,
            "DatasetMaxFileCount": 100000000,
            "DatasetName": "test-dataset",
            "DatasetMaxBindCount": 10,
            "UpdateTime": "2022-07-05T10:43:32.429344821+08:00",
            "DatasetMaxEntityCount": 10000000000,
            "TotalFileSize": 0,
            "TemplateId": "Official:ImageManagement"
        }
    }
  • Exemple de code complet (SDK Python v1.27.3)

    # -*- coding: utf-8 -*-
    
    import os
    from alibabacloud_imm20200930.client import Client as imm20200930Client
    from alibabacloud_tea_openapi import models as open_api_models
    from alibabacloud_imm20200930 import models as imm_20200930_models
    from alibabacloud_tea_util import models as util_models
    from alibabacloud_tea_util.client import Client as UtilClient
    
    class Sample:
        def __init__(self):
            pass
    
        @staticmethod
        def create_client(
            access_key_id: str,
            access_key_secret: str,
        ) -> imm20200930Client:
            """
            Use your AccessKey ID and AccessKey secret to initialize the client.
            @param access_key_id:
            @param access_key_secret:
            @return: Client
            @throws Exception
            """
            config = open_api_models.Config(
                access_key_id=access_key_id,
                access_key_secret=access_key_secret
            )
            # Specify the endpoint.
            config.endpoint = f'imm.cn-shenzhen.aliyuncs.com'
            return imm20200930Client(config)
    
        @staticmethod
        def main() -> None:
            # An Alibaba Cloud account AccessKey pair can perform all API operations. For security, we recommend using a RAM user for API access or routine O&M.
            # Do not hard-code your AccessKey ID and AccessKey secret in the code. This practice can lead to security risks if the keys are leaked.
            # This example retrieves an AccessKey pair from environment variables for authentication. For more information about how to configure environment variables, see https://www.alibabacloud.com/help/document_detail/2361894.html.
            imm_access_key_id = os.getenv("AccessKeyId")
            imm_access_key_secret = os.getenv("AccessKeySecret")
            client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
            get_dataset_request = imm_20200930_models.GetDatasetRequest(
                # Specify the name of the IMM project.
                project_name='test-project',
                # Specify the name of the dataset.
                dataset_name='test-dataset',
                # Do not return statistics, such as the number of files and total file size.
                with_statistics=False
            )
            runtime = util_models.RuntimeOptions()
            try:
                # Print the response of the API operation.
                response = client.get_dataset_with_options(get_dataset_request, runtime)
                print(response.body.to_map())
            except Exception as error:
                # Print the error message if an error occurs.
                UtilClient.assert_as_string(error.message)
                print(error)
    
    if __name__ == '__main__':
        Sample.main()