Ejemplo n.º 1
0
    def convert(self):
        images_pathes = self._get_images_pathes()
        dataset_name = os.path.basename(os.path.normpath(self.dataset_dir))
        out_pr = ProjectStructure(self.settings['res_names']['project'])

        for image_fp in images_pathes:
            image_ext = os.path.splitext(image_fp)[1]
            image_name = os.path.splitext(image_fp)[0]
            dt = {"image_ext": image_ext}
            out_pr.add_item(dataset_name, image_name, dt)

        out_pr_fs = ProjectFS(self.out_dir, out_pr)
        out_pr_fs.make_dirs()

        res_meta = ProjectMeta()
        for class_name in self.classes:
            # TODO: Fix it line by new meta and object classes
            res_meta.classes.add({
                'title':
                class_name,
                'shape':
                'bitmap',
                'color':
                color_utils.rgb2hex(color_utils.random_rgb())
            })
        res_meta.to_dir(out_pr_fs.project_path)

        progress = progress_counter.progress_counter_import(
            out_pr.name, out_pr.image_cnt)
        for sample_info in out_pr_fs:
            self._convert_sample(sample_info, res_meta)
            progress.iter_done_report()
Ejemplo n.º 2
0
    def convert(self):
        images_pathes = self._get_images_pathes()
        masks_map = self._get_masks_mapping()
        dataset_name = 'ds'
        out_pr = ProjectStructure(self.settings['res_names']['project'])

        for image_fp in images_pathes:
            base_name = os.path.basename(image_fp)
            image_ext = os.path.splitext(image_fp)[1]
            image_id = os.path.splitext(base_name)[0]
            if base_name.replace(image_ext, '') in masks_map:
                dt = {"image_ext": ".png", "image_orig_path": image_fp}
                out_pr.add_item(dataset_name, image_id, dt)

        out_pr_fs = ProjectFS(self.out_dir, out_pr)
        out_pr_fs.make_dirs()

        res_meta = ProjectMeta()
        # TODO: Fix it line by new meta and object classes
        res_meta.classes.add({
            'title':
            'leaf',
            'shape':
            'bitmap',
            'color':
            color_utils.rgb2hex(color_utils.random_rgb())
        })
        res_meta.to_dir(out_pr_fs.project_path)

        progress = progress_counter.progress_counter_import(
            out_pr.name, out_pr.image_cnt)
        for sample_info in out_pr_fs:
            self._convert_sample(sample_info, masks_map, res_meta)
            progress.iter_done_report()
Ejemplo n.º 3
0
 def to_json(self):
     jdict = {
         TagMetaJsonFields.NAME: self.name,
         TagMetaJsonFields.VALUE_TYPE: self.value_type,
         TagMetaJsonFields.COLOR: rgb2hex(self.color)
     }
     if self.value_type == TagValueType.ONEOF_STRING:
         jdict[TagMetaJsonFields.VALUES] = self.possible_values
     return jdict
Ejemplo n.º 4
0
    def to_json(self):
        points_json = []
        for point in self.points:
            points_json.append({
                LABEL: point.label,
                COLOR: rgb2hex(point.color)
            })

        edges_json = []
        for edge in self.edges:
            edges_json.append({
                LABEL: edge.label,
                COLOR: rgb2hex(edge.color),
                POINTS: [edge.start, edge.end]
            })

        packed_obj = {POINTS: points_json, EDGES: edges_json}
        return packed_obj
Ejemplo n.º 5
0
    def to_json(self) -> dict:
        """
        Converts object to json serializable dictionary. See Supervisely Json format explanation here:
        https://docs.supervise.ly/ann_format/

        Returns:
            json serializable dictionary
        """
        return {ObjClassJsonFields.NAME: self.name,
                ObjClassJsonFields.GEOMETRY_TYPE: self.geometry_type.geometry_name(),
                ObjClassJsonFields.COLOR: rgb2hex(self.color)}
Ejemplo n.º 6
0
 def to_json(self):
     '''
     The function to_json convert TagMeta object to json format
     :return: tagmeta in json format
     '''
     jdict = {
         TagMetaJsonFields.NAME: self.name,
         TagMetaJsonFields.VALUE_TYPE: self.value_type,
         TagMetaJsonFields.COLOR: rgb2hex(self.color)
     }
     if self.value_type == TagValueType.ONEOF_STRING:
         jdict[TagMetaJsonFields.VALUES] = self.possible_values
     return jdict
Ejemplo n.º 7
0
    def validate_classes_colors(self, logger=None):
        # check colors uniq
        color_names = defaultdict(list)
        for obj_class in self:
            hex = rgb2hex(obj_class.color)
            color_names[hex].append(obj_class.name)

        class_colors_notify = None
        for hex_color, class_names in color_names.items():
            if len(class_names) > 1:
                warn_str = "Classes {!r} have the same RGB color = {!r}".format(class_names, hex2rgb(hex_color))
                if logger is not None:
                    logger.warn(warn_str)
                if class_colors_notify is None:
                    class_colors_notify = ""
                class_colors_notify += warn_str + '\n\n'
        return class_colors_notify
Ejemplo n.º 8
0
    def to_json(self) -> dict:
        """
        Converts object to json serializable dictionary. See Supervisely Json format explanation here:
        https://docs.supervise.ly/ann_format/

        Returns:
            json serializable dictionary
        """
        res = {
            ObjClassJsonFields.NAME: self.name,
            ObjClassJsonFields.GEOMETRY_TYPE: self.geometry_type.geometry_name(),
            ObjClassJsonFields.COLOR: rgb2hex(self.color),
            ObjClassJsonFields.GEOMETRY_CONFIG: self.geometry_type.config_to_json(self._geometry_config)
        }
        if self.sly_id is not None:
            res[ObjClassJsonFields.ID] = self.sly_id
        if self._hotkey is not None:
            res[ObjClassJsonFields.HOTKEY] = self.hotkey
        return res
Ejemplo n.º 9
0
    def validate_classes_colors(self, logger=None):
        # check colors uniq
        color_names = defaultdict(list)
        for obj_class in self:
            hex = rgb2hex(obj_class.color)
            color_names[hex].append(obj_class.name)

        class_colors_notify = None
        for hex_color, class_names in color_names.items():
            if len(class_names) > 1:
                warn_str = "Classes {!r} have the same RGB color = {!r}".format(
                    class_names, hex2rgb(hex_color))
                if logger is not None:
                    logger.warn(warn_str)
                if class_colors_notify is None:
                    class_colors_notify = ""
                class_colors_notify += warn_str + '\n\n'
        #if class_colors_notify != "":
        #    pass
        #    api.report.create_notification("Classes colors", class_colors_notify, sly.NotificationType.WARNING))
        return class_colors_notify
Ejemplo n.º 10
0
    def to_json(self):
        '''
        The function to_json convert TagMeta object to json format
        :return: tagmeta in json format
        '''
        jdict = {
            TagMetaJsonFields.NAME: self.name,
            TagMetaJsonFields.VALUE_TYPE: self.value_type,
            TagMetaJsonFields.COLOR: rgb2hex(self.color)
        }
        if self.value_type == TagValueType.ONEOF_STRING:
            jdict[TagMetaJsonFields.VALUES] = self.possible_values

        if self.sly_id is not None:
            jdict[TagMetaJsonFields.ID] = self.sly_id
        if self._hotkey is not None:
            jdict[TagMetaJsonFields.HOTKEY] = self.hotkey
        if self._applicable_to is not None:
            jdict[TagMetaJsonFields.APPLICABLE_TYPE] = self.applicable_to
        if self._applicable_classes is not None:
            jdict[
                TagMetaJsonFields.APPLICABLE_CLASSES] = self.applicable_classes

        return jdict