mindformers.pipeline.ImageClassificationPipeline¶
- class mindformers.pipeline.ImageClassificationPipeline(model: Union[str, BaseModel, Model], image_processor: Optional[BaseImageProcessor] = None, **kwargs)[源代码]¶
Pipeline for image classification
- Args:
- model (Union[str, BaseModel]): The model used to perform task,
the input could be a supported model name, or a model instance inherited from BaseModel.
- image_processor (Optional[BaseImageProcessor]): The image_processor of model,
it could be None if the model do not need image_processor.
- Raises:
TypeError: If input model and image_processor’s types are not corrected. ValueError: If the input model is not in support list.
- Examples:
>>> import numpy as np >>> from mindformers.pipeline import ImageClassificationPipeline >>> from mindformers import ViTImageProcessor >>> processor = ViTImageProcessor(size=224) >>> classifier = ImageClassificationPipeline( ... model='vit_base_p16', ... image_processor=processor, ... top_k=5 ... ) >>> classifier(np.uint8(np.random.random((5, 3, 255, 255)))) [[{'score': 0.0016654134, 'label': 'matchstick'}, {'score': 0.0015071577, 'label': 'theater curtain'}, {'score': 0.0014839625, 'label': 'ocarina'}, {'score': 0.0014319294, 'label': 'abaya'}, {'score': 0.0014109017, 'label': 'bottlecap'}], ..., {'score': 0.0014109018, 'label': 'bottlecap'}]]
- forward(model_inputs: dict, **forward_params)[源代码]¶
The Forward Process of Model
- Args:
model_inputs (dict): The output of preprocess. forward_params (dict): The parameter dict for model forward.