Bir veri kümesi oluşturduktan sonra, Object Storage Service (OSS) ve Drive and Photo Service (PDS) gibi hizmetlerdeki dosyalar için bir metadata dizini oluşturarak büyük hacimli medya dosyalarını verimli bir şekilde yönetebilir ve erişebilirsiniz.
Önkoşullar
Bir veri kümesi oluşturmuş olmanız gerekir. Daha fazla bilgi için bkz. Veri kümesi oluşturma.
Genel Bakış
Metadata dizini, anahtar kelimeler, nitelikler veya diğer tanımlayıcılara göre büyük medya dosyası koleksiyonlarını aramanızı, filtrelemenizi ve yönetmenizi sağlar.
Yordam
OSS paketindeki tüm dosyaları otomatik olarak indeksleyebilir veya OSS paketindeki ya da PDS'deki belirli dosyaları manuel olarak indeksleyebilirsiniz.
OSS paketindeki tüm dosyaları otomatik olarak indeksleme
OSS paketindeki tüm dosyaları otomatik olarak indekslemek için API çağırarak veya IMM konsolunda veri kaynağı ekleyerek veri kümesi ile paket arasında bir bağlama oluşturun. Bağlama oluşturulduktan sonra Intelligent Media Management (IMM), paketteki mevcut verilerin tam taramasını yapar, dosya metadatasını çıkarır ve indeksler. IMM ardından paketi yeni dosyalara karşı izler ve bu dosyaların metadatasını çıkarmak ve indekslemek için gerçek zamanlı artımlı taramalar gerçekleştirir.
Önemli: Bağlama başarıyla oluşturulduktan sonra IMM, belirtilen OSS paketinizdeki mevcut veya yeni dosyaların taramasını başlatır. Paketinizin içerdiği nesne sayısı arttıkça metadata tarama maliyetleri de yükselir. Daha fazla bilgi için bkz. IMM Faturalama. Bu özelliği test ediyorsanız veya sonuçtan emin değilseniz beklenmeyen ücretlerden kaçınmak için az sayıda dosya içeren bir OSS paketi kullanmanızı ve dikkatli bir şekilde bir iş akışı şablonu seçmenizi öneririz.
API
Aşağıdaki örnekte, test-bucket paketindeki tüm dosyalar indekslenir ve dizin, test-project projesindeki test-dataset veri kümesinde saklanır.
-
Veri kümesi ile OSS paketi arasında bağlama oluşturmak için CreateBinding API'sini çağırın.
-
Örnek istek
{ "ProjectName": "test-project", "URI": "oss://test-bucket", "DatasetName": "test-dataset" } -
Örnek yanıt
{ "Binding": { "Phase": "", "ProjectName": "test-project", "DatasetName": "test-dataset", "State": "Ready", "CreateTime": "2022-07-06T07:03:28.054762739+08:00", "UpdateTime": "2022-07-06T07:03:28.054762739+08:00", "URI": "oss://test-bucket" }, "RequestId": "090D2AC5-8450-0AA8-A1B1-****" } -
Örnek kod (Python SDK)
# -*- 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 an AccessKey ID and AccessKey secret to initialize a 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-beijing.aliyuncs.com' return imm20200930Client(config) @staticmethod def main() -> None: # The AccessKey pair of an Alibaba Cloud account grants full access to all APIs. For better security, we recommend that you use a RAM user for API calls and daily operations. # To prevent security risks, do not hard-code your AccessKey ID and AccessKey secret in your project code. # This example shows how to read the 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_binding_request = imm_20200930_models.CreateBindingRequest( # Specify the name of the IMM project. project_name='test-project', # Specify the name of the IMM dataset. dataset_name='test-dataset', # Specify the URI of the OSS bucket to bind. uri='oss://test-bucket' ) runtime = util_models.RuntimeOptions() try: # Print the API response. response = client.create_binding_with_options(create_binding_request, runtime) print(response.body.to_map()) except Exception as error: # If an error occurs, print the error message. UtilClient.assert_as_string(error.message) print(error) if __name__ == '__main__': Sample.main()
-
-
İsteğe bağlı: Bağlama durumunu sorgulamak için GetBinding API'sini çağırın.
-
Örnek istek
{ "ProjectName": "test-project", "URI": "oss://test-bucket", "DatasetName": "test-dataset" } -
Örnek yanıt
{ "Binding": { "Phase": "IncrementalScanning", "ProjectName": "test-project", "DatasetName": "test-dataset", "State": "Running", "CreateTime": "2022-07-06T07:04:05.105182822+08:00", "UpdateTime": "2022-07-06T07:04:13.302084076+08:00", "URI": "oss://test-bucket" }, "RequestId": "B5A9F54B-6C54-03C9-B011-****" }NotPhase parametresinin değeri IncrementalScanning ise IMM, OSS paketindeki mevcut verileri indekslemeyi tamamlamıştır ve yeni dosyaları artımlı olarak tarıyor demektir.
State parametresinin değeri Running ise bağlama etkin durumdadır.
-
Örnek kod (Python SDK 1.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 an AccessKey ID and AccessKey secret to initialize a client. @param access_key_id: @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-beijing.aliyuncs.com' return imm20200930Client(config) @staticmethod def main() -> None: # The AccessKey pair of an Alibaba Cloud account grants full access to all APIs. For better security, we recommend that you use a RAM user for API calls and daily operations. # To prevent security risks, do not hard-code your AccessKey ID and AccessKey secret in your project code. # This example shows how to read the 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_binding_request = imm_20200930_models.GetBindingRequest( # Specify the name of the IMM project. project_name='test-project', # Specify the name of the IMM dataset. dataset_name='test-dataset', # Specify the URI of the bound OSS bucket. uri='oss://test-bucket' ) runtime = util_models.RuntimeOptions() try: # Print the API response. response = client.get_binding_with_options(get_binding_request, runtime) print(response.body.to_map()) except Exception as error: # If an error occurs, print the error message. UtilClient.assert_as_string(error.message) print(error) if __name__ == '__main__': Sample.main()
-
Veri kaynağı ekleme
-
Projenizde test-dataset veri kümesini bulun.
Sol gezinme bölmesinde Data Management & Indexing > Datasets seçeneklerini belirleyin. Listede test-dataset öğesini bulabilirsiniz.
test-dataset veri kümesine tıklayın, Data access sekmesini seçin ve ardından New Data Source düğmesine tıklayın.
-
Bağlamak istediğiniz paketi seçin ve Tamam'a tıklayın.
NotBir veri kaynağı ekledikten sonra IMM önce paketteki mevcut dosyalar için metadata çıkarma görevleri oluşturur. Ardından IMM, olaylar için veri kaynağını sürekli olarak izler ve buna göre yeni görevler oluşturur. Bu görevler ücrete tabidir. Daha fazla bilgi için bkz. Faturalamaya genel bakış. Bu özelliği az miktarda veri içeren bir paketle test etmenizi öneririz.
Belirli dosyaları manuel olarak indeksleme
API
OSS paketindeki veya PDS'deki belirli dosyaları manuel olarak indekslemek için BatchIndexFileMeta veya IndexFileMeta API'lerini çağırın.
-
BatchIndexFileMeta işlemini çağırma
Aşağıdaki örnekte, test-project projesindeki test-dataset veri kümesinde oss://test-bucket/test-object1.jpg ve oss://test-bucket/test-object2.jpg OSS dosyaları indekslenir.
-
Örnek istek
{ "ProjectName": "test-project", "DatasetName": "test-dataset", "Files": [ { "URI": "oss://test-bucket/test-object1.jpg", "CustomLabels": { "category": "People" } }, { "URI": "oss://test-bucket/test-object2.jpg", "CustomLabels": { "category": "Pets" } } ], "Notification": { "MNS": { "TopicName": "test-topic" } } } -
Örnek yanıt
{ "RequestId": "0D4CB096-EB44-02D6-A4E9-****", "EventId": "16C-1KoeYbdckkiOObpyzc****" } -
Simple Message Queue (MNS) mesajı. Sonuç bir MNS mesajında döndürülür. MNS SDK hakkında daha fazla bilgi için bkz. Adım 4: Mesajları alma ve silme.
{ "ProjectName": "test-project", "DatasetName": "test-dataset", "RequestId": "658FFD57-B495-07C0-B24B-B64CC52993CB", "StartTime": "2022-07-06T07:18:18.664770352+08:00", "EndTime": "2022-07-06T07:18:20.762465221+08:00", "Success": true, "Message": "", "Files": [ { "URI": "oss://test-bucket/test-object1.jpg", "CustomLabels": { "category": "People" }, "Error": "" }, { "URI": "oss://test-bucket/test-object2.jpg", "CustomLabels": { "category": "Pets" }, "Error": "" } ] }NotSuccess parametresi true ise metadata indeksleme görevi başarılı olmuş demektir.
Files dizisi, her dosya için URI ve hata bilgilerini döndürür. Error alanı boşsa dosyanın metadatası başarıyla indekslenmiştir.
-
Örnek kod (Python SDK)
# -*- coding: utf-8 -*- # This file is auto-generated, don't edit it. Thanks. import sys import os from typing import List 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 an AccessKey ID and AccessKey secret to initialize a 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-beijing.aliyuncs.com' return imm20200930Client(config) @staticmethod def main( args: List[str], ) -> None: # The AccessKey pair of an Alibaba Cloud account grants full access to all APIs. For better security, we recommend that you use a RAM user for API calls and daily operations. # To prevent security risks, do not hard-code your AccessKey ID and AccessKey secret in your project code. # This example shows how to read the 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) notification_mns = imm_20200930_models.MNS( topic_name='test-topic' ) notification = imm_20200930_models.Notification( mns=notification_mns ) input_file_0custom_labels = { 'category': 'People' } input_file_0 = imm_20200930_models.InputFile( uri='oss://test-bucket/test-object1.jpg', custom_labels=input_file_0custom_labels ) input_file_1custom_labels = { 'category': 'Pets' } input_file_1 = imm_20200930_models.InputFile( uri='oss://test-bucket/test-object2.jpg', custom_labels=input_file_1custom_labels ) batch_index_file_meta_request = imm_20200930_models.BatchIndexFileMetaRequest( project_name='test-project', dataset_name='test-dataset', files=[ input_file_0, input_file_1 ], notification=notification ) runtime = util_models.RuntimeOptions() try: # Send the request to start the asynchronous indexing task. client.batch_index_file_meta_with_options(batch_index_file_meta_request, runtime) except Exception as error: # If an error occurs, print the error message. UtilClient.assert_as_string(error.message) @staticmethod async def main_async( args: List[str], ) -> None: # The AccessKey pair of an Alibaba Cloud account grants full access to all APIs. For better security, we recommend that you use a RAM user for API calls and daily operations. # To prevent security risks, do not hard-code your AccessKey ID and AccessKey secret in your project code. # This example shows how to read the 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) notification_mns = imm_20200930_models.MNS( topic_name='test-topic' ) notification = imm_20200930_models.Notification( mns=notification_mns ) input_file_0custom_labels = { 'category': 'People' } input_file_0 = imm_20200930_models.InputFile( uri='oss://test-bucket/test-object1.jpg', custom_labels=input_file_0custom_labels ) input_file_1custom_labels = { 'category': 'Pets' } input_file_1 = imm_20200930_models.InputFile( uri='oss://test-bucket/test-object2.jpg', custom_labels=input_file_1custom_labels ) batch_index_file_meta_request = imm_20200930_models.BatchIndexFileMetaRequest( project_name='test-project', dataset_name='test-dataset', files=[ input_file_0, input_file_1 ], notification=notification ) runtime = util_models.RuntimeOptions() try: # When you run the code, print the API response. await client.batch_index_file_meta_with_options_async(batch_index_file_meta_request, runtime) except Exception as error: # If an error occurs, print the error message. UtilClient.assert_as_string(error.message) if __name__ == '__main__': Sample.main(sys.argv[1:])
-
-
IndexFileMeta işlemini çağırma
Aşağıdaki örnekte, test-project projesindeki test-dataset veri kümesinde oss://test-bucket/test-object1.jpg OSS dosyası indekslenir.
-
Örnek istek
{ "ProjectName": "test-project", "DatasetName": "test-dataset", "File": { "URI": "oss://test-bucket/test-object1.jpg", "CustomLabels": { "category": "People" } }, "Notification": { "MNS": { "TopicName": "test-topic" } } } -
Örnek yanıt
{ "RequestId": "5AA694AD-3D10-0B6A-85B2-****", "EventId": "17C-1Kofq1mlJxRYF7vAGF****" } -
Simple Message Queue (MNS) mesajı. Sonuç bir MNS mesajında döndürülür. MNS SDK hakkında daha fazla bilgi için bkz. Adım 4: Mesajları alma ve silme.
{ "ProjectName": "test-project", "DatasetName": "test-dataset", "RequestId": "658FFD57-B495-07C0-B24B-B64CC52993CB", "StartTime": "2022-07-06T07:18:18.664770352+08:00", "EndTime": "2022-07-06T07:18:20.762465221+08:00", "Success": true, "Message": "", "Files": [ { "URI": "oss://test-bucket/test-object1.jpg", "CustomLabels": { "category": "People" }, "Error": "" } ] }NotSuccess parametresi true ise metadata indeksleme görevi başarılı olmuş demektir.
Files dizisi, dosya için URI ve hata bilgilerini döndürür. Error alanı boşsa dosyanın metadatası başarıyla indekslenmiştir.
-
Örnek kod (Python SDK)
# -*- coding: utf-8 -*- # This file is auto-generated, don't edit it. Thanks. import sys import os from typing import List 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 an AccessKey ID and AccessKey secret to initialize a 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-beijing.aliyuncs.com' return imm20200930Client(config) @staticmethod def main( args: List[str], ) -> None: # The AccessKey pair of an Alibaba Cloud account grants full access to all APIs. For better security, we recommend that you use a RAM user for API calls and daily operations. # To prevent security risks, do not hard-code your AccessKey ID and AccessKey secret in your project code. # This example shows how to read the 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) notification_mns = imm_20200930_models.MNS( topic_name='test-topic' ) notification = imm_20200930_models.Notification( mns=notification_mns ) input_file_custom_labels = { 'category': 'People' } input_file = imm_20200930_models.InputFile( uri='oss://test-bucket/test-object1.jpg', custom_labels=input_file_custom_labels ) index_file_meta_request = imm_20200930_models.IndexFileMetaRequest( project_name='test-project', dataset_name='test-dataset', file=input_file, notification=notification ) runtime = util_models.RuntimeOptions() try: # When you run the code, print the API response. client.index_file_meta_with_options(index_file_meta_request, runtime) except Exception as error: # If an error occurs, print the error message. UtilClient.assert_as_string(error.message) @staticmethod async def main_async( args: List[str], ) -> None: # The AccessKey pair of an Alibaba Cloud account grants full access to all APIs. For better security, we recommend that you use a RAM user for API calls and daily operations. # To prevent security risks, do not hard-code your AccessKey ID and AccessKey secret in your project code. # This example shows how to read the 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) notification_mns = imm_20200930_models.MNS( topic_name='test-topic' ) notification = imm_20200930_models.Notification( mns=notification_mns ) input_file_custom_labels = { 'category': 'People' } input_file = imm_20200930_models.InputFile( uri='oss://test-bucket/test-object1.jpg', custom_labels=input_file_custom_labels ) index_file_meta_request = imm_20200930_models.IndexFileMetaRequest( project_name='test-project', dataset_name='test-dataset', file=input_file, notification=notification ) runtime = util_models.RuntimeOptions() try: # When you run the code, print the API response. await client.index_file_meta_with_options_async(index_file_meta_request, runtime) except Exception as error: # If an error occurs, print the error message. UtilClient.assert_as_string(error.message) if __name__ == '__main__': Sample.main(sys.argv[1:])
-
Toplu ekleme
Tek bir toplu işlemde bir OSS paketinden birden çok dosyayı veri kümesine ekleyebilirsiniz. IMM ardından bu yeni dosyaların metadatasını çıkarmak ve indekslemek için eşzamansız bir iş akışı çalıştırır. Bu iş akışı mesaj bildirimlerini desteklediğinden dosyaları eklerken görev sonuçlarını almak için bir MNS konusu belirtin. Daha fazla bilgi için bkz. Eşzamansız bildirim mesaj biçimi.
Projenizde test-dataset veri kümesini bulun.
test-dataset veri kümesine tıklayın, Data access sekmesini seçin ve ardından Batch Add düğmesine tıklayın.
-
Add File to Dataset panelinde sonuçların alınacağı Simple Message Queue (MNS) konusunun adını girin ve ardından indekslemek istediğiniz dosyaları eklemek için Select File seçeneğine tıklayın.
Dosyalar eklendikten sonra listeye eklenen OSS dosya kayıtlarını görüntüleyebilirsiniz. Bir dosyaya özel etiketler eklemek için Edit Labels seçeneğine veya bir dosyayı kaldırmak için Delete seçeneğine tıklayın.