def __init__(self, config: dict, in_meta: ProjectMeta, model: SingleImageInferenceBase): super().__init__(config, in_meta, model) # If saving the bounding boxes on which inference was called is requested, create separate classes # for those bounding boxes by renaming the source object classes. self._renamer_intermediate = None if self._config[SAVE]: renamer_intermediate = Renamer( add_suffix=self._config[Renamer.ADD_SUFFIX], enabled_classes=self._config[FROM_CLASSES]) # First simply rename the matching source classes. intermediate_renamed_classes = make_renamed_classes( in_meta.obj_classes, renamer_intermediate, skip_missing=True) # Next, change the geometry type for the intermediate bounding box classes to Rectangle. intermediate_renamed_rectangle_classes = ObjClassCollection(items=[ renamed_class.clone(geometry_type=Rectangle) for renamed_class in intermediate_renamed_classes ]) # Add the renamed Rectangle classes to the output meta and set up a class mapper. self._out_meta = self._out_meta.add_obj_classes( intermediate_renamed_rectangle_classes) self._intermediate_class_mapper = RenamingObjClassMapper( dest_obj_classes=intermediate_renamed_rectangle_classes, renamer=renamer_intermediate)
def __init__(self, config: dict, in_meta: ProjectMeta, model: SingleImageInferenceBase): validation_schema_path = pkg_resources.resource_filename( __name__, 'inference_modes_schemas/{}.json'.format(self.mode_name())) MultiTypeValidator(validation_schema_path).val(INFERENCE_MODE_CONFIG, config) self._config = deepcopy(config) self._out_meta = in_meta self._model = model model_out_meta = self._model.model_out_meta # Renamer for model classes. renamer_model = Renamer.from_json(config.get(MODEL_CLASSES, {})) # Add all the applicable (passing the renamer filter) renamed model classes to the output meta. self._out_meta = self.out_meta.add_obj_classes( make_renamed_classes(model_out_meta.obj_classes, renamer_model, skip_missing=True)) # Make a class mapper to translate from model object space to output meta space. # TODO store the renamed model classes separately for the mapper instead of mixing in with the input annotation # classes. self._model_class_mapper = RenamingObjClassMapper(dest_obj_classes=self._out_meta.obj_classes, renamer=renamer_model) # Renamer for model tags. self._model_tags_renamer = Renamer.from_json(config.get(MODEL_TAGS, {})) # Rename the model output tags, set up a mapper and add them to the output meta. self._renamed_model_tags = make_renamed_tag_metas( model_out_meta.tag_metas, self._model_tags_renamer, skip_missing=True) self._model_tag_meta_mapper = RenamingTagMetaMapper(dest_tag_meta_dict=self._renamed_model_tags, renamer=self._model_tags_renamer) self._out_meta = self._out_meta.add_tag_metas(self._renamed_model_tags)
def __init__(self, config: dict, in_meta: ProjectMeta, model: SingleImageInferenceBase): super().__init__(config, in_meta, model) self._renamer_intermediate = None if self._config[SAVE]: renamer_intermediate = Renamer(add_suffix=self._config.get(Renamer.ADD_SUFFIX, ''), enabled_classes=self._config[FROM_CLASSES]) intermediate_renamed_classes = make_renamed_classes(in_meta.obj_classes, renamer_intermediate, skip_missing=True) for renamed_class in intermediate_renamed_classes: self._out_meta = self._out_meta.add_obj_class(renamed_class.clone(geometry_type=Rectangle)) self._intermediate_class_mapper = RenamingObjClassMapper(dest_obj_classes=self._out_meta.obj_classes, renamer=renamer_intermediate) self._out_meta = self._out_meta.add_obj_tag_metas(self._renamed_model_img_tags)
def __init__(self, config: dict, in_meta: ProjectMeta, model: SingleImageInferenceBase): validation_schema_path = pkg_resources.resource_filename( __name__, 'inference_modes_schemas/{}.json'.format(self.mode_name())) MultiTypeValidator(validation_schema_path).val(INFERENCE_MODE_CONFIG, config) self._config = deepcopy(config) self._out_meta = in_meta.clone() self._model = model model_out_meta = self._model.model_out_meta renamer_model = Renamer.from_json(config[MODEL_CLASSES]) for out_class in make_renamed_classes(model_out_meta.obj_classes, renamer_model, skip_missing=True): self._out_meta = self._out_meta.add_obj_class(out_class) self._model_class_mapper = RenamingObjClassMapper(dest_obj_classes=self._out_meta.obj_classes, renamer=renamer_model) self._model_img_tags_renamer = Renamer(add_suffix=config[MODEL_CLASSES][Renamer.ADD_SUFFIX]) self._renamed_model_img_tags = make_renamed_tag_metas(model_out_meta.img_tag_metas, self._model_img_tags_renamer, skip_missing=True) self._model_img_tag_meta_mapper = RenamingTagMetaMapper(dest_tag_meta_dict=self._renamed_model_img_tags, renamer=self._model_img_tags_renamer) self._out_meta = self._out_meta.merge(ProjectMeta(obj_tag_metas=model_out_meta.obj_tag_metas))