hugging_face_zero_shot_image_classification
Hugging Face Zero-Shot Image Classification Algorithm.
Classes
HuggingFaceZeroShotImageClassificationInference
class HuggingFaceZeroShotImageClassificationInference( model_id: str, image_column_name: str, candidate_labels: List[str], batch_size: int = 1, class_outputs: Optional[List[str]] = None, hypothesis_template: Optional[str] = None, seed: int = 42,):
Inference for pre-trained Hugging Face zero shot image classification models.
Arguments
batch_size
: The batch size for inference. Defaults to 1.candidate_labels
: The candidate labels for this image.class_outputs
: A list of strings corresponding to prediction outputs. If provided, the model will return a dataframe of results with the class outputs list elements as columns. Defaults to None.hypothesis_template
: The sentence used in conjunction with candidate_labels to attempt the image classification by replacing the placeholder with the candidate_labels. Then likelihood is estimated by using logits_per_image. Defaults to None.image_column_name
: The image column on which the inference should be done.model_id
: The model id to use for zero shot image classification inference. The model id is of a pretrained model hosted inside a model repo on huggingface.co.seed
: Sets the seed of the algorithm. For reproducible behavior it defaults to 42.
Attributes
batch_size
: The batch size for inference. Defaults to 1.candidate_labels
: The candidate labels for this image.class_name
: The name of the algorithm class.class_outputs
: A list of strings corresponding to prediction outputs. If provided, the model will return a dataframe of results with the class outputs list elements as columns. Defaults to None.fields_dict
: A dictionary mapping all attributes that will be serialized in the class to their marshamllow field type. (e.g. fields_dict ={"class_name": fields.Str()}
).hypothesis_template
: The sentence used in conjunction with candidate_labels to attempt the image classification by replacing the placeholder with the candidate_labels. Then likelihood is estimated by using logits_per_image. Defaults to None.image_column_name
: The image column on which the inference should be done.model_id
: The model id to use for zero shot image classification inference. The model id is of a pretrained model hosted inside a model repo on huggingface.co.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}
)seed
: Sets the seed of the algorithm. For reproducible behavior it defaults to 42.
Ancestors
- BaseAlgorithmFactory
- abc.ABC
- bitfount.federated.roles._RolesMixIn
- bitfount.types._BaseSerializableObjectMixIn
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, **kwargs: Any,) ‑> bitfount.federated.algorithms.hugging_face_algorithms.hugging_face_zero_shot_image_classification._ModellerSide:
Returns the modeller side of the HuggingFaceZeroShotImageClassificationInference algorithm.
worker
def worker( self, **kwargs: Any,) ‑> bitfount.federated.algorithms.hugging_face_algorithms.hugging_face_zero_shot_image_classification._WorkerSide:
Returns the worker side of the HuggingFaceZeroShotImageClassificationInference algorithm.