def main(argv):

    path = os.path.abspath('../../../') + "/resources/voc/test.xml"
    pascal_voc = PascalVocIO.parse_xml(path)
    validate_python(pascal_voc)
    print("test read VOC xml from python: Success")

    path = os.path.abspath('../../../') + "/resources/voc/2007_000027.xml"
    pascal_voc = PascalVocIO.parse_xml(path)
    validate_uk(pascal_voc)
    print("test read VOC xml from UK: Success")
Ejemplo n.º 2
0
def test_read_voc_xml_with_empty_xml():
    path = os.path.abspath('../../../') + "/resources/voc/errorFiles/empty.xml"
    try:
        pascal_voc = PascalVocIO.parse_xml(path)
    except Exception as e:
        print(e)
        assert ("Can't parse the XML file, no element found" in str(e)) is True
Ejemplo n.º 3
0
def test_read_voc_xml_with_empty_object_difficult():
    path = os.path.abspath('../../../') + "/resources/voc/errorFiles/2007_000027_difficult_empty.xml"
    try:
        pascal_voc = PascalVocIO.parse_xml(path)
    except Exception as e:
        print(e)
        assert ("Can't parse the XML file, object difficult can't be empty in VOC file!; The file is" in str(e)) is True
Ejemplo n.º 4
0
def create_pascal_voc():
    size_list = [640, 426, 3]
    file_name = "000000484951.jpg"
    voc_object_tags = ["labelProperties", "big", "labelProperties3", "labelProperties2", "labelProperties4", "small"]
    voc_object_properties = [{"color": "green", "属性": "绿色", "property": "value", "color2": "blue", "颜色2": "蓝色",
                              "pose": "0", "truncated": "0", "difficult": "0",
                              "@modelarts:shape": "bndbox", "@modelarts:feature": [[199, 356], [230, 385]]},
                             {"pose": "0", "truncated": "0", "difficult": "0",
                              "@modelarts:shape": "bndbox", "@modelarts:feature": [[248, 59], [638, 292]]},
                             {"颜色": "红色", "pose": "0", "truncated": "0", "difficult": "0",
                              "@modelarts:shape": "polygon", "@modelarts:feature": [[202, 293], [199, 308],
                                                                                    [211, 319], [230, 311],
                                                                                    [226, 293], [210, 287],
                                                                                    [202, 293]]},
                             {"color": "yellow", "pose": "0", "truncated": "0", "difficult": "0",
                              "@modelarts:shape": "bndbox", "@modelarts:feature": [[197, 324], [227, 348]]},
                             {"color2": "blue", "pose": "0", "truncated": "0", "difficult": "0",
                              "@modelarts:shape": "bndbox", "@modelarts:feature": [[197, 324], [227, 348]]},
                             {"pose": "0", "truncated": "0", "difficult": "0",
                              "@modelarts:shape": "bndbox", "@modelarts:feature": [[317, 104], [461, 222]]}]
    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))

    return PascalVocIO(file_name=file_name, width=size_list[0], height=size_list[1], depth=size_list[2],
                       voc_objects=voc_objects)
Ejemplo n.º 5
0
def create_pascal_voc():
    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))

    return PascalVocIO(file_name=file_name,
                       width=size_list[0],
                       height=size_list[1],
                       depth=size_list[2],
                       voc_objects=voc_objects)
Ejemplo n.º 6
0
def read_more_than_one_position_in_voc_part():
    path = os.path.abspath('../../../') + "/resources/voc/errorFiles/twoPosition_2007_000027.xml"
    try:
        pascal_voc = PascalVocIO.parse_xml(path)
    except Exception as e:
        print(e)
        assert ("Can't parse the XML file, The number of object position type can't more than one "
              "in one object or one part, there are bndbox and circle in the object; The file is" in str(e)) is True
Ejemplo n.º 7
0
def test_read_voc_xml_with_empty_annotation():
    path = os.path.abspath(
        '../../../') + "/resources/voc/errorFiles/emptyAnnotation.xml"
    try:
        pascal_voc = PascalVocIO.parse_xml(path)
        assert True
    except Exception as e:
        print(e)
        assert False
Ejemplo n.º 8
0
def test_read_voc_xml_with_empty_source():
    path = os.path.abspath(
        '../../../'
    ) + "/resources/voc/errorFiles/2007_000027_source_database_empty.xml"
    try:
        pascal_voc = PascalVocIO.parse_xml(path)
        assert True
    except Exception as e:
        print(e)
        assert False
Ejemplo n.º 9
0
def read_more_than_one_bndbox_in_voc():
    path = os.path.abspath(
        '../../../') + "/resources/voc/errorFiles/twoBndBox.xml"
    try:
        pascal_voc = PascalVocIO.parse_xml(path)
    except Exception as e:
        print(e)
        assert (
            "Can't parse the XML file, The number of object bndbox can't more than one "
            "in one object or one part; The file is" in str(e)) is True
def test_read_voc_xml_label_properties_empty3():
    path = os.path.abspath(
        '../../../') + "/resources/voc/errorFiles/labelPropertiesEmpty3.xml"
    try:
        pascal_voc = PascalVocIO.parse_xml(path)
    except Exception as e:
        print(e)
        assert (
            "Can't parse the XML file, object properties color can't be empty in VOC file!; The file is"
            in str(e)) is True
Ejemplo n.º 11
0
def main(argv):
    if len(argv) < 2:
        path = os.path.abspath(
            '../../../') + "/resources/voc/000000089955_1556180702627.xml"
        pascal_voc = PascalVocIO.parse_xml(path)
        validate(pascal_voc)
        print("test read local xml: Success")
    elif len(argv) < 3:
        path = argv[1]
        pascal_voc = PascalVocIO.parse_xml(path)
        validate(pascal_voc)
        print("test read local xml: Success")
    else:
        path = argv[1]
        ak = argv[2]
        sk = argv[3]
        endpoint = argv[4]
        pascal_voc = PascalVocIO.parse_xml(path, ak, sk, endpoint)
        validate(pascal_voc)
        print("test read OBS xml: Success")
def main(argv):
    path = os.path.abspath('../../../') + "/resources/voc/labelProperties.xml"
    pascal_voc = PascalVocIO.parse_xml(path)
    validate_voc_label_properties(pascal_voc)
Ejemplo n.º 13
0
def create_pascal_voc():
    size_list = [640, 480, 3]
    file_name = "000000115967.jpg"
    voc_object_tags = [
        "car", "car", "DottedLine", "DottedLine", "line", "trafficlight",
        "trafficlight", "greenLight", "redPoint", "redPoint", "redPoint"
    ]
    voc_object_properties = [{
        "pose":
        "0",
        "truncated":
        "0",
        "difficult":
        "0",
        "confidence":
        "0.8",
        "@modelarts:shape":
        "polygon",
        "@modelarts:feature": [[0, 292], [12, 279], [102, 280], [122, 294],
                               [134, 326], [137, 321], [138, 312], [148, 314],
                               [152, 319], [150, 326], [136, 331], [149, 349],
                               [147, 414], [128, 422], [111, 422], [104, 403],
                               [26, 403], [24, 415], [7, 419], [0, 424],
                               [1, 413]]
    }, {
        "pose":
        "0",
        "truncated":
        "0",
        "difficult":
        "0",
        "confidence":
        "0.8",
        "@modelarts:shape":
        "polygon",
        "@modelarts:feature": [[259, 340], [258, 328], [263, 322], [278, 322],
                               [281, 329], [282, 333], [282, 341], [280, 342]]
    }, {
        "pose": "0",
        "truncated": "0",
        "difficult": "0",
        "@modelarts:shape": "dashed",
        "@modelarts:feature": [[474, 456], [370, 339]]
    }, {
        "pose": "0",
        "truncated": "0",
        "difficult": "0",
        "@modelarts:shape": "dashed",
        "@modelarts:feature": [[160, 445], [195, 368]]
    }, {
        "pose": "0",
        "truncated": "0",
        "difficult": "0",
        "@modelarts:shape": "line",
        "@modelarts:feature": [[154, 449], [466, 457]]
    }, {
        "pose": "0",
        "truncated": "0",
        "difficult": "0",
        "@modelarts:shape": "bndbox",
        "@modelarts:feature": [[374, 209], [405, 224]]
    }, {
        "pose": "0",
        "truncated": "0",
        "difficult": "0",
        "@modelarts:shape": "bndbox",
        "@modelarts:feature": [[255, 205], [293, 220]]
    }, {
        "pose": "0",
        "truncated": "0",
        "difficult": "1",
        "@modelarts:shape": "circle",
        "@modelarts:feature": [61, 204, 5]
    }, {
        "pose": "0",
        "truncated": "0",
        "difficult": "0",
        "@modelarts:shape": "point",
        "@modelarts:feature": [259, 282]
    }, {
        "pose": "0",
        "truncated": "0",
        "difficult": "0",
        "@modelarts:shape": "point",
        "@modelarts:feature": [226, 281]
    }, {
        "pose": "0",
        "truncated": "0",
        "difficult": "0",
        "@modelarts:shape": "point",
        "@modelarts:feature": [259, 290]
    }]
    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))

    return PascalVocIO(file_name=file_name,
                       width=size_list[0],
                       height=size_list[1],
                       depth=size_list[2],
                       voc_objects=voc_objects)
def main(argv):
    if len(argv) < 2:
        path_base = os.path.abspath('../../../resources')
        path1 = path_base + "/detect-multi-local-voc.manifest"
        test_multi_default(path1)
        test_multi_exactly_match_type(path1)

        dataset = manifest.parse_manifest(path1)
        sample_num = dataset.get_size()
        for i in range(sample_num):
            sample = dataset.get_sample_list()[i]
            print("sample ", i)
            if len(sample.get_annotations()) == 1:
                validate_single_annotation_sample(sample)
                annotation = sample.get_annotations()[0]
                if "2007_000027" in annotation.get_loc():
                    path2 = path_base + annotation.get_loc()[1:]
                    pascal_voc = PascalVocIO.parse_xml(path2)
                    test_read_voc_xml_local.validate_uk(pascal_voc)
                    print("test read VOC xml from UK: Success")
                if "000000089955_1556180702627" in annotation.get_loc():
                    path2 = path_base + annotation.get_loc()[1:]
                    pascal_voc = PascalVocIO.parse_xml(path2)
                    test_read_voc_xml_local.validate(pascal_voc)
                    print("test read VOC xml: Success")
            else:
                annotations = sample.get_annotations()
                for annotation in annotations:
                    assert annotation.get_annotation_format() == "PASCAL VOC"
                    assert annotation.get_annotated_by() == "human"
                    assert annotation.get_type(
                    ) == "modelarts/object_detection"
                    if "2007_000027" in annotation.get_loc():
                        path2 = path_base + annotation.get_loc()[1:]
                        pascal_voc = PascalVocIO.parse_xml(path2)
                        test_read_voc_xml_local.validate_uk(pascal_voc)
                        print("test read VOC xml from UK: Success")
                    if "000000089955_1556180702627" in annotation.get_loc():
                        path2 = path_base + annotation.get_loc()[1:]
                        pascal_voc = PascalVocIO.parse_xml(path2)
                        test_read_voc_xml_local.validate(pascal_voc)
                        print("test read VOC xml: Success")
        print("test local Success")
    elif len(argv) < 3:
        path1 = argv[1]
        path_base = path1[:path1.rfind('/')]
        test_multi_default(path1)
        test_multi_exactly_match_type(path1)

        dataset = manifest.parse_manifest(path1)
        sample_num = dataset.get_size()
        for i in range(sample_num):
            sample = dataset.get_sample_list()[i]
            print("sample ", i)
            if len(sample.get_annotations()) == 1:
                validate_single_annotation_sample(sample)
                annotation = sample.get_annotations()[0]
                if "2007_000027" in annotation.get_loc():
                    path2 = path_base + annotation.get_loc()[1:]
                    pascal_voc = PascalVocIO.parse_xml(path2)
                    test_read_voc_xml_local.validate_uk(pascal_voc)
                    print("test read VOC xml from UK: Success")
                if "000000089955_1556180702627" in annotation.get_loc():
                    path2 = path_base + annotation.get_loc()[1:]
                    pascal_voc = PascalVocIO.parse_xml(path2)
                    test_read_voc_xml_local.validate(pascal_voc)
                    print("test read VOC xml: Success")
            else:
                annotations = sample.get_annotations()
                for annotation in annotations:
                    assert annotation.get_annotation_format() == "PASCAL VOC"
                    assert annotation.get_annotated_by() == "human"
                    assert annotation.get_type(
                    ) == "modelarts/object_detection"
                    if "2007_000027" in annotation.get_loc():
                        path2 = path_base + annotation.get_loc()[1:]
                        pascal_voc = PascalVocIO.parse_xml(path2)
                        test_read_voc_xml_local.validate_uk(pascal_voc)
                        print("test read VOC xml from UK: Success")
                    if "000000089955_1556180702627" in annotation.get_loc():
                        path2 = path_base + annotation.get_loc()[1:]
                        pascal_voc = PascalVocIO.parse_xml(path2)
                        test_read_voc_xml_local.validate(pascal_voc)
                        print("test read VOC xml: Success")
    else:
        path_base = "s3://obs-dataset-sjy"
        path1 = path_base + "/detect-multi-local-voc.manifest"
        ak = argv[1]
        sk = argv[2]
        endpoint = argv[3]
        test_multi_default(path1, ak, sk, endpoint)
        test_multi_exactly_match_type(path1, ak, sk, endpoint)

        dataset = manifest.parse_manifest(path1, ak, sk, endpoint)
        sample_num = dataset.get_size()
        for i in range(sample_num):
            sample = dataset.get_sample_list()[i]
            print("sample ", i)
            if len(sample.get_annotations()) == 1:
                validate_single_annotation_sample(sample)
                annotation = sample.get_annotations()[0]
                if "2007_000027" in annotation.get_loc():
                    path2 = path_base + annotation.get_loc()[1:]
                    pascal_voc = PascalVocIO.parse_xml(path2, ak, sk, endpoint)
                    test_read_voc_xml_local.validate_uk(pascal_voc)
                    print("test read VOC xml from UK: Success")
                if "000000089955_1556180702627" in annotation.get_loc():
                    path2 = path_base + annotation.get_loc()[1:]
                    pascal_voc = PascalVocIO.parse_xml(path2, ak, sk, endpoint)
                    test_read_voc_xml_local.validate(pascal_voc)
                    print("test read VOC xml: Success")
            else:
                annotations = sample.get_annotations()
                for annotation in annotations:
                    assert annotation.get_annotation_format() == "PASCAL VOC"
                    assert annotation.get_annotated_by() == "human"
                    assert annotation.get_type(
                    ) == "modelarts/object_detection"
                    if "2007_000027" in annotation.get_loc():
                        path2 = path_base + annotation.get_loc()[1:]
                        pascal_voc = PascalVocIO.parse_xml(
                            path2, ak, sk, endpoint)
                        test_read_voc_xml_local.validate_uk(pascal_voc)
                        print("test read VOC xml from UK: Success")
                    if "000000089955_1556180702627" in annotation.get_loc():
                        path2 = path_base + annotation.get_loc()[1:]
                        pascal_voc = PascalVocIO.parse_xml(
                            path2, ak, sk, endpoint)
                        test_read_voc_xml_local.validate(pascal_voc)
                        print("test read VOC xml: Success")
        print("test OBS Success")
def main(argv):
    path = os.path.abspath(
        '../../../') + "/resources/voc/000000115967_1556247179208.xml"
    pascal_voc = PascalVocIO.parse_xml(path)
    validate_voc_multiple_object(pascal_voc)