Creating and Saving a Pascal VOC File
Create an object that contains the Pascal VOC information and save the object. For details about Pascal VOC, see Table 2. The path can be either a local or OBS path. If an OBS path is used, a session is required.
pascal_voc.save_xml(xml_file_path, save_mode='w', session=None)
Sample Code
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)
Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
xml_file_path |
Yes |
String |
Path for storing a Pascal VOC XML 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. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.