创建和保存Pascal VOC文件
需要先创建包含Pascal VOC信息的对象,然后保存。Pascal VOC信息请见表2。路径支持本地和OBS,如果是OBS,需要Session信息。
pascal_voc.save_xml(xml_file_path, save_mode='w', session=None)
示例代码
from modelarts.dataset.format.voc.pascal_voc import PascalVoc from modelarts.dataset.format.voc.voc_object import VocObject from modelarts.session import Session path = "obs://your-obs-bucket/voc/test2.xml" size_list = [640, 321, 3] file_name = "000000089955.jpg" voc_object_tags = ["trafficlight", "trafficlight"] voc_object_properties = [{"@modelarts:color": "#FFFFF0", "@modelarts:shortcut": "C", "pose": "0", "truncated": "0", "difficult": "0", "@modelarts:shape": "bndbox", "@modelarts:feature": [[347, 186], [382, 249]]}, {"@modelarts:color": "#FFFFE0", "@modelarts:shortcut": "D", "pose": "0", "truncated": "0", "difficult": "0", "@modelarts:shape": "bndbox", "@modelarts:feature": [[544, 50], [591, 149]]}] voc_objects = [] for i in range(len(voc_object_tags)): object_tag = voc_object_tags[i] object_properties = voc_object_properties[i] voc_objects.append(VocObject(name=object_tag, properties=object_properties)) pascal_voc = PascalVoc(file_name=file_name, width=size_list[0], height=size_list[1], depth=size_list[2], voc_objects=voc_objects) session = Session() pascal_voc.save_xml(path, session=session)
参数说明
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
xml_file_path |
是 |
String |
Pascal VOC格式的XML文件保存路径。 |
session |
否 |
Object |
会话对象,初始化方法请参见Session鉴权。 当需要操作OBS时必填。 |
save_mode |
否 |
String |
保存模式。默认为w,即重写模式,另外还支持a,为追加模式。 |