File size: 875 Bytes
52dd1ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# src/inference/base_model.py
from abc import ABC, abstractmethod
from typing import Dict, Any
from PIL import Image

class BaseModel(ABC):
    """Common interface for all pet recognition models."""

    def __init__(self, name: str, labels: Dict[int, str]):
        self.name = name
        self.labels = labels

    @abstractmethod
    def preprocess(self, image: Image.Image) -> Any:
        """Convert PIL image → model input (tensor / numpy / feature vector)."""
        pass

    @abstractmethod
    def predict(self, image: Image.Image) -> Dict[str, Any]:
        """

        Run full pipeline: preprocess → forward pass → postprocess.



        Returns:

            {

              "class_id": int,

              "class_name": str,

              "probs": Dict[str, float],   # optional, top-k

            }

        """
        pass