Updated on 2024-06-12 GMT+08:00

Creating and Saving a Manifest File

Create an object that contains the manifest information and save the object. For details about the manifest information, see Table 2. The path can be either a local or OBS path. If an OBS path is used, a session is required.

manifest_info.save(path, session=None, save_mode="w")

Sample Code

Before saving a manifest file, create an object that contains the manifest information, including the samples and their labels, and then combine the samples into the manifest file. Call the save API to save the imported session in a specified path.
from modelarts.dataset.format.manifest.annotation import Annotation
from modelarts.dataset.format.manifest import Manifest
from modelarts.dataset.format.manifest.sample import Sample
from modelarts.session import Session

size = 0
sample_list = []
for i in range(19):
    size = size + 1
    source = "s3://obs-path/examples/image-classification/data/image_" + str(i) + ".jpg"
    usage = "TRAIN"
    inference_loc = "s3://obs-path/examples/image-classification/data/image_" + str(i) + ".txt"
    annotations_list = []

    for j in range(1):
        annotation_type = "modelarts/image_classification"
        if 0 == i % 2:
            annotation_name = "Bees"
        else:
            annotation_name = "Rabbits"
        annotation_creation_time = "2019-02-20 08:23:06"
        annotation_format = "manifest"
        annotation_property = {"color": "black"}
        annotation_confidence = 0.8
        annotated_by = "human"
        annotations_list.append(
            Annotation(name=annotation_name, type=annotation_type,
                       confidence=annotation_confidence,
                       creation_time=annotation_creation_time,
                       annotated_by=annotated_by, annotation_format=annotation_format,
                       annotation_property=annotation_property))
    sample_list.append(
        Sample(source=source, usage=usage, annotations=annotations_list, inference_loc=inference_loc))
manifest_info = Manifest(samples=sample_list, size=size)

path = "obs://your-obs-bucket/manifest/V001.manifest"
session = Session()
manifest_info.save(path, session=session, save_mode="a")

Parameters

Table 1 Request parameters

Parameter

Mandatory

Type

Description

path

Yes

String

Path for storing a manifest file

session

No

Object

Session object. For details about the initialization method, see Session Authentication. This parameter is mandatory when OBS is used.

save_mode

No

String

Save mode. The default value is w, indicating rewriting. Value a indicates appending.