创建和保存Manifest文件
需要先创建包含Manifest信息的对象,然后保存。Manifest信息请见表2。路径支持本地和OBS,如果是OBS,需要Session信息。
manifest_info.save(path, session=None, save_mode="w")
示例代码
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")
参数说明
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
path |
是 |
String |
Manifest文件保存路径。 |
session |
否 |
Object |
会话对象,初始化方法请参见Session鉴权。 当需要操作OBS时必填。 |
save_mode |
否 |
String |
保存模式。默认为w,即重写模式,另外还支持a,为追加模式。 |