Beispiel #1
0
    def from_json(cls, data):
        '''
        The function from_json convert ProjectMeta from json format to ProjectMeta class object. Generate exception error if all project tags not in a single collection
        :param data: input ProjectMeta in json format
        :return: ProjectMeta class object
        '''
        tag_metas_json = data.get(ProjectMetaJsonFields.TAGS, [])
        img_tag_metas_json = data.get(ProjectMetaJsonFields.IMG_TAGS, [])
        obj_tag_metas_json = data.get(ProjectMetaJsonFields.OBJ_TAGS, [])
        project_type = data.get(ProjectMetaJsonFields.PROJECT_TYPE, None)

        if len(tag_metas_json) > 0:
            # New format - all project tags in a single collection.
            if any(len(x) > 0 for x in [img_tag_metas_json, obj_tag_metas_json]):
                raise ValueError(
                    'Project meta JSON contains both the {!r} section (current format merged tags for all of '
                    'the project) and {!r} or {!r} sections (legacy format with separate collections for images '
                    'and labeled objects). Either new format only or legacy format only are supported, but not a '
                    'mix.'.format(
                        ProjectMetaJsonFields.TAGS, ProjectMetaJsonFields.IMG_TAGS, ProjectMetaJsonFields.OBJ_TAGS))
            tag_metas = TagMetaCollection.from_json(tag_metas_json)
        else:
            img_tag_metas = TagMetaCollection.from_json(img_tag_metas_json)
            obj_tag_metas = TagMetaCollection.from_json(obj_tag_metas_json)
            tag_metas = _merge_img_obj_tag_metas(img_tag_metas, obj_tag_metas)

        return cls(obj_classes=ObjClassCollection.from_json(data[ProjectMetaJsonFields.OBJ_CLASSES]),
                   tag_metas=tag_metas, project_type=project_type)
Beispiel #2
0
 def _model_out_tags(self):
     temp_collection = TagMetaCollection.from_json(
         self.train_config[self.classification_tags_key])
     res_collection = TagMetaCollection([
         TagMeta(x.name, TagValueType.ANY_NUMBER) for x in temp_collection
     ])
     return res_collection
 def from_json(cls, data):
     return cls(
         ObjClassCollection.from_json(
             data[ProjectMetaJsonFields.OBJ_CLASSES]),
         TagMetaCollection.from_json(data[ProjectMetaJsonFields.IMG_TAGS]),
         TagMetaCollection.from_json(data[ProjectMetaJsonFields.OBJ_TAGS]))