hugging_face_image_segmentation
Hugging Face Image Segmentation Algorithm.
Classes
HuggingFaceImageSegmentationInference
class HuggingFaceImageSegmentationInference( datastructure: DataStructure, model_id: str, alpha: float = 0.3, batch_size: int = 1, dataframe_output: bool = False, mask_threshold: float = 0.5, overlap_mask_area_threshold: float = 0.5, save_path: Union[str, os.PathLike] = PosixPath('.'), seed: int = 42, subtask: Optional[_Subtask] = None, threshold: float = 0.9,):Inference for pre-trained Hugging Face image segmentation models.
Perform segmentation (detect masks & classes) in the image(s) passed as inputs.
Arguments
- **
**kwargs**: Additional keyword arguments. alpha: the alpha for the mask overlay.batch_size: The batch size for inference. Defaults to 1.dataframe_output: Whether to output the prediction results in a dataframe format. Defaults toFalse.datastructure: The data structure to use for the algorithm.mask_threshold: Threshold to use when turning the predicted masks into binary values. Defaults to 0.5.model_id: The model id to use for image segmentation inference. The model id is of a pretrained model hosted inside a model repo on huggingface.co. Accepts resnet models.overlap_mask_area_threshold: Mask overlap threshold to eliminate small, disconnected segments. Defaults to 0.5.seed: Sets the seed of the algorithm. For reproducible behavior it defaults to 42.subtask: Segmentation task to be performed, choose [semantic,instanceandpanoptic] depending on model capabilities. If not set, the pipeline will attempt to resolve in the following order:panoptic,instance,semantic.threshold: Probability threshold to filter out predicted masks. Defaults to 0.9.
Attributes
alpha: the alpha for the mask overlay.batch_size: The batch size for inference. Defaults to 1.class_name: The name of the algorithm class.dataframe_output: Whether to output the prediction results in a dataframe format. Defaults toFalse.fields_dict: A dictionary mapping all attributes that will be serialized in the class to their marshmallow field type. (e.g. fields_dict ={"class_name": fields.Str()}).mask_threshold: Threshold to use when turning the predicted masks into binary values. Defaults to 0.5.model_id: The model id to use for image segmentation inference. The model id is of a pretrained model hosted inside a model repo on huggingface.co. Accepts resnet models.nested_fields: A dictionary mapping all nested attributes to a registry that contains class names mapped to the respective classes. (e.g. nested_fields ={"datastructure": datastructure.registry})overlap_mask_area_threshold: Mask overlap threshold to eliminate small, disconnected segments. Defaults to 0.5.seed: Sets the seed of the algorithm. For reproducible behavior it defaults to 42.subtask: Segmentation task to be performed, choose [semantic,instanceandpanoptic] depending on model capabilities. If not set, the pipeline will attempt to resolve in the following order:panoptic,instance,semantic.threshold: Probability threshold to filter out predicted masks. Defaults to 0.9.
Ancestors
- BaseNonModelAlgorithmFactory
- BaseAlgorithmFactory
- abc.ABC
- bitfount.federated.roles._RolesMixIn
- bitfount.types._BaseSerializableObjectMixIn
- typing.Generic
Variables
- static
fields_dict : ClassVar[dict[str, marshmallow.fields.Field]]
Methods
create
def create(self, role: Union[str, Role], **kwargs: Any) ‑> Any:Create an instance representing the role specified.
modeller
def modeller( self, *, context: ProtocolContext, **kwargs: Any,) ‑> bitfount.federated.algorithms.hugging_face_algorithms.base._HFModellerSide:Returns the modeller side of the HuggingFaceImageSegmentationInference algorithm.
worker
def worker( self, *, context: ProtocolContext, **kwargs: Any,) ‑> bitfount.federated.algorithms.hugging_face_algorithms.hugging_face_image_segmentation._WorkerSide:Returns the worker side of the HuggingFaceImageSegmentationInference algorithm.