Esempio n. 1
0
def json_to_pascal(labelled_data='json_files/project_labels.json'):

    print("Downloading images and xml files, please wait...")

    # set labeled_data to the file path of the Labelbox JSON export
    if labelled_data != 'json_files/project_labels.json':
        labelled_data = labelled_data

    # set ann_output_dir to the file path of the directory to write Pascal VOC
    # annotation files. The directory must exist.
    if not os.path.exists('Annotations'):
        os.mkdir('Annotations')
    ann_output_dir = './Annotations'

    # set images_output_dir to the file path of the directory to write images.
    # The directory must exist.
    if not os.path.exists('Images'):
        os.mkdir('Images')
    images_output_dir = './Images'

    # call the Labelbox to Pascal conversion
    # NOTE: make sure to specify the correct label_format based on the export
    #  format chosen on Labelbox; 'WKT' or 'XY'.
    lb2pa.from_json(labeled_data=labelled_data, annotations_output_dir=ann_output_dir,
                    images_output_dir=images_output_dir, label_format='XY')

    print('Done getting xml files')
 def test_bad_label_format(self):
     try:
         lb2pa.from_json('test-fixtures/labelbox_xy_1.json',
                         self.results_output(),
                         self.results_output(),
                         label_format='bad format')
     except lb2pa.UnknownFormatError as e:
         pass
Esempio n. 3
0
def test_v3_wkt_bndbox(output_dir):
    fixture = 'test-fixtures/v3_wkt_rectangle.json'
    with open(fixture, 'r') as f:
        annotation_file_path = output_dir + '/' + json.load(
            f)[0]['ID'] + '.xml'

    lb2pa.from_json(fixture, output_dir, output_dir, label_format='WKT')

    with open(annotation_file_path, 'r') as f:
        annotation = xmltodict.parse(f.read())
        assert 'bndbox' in annotation['annotation']['object']
Esempio n. 4
0
def test_from_json():
    if not os.path.isdir('test-results'):
        os.makedirs('test-results')

    # test 1
    lb2pa.from_json('test-fixtures/labelbox_1.json', 'test-results',
                    'test-results')

    # test 2
    lb2pa.from_json('test-fixtures/labelbox_2.json', 'test-results',
                    'test-results')
 def test_xy_1(self):
     lb2pa.from_json('test-fixtures/labelbox_xy_1.json',
                     self.results_output(),
                     self.results_output(),
                     label_format='XY')
 def test_wkt_2(self):
     lb2pa.from_json('test-fixtures/labelbox_2.json', self.results_output(),
                     self.results_output())
Esempio n. 7
0
# import labelbox2pascal library
import labelbox2pascal as lb2pa

# set labeled_data to the file path of the Labelbox JSON export
labeled_data = 'testimages.json'

# set ann_output_dir to the file path of the directory to write Pascal VOC
# annotation files. The directory must exist.
ann_output_dir = 'M:\\Documents\\700_Tutorials\\bibtagger_hood_2018\\bib-tagger\\Annotatins'

# set images_output_dir to the file path of the directory to write images.
# The directory must exist.
images_output_dir = 'M:\\Documents\\700_Tutorials\\bibtagger_hood_2018\\bib-tagger\\Images'

# call the Labelbox to Pascal conversion
# NOTE: make sure to specify the correct label_format based on the export
#  format chosen on Labelbox; 'WKT' or 'XY'.
lb2pa.from_json(labeled_data=labeled_data,
                ann_output_dir=ann_output_dir,
                images_output_dir=images_output_dir,
                label_format='XY')
def remove_duplicates_from_label_box(export_file, new_export_file):
    with open(export_file) as f:
        temp_label_data = json.loads(f.read())

    with open(export_file, 'w') as outfile:
        json.dump(temp_label_data, outfile, sort_keys=True, indent=4)

    seen = set()
    new_label_data = []

    for dic in temp_label_data:
        key = (dic['DataRow ID'])
        if key in seen:
            continue
        new_label_data.append(dic)
        seen.add(key)

    with open(new_export_file, 'w') as outfile:
        json.dump(new_label_data, outfile, sort_keys=True, indent=4)


remove_duplicates_from_label_box(labeled_data, labeled_data_no_duplicates)

lb2pa.from_json(labeled_data=labeled_data_no_duplicates,
                annotations_output_dir=ann_output_dir,
                images_output_dir=images_output_dir,
                image_sets_dir=image_sets_dir,
                label_format='object',
                database='fulldata - version 6 - labelbox - reworked',
                use_local=False,
                local_image_dir='')
Esempio n. 9
0
def test_bad_label_format(output_dir):
    with pytest.raises(lb2pa.UnknownFormatError):
        lb2pa.from_json('test-fixtures/labelbox_xy_1.json',
                        output_dir,
                        output_dir,
                        label_format='INVALID')
Esempio n. 10
0
def test_empty_skipped(output_dir):
    lb2pa.from_json('test-fixtures/empty_skipped.json',
                    output_dir,
                    output_dir,
                    label_format='WKT')
Esempio n. 11
0
def test_v3_xy(output_dir):
    lb2pa.from_json('test-fixtures/v3_xy.json',
                    output_dir,
                    output_dir,
                    label_format='XY')
Esempio n. 12
0
def test_xy_1(output_dir):
    lb2pa.from_json('test-fixtures/labelbox_xy_1.json',
                    output_dir,
                    output_dir,
                    label_format='XY')
Esempio n. 13
0
def test_v3_wkt(output_dir):
    lb2pa.from_json('test-fixtures/v3_wkt.json', output_dir, output_dir)
Esempio n. 14
0
def test_wkt_2(output_dir):
    lb2pa.from_json('test-fixtures/labelbox_2.json', output_dir, output_dir)