Exemplo n.º 1
0
    def add_annotations(self, annotations: List[Annotation]):
        
        """
        Upload of annotations to the annotation set.
        
        Example::
            urls = ['https://remo-scripts.s3-eu-west-1.amazonaws.com/open_images_sample_dataset.zip']
            ds = remo.create_dataset(name = 'D1', urls = urls)
            ann_set = ds.create_annotation_set(annotation_task = 'Object Detection', name = 'test_set')
            
            image_name = '000a1249af2bc5f0.jpg'
            annotations = []

            annotation = remo.Annotation()
            annotation.img_filename = image_name
            annotation.classes='Human hand'
            annotation.bbox=[227, 284, 678, 674]
            annotations.append(annotation)

            annotation = remo.Annotation()
            annotation.img_filename = image_name
            annotation.classes='Fashion accessory'
            annotation.bbox=[496, 322, 544,370]
            annotations.append(annotation)

            ann_set.add_annotations(annotations)
            
        Args:
            annotations: list of Annotation objects
            
        """
            
        temp_path, list_of_classes = create_tempfile(annotations)
        
            
        self.sdk.add_data_to_dataset(
            dataset_id = self.dataset_id,
            paths_to_upload=[temp_path],
            annotation_task=self.task,
            annotation_set_id=self.id
        )
Exemplo n.º 2
0
    def add_annotations(
        self,
        annotations: List[Annotation],
        annotation_set_id: int = None,
        create_new_annotation_set: bool = False,
    ):
        """
        Fast upload of annotations to the Dataset.

        If annotation_set_id is not provided, annotations will be added to:

            - the only annotation set present, if the Dataset has exactly one Annotation Set and the tasks match
            - a new annotation set, if the Dataset doesn't have any Annotation Sets or if create_new_annotation_set = True

        Otherwise, annotations will be added to the Annotation Set specified by annotation_set_id.

        Example::
            urls = ['https://remo-scripts.s3-eu-west-1.amazonaws.com/open_images_sample_dataset.zip']
            my_dataset = remo.create_dataset(name = 'D1', urls = urls)
            image_name = '000a1249af2bc5f0.jpg'
            annotations = []

            annotation = remo.Annotation()
            annotation.img_filename = image_name
            annotation.classes='Human hand'
            annotation.bbox=[227, 284, 678, 674]
            annotations.append(annotation)

            annotation = remo.Annotation()
            annotation.img_filename = image_name
            annotation.classes='Fashion accessory'
            annotation.bbox=[496, 322, 544,370]
            annotations.append(annotation)

            my_dataset.add_annotations(annotations)

        Args:
            annotations: list of Annotation objects
            annotation_set_id: annotation set id
            create_new_annotation_set: if True, a new annotation set will be created


        """
        if annotation_set_id and create_new_annotation_set:
            raise Exception(
                "You passed an annotation set but also set create_new_annotation_set = True. You can't have both."
            )

        if annotation_set_id:
            annotation_set = self.get_annotation_set(annotation_set_id)
        else:
            annotation_sets = self.annotation_sets()
            if len(annotation_sets) > 0:
                annotation_set = self.get_annotation_set()
                annotation_set_id = annotation_set.id

        temp_path, list_of_classes = create_tempfile(annotations)

        if create_new_annotation_set or (not annotation_set_id):
            n_annotation_sets = len(self.annotation_sets())
            self.create_annotation_set(
                annotation_task=annotations[0].task,
                name='my_ann_set_{}'.format(n_annotation_sets + 1),
                classes=list_of_classes,
                paths_to_files=temp_path,
            )

        else:
            self.add_data(
                annotation_task=annotation_set.task,
                annotation_set_id=annotation_set.id,
                paths_to_upload=[temp_path],
            )

        # TODO ALR: removing the temp_path doesn't work on Windows, hence the try except as a temp fix

        try:
            os.remove(temp_path)
        except:
            pass