How to use the dtlpy.AnnotationCollection.from_json function in dtlpy

To help you get started, we’ve selected a few dtlpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dataloop-ai / ZazuML / dataloop_services / dl_to_csv.py View on Github external
def get_annotations_from_single_file(w_i, w_img_filename):
        try:
            name, ext = os.path.splitext(w_img_filename)
            name = name.replace(images_path, annotations_path)
            annotation_filename = name + '.json'
            img_annotations = list()
            if not os.path.isfile(annotation_filename):
                print('Missing annotations filepath: {}'.format(annotation_filename))
                img_annotations.append('{},,,,,'.format(w_img_filename))
            else:
                with open(annotation_filename, 'r') as f:
                    data = json.load(f)
                current_annotations = dl.AnnotationCollection.from_json(_json=data['annotations'])
                any_annotation_in_file = False
                for annotation in current_annotations.annotations:
                    try:
                        label = annotation.label.lower()
                        if annotation.type != 'box':
                            continue
                        if label in labels_list:
                            top = int(np.round(annotation.top))
                            left = int(np.round(annotation.left))
                            bottom = int(np.round(annotation.bottom))
                            right = int(np.round(annotation.right))
                            if top == bottom:
                                continue
                            if right == left:
                                continue
                            if label not in label_ids: