torch¶
torch ¶
Attributes¶
Classes¶
ClassificationMixin ¶
Shared classification preprocessing/postprocessing logic.
Attributes:
| Name | Type | Description |
|---|---|---|
image_size | tuple[int, int] | Target image size. |
mean | Tensor | Normalization mean. |
std | Tensor | Normalization std. |
class_names | dict[int, str] | Mapping from class ID to class name. |
transform | Compose | Image transformation pipeline. |
ClassificationPipeline ¶
ClassificationPipeline(runtime: Runtime[Tensor, Tensor], image_size: tuple[int, int] = (224, 224), mean: tuple[float, float, float] = (0.485, 0.456, 0.406), std: tuple[float, float, float] = (0.229, 0.224, 0.225), class_names: dict[int, str] | None = None, batch_strategy: BatchStrategy[Tensor, Tensor] | None = None)
Bases: ClassificationMixin, Pipeline[Tensor, Tensor, ClassificationOutput]
Image classification pipeline (sync version).
Performs
- Image decoding and conversion
- Resizing and normalization
- Model inference
- Class prediction with confidence
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runtime | Runtime[Tensor, Tensor] | Inference runtime. | required |
image_size | tuple[int, int] | Target image size (default: (224, 224)). | (224, 224) |
mean | tuple[float, float, float] | Normalization mean (default: ImageNet mean). | (0.485, 0.456, 0.406) |
std | tuple[float, float, float] | Normalization std (default: ImageNet std). | (0.229, 0.224, 0.225) |
class_names | dict[int, str] | None | Optional mapping from class ID to class name. | None |
batch_strategy | BatchStrategy[Tensor, Tensor] | None | Optional batching strategy. | None |
Example
Source code in inferflow/pipeline/classification/torch.py
Attributes¶
Functions¶
preprocess ¶
preprocess(input: ImageInput) -> Tensor
Preprocess image input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input | ImageInput | Raw image input (bytes, numpy array, PIL Image, or tensor). | required |
Returns:
| Type | Description |
|---|---|
Tensor | Preprocessed tensor ready for model inference. |
Source code in inferflow/pipeline/classification/torch.py
postprocess ¶
postprocess(raw: Tensor) -> ClassificationOutput
Postprocess model output to classification result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw | Tensor | Raw output tensor from model inference. | required |
Returns:
| Type | Description |
|---|---|
ClassificationOutput | ClassificationOutput with class ID, confidence, and optional class name. |