def set_annotation(self, ann: Union[Annotation, dict] = None):
     if ann is not None:
         if type(ann) is dict:
             res_ann = Annotation.from_json(ann, self._project_meta)
         else:
             res_ann = ann.clone()
     else:
         res_ann = None
     self._ann = res_ann
 def _set_item(self,
               name,
               title,
               image_url,
               ann: Union[Annotation, dict] = None):
     setattr(self, f"_{name}_title", title)
     setattr(self, f"_{name}_image_url", image_url)
     res_ann = Annotation((1, 1))
     if ann is not None:
         if type(ann) is dict:
             res_ann = Annotation.from_json(ann, self._project_meta)
         else:
             res_ann = ann.clone()
     setattr(self, f"_{name}_ann", res_ann)
Example #3
0
    def _do_single_img_inference(self, img, in_msg):
        in_project_meta = self._in_project_meta_from_msg(in_msg)
        ann_json = in_msg.get('annotation')
        if ann_json is not None:
            if in_project_meta is None:
                raise ValueError('In order to perform inference with annotation you must specify the appropriate'
                                 ' project meta.')
            ann = Annotation.from_json(ann_json, in_project_meta)
        else:
            in_project_meta = in_project_meta or ProjectMeta()
            ann = Annotation(img.shape[:2])

        inference_mode = self._make_inference_mode(in_msg.get(MODE, {}), in_project_meta)
        inference_result = inference_mode.infer_annotate(img, ann)
        return inference_result.to_json()
Example #4
0
    def add_item(self,
                 title,
                 image_url,
                 ann: Union[Annotation, dict] = None,
                 col_index=None,
                 custom_info: dict = None,
                 zoom_to_figure=None,
                 title_url=None):

        if col_index is not None:
            if col_index <= 0 or col_index > self.col_number:
                raise ValueError(
                    "Column number is not correct, check your input data")

        res_ann = Annotation((1, 1))
        if ann is not None:
            if type(ann) is dict:
                res_ann = Annotation.from_json(ann, self._project_meta)
            else:
                res_ann = ann.clone()

        self._data[title] = {
            "image_url": image_url,
            "ann": res_ann,
            "col_index": col_index
        }

        if zoom_to_figure is not None:
            self._data[title]["zoom_to_figure"] = zoom_to_figure
            self._need_zoom = True

        if title_url is not None:
            self.preview_info = True
            self._with_title_url = True
            self._data[title]["labelingUrl"] = title_url

        if self.preview_info:
            if custom_info is not None:
                self._data[title]["info"] = custom_info
            else:
                self._data[title]["info"] = None