Abstract interface for tissue segmentation models.
Defines the TissueMaskModel abstract base class used by tissue mask providers to process individual tile requests into binary segmentation masks.
TissueMaskModel
class TissueMaskModel(ABC)
Abstract interface for tissue segmentation models.
Accepts a batch of fixed-size RGB tiles and returns a batch of binary masks. GPU-backed models can process the whole batch at once; CPU-only models (like Otsu) can iterate internally.
The batch dimension is always the first axis:
- Input:
(B, H, W, 3) — uint8 RGB.
- Output:
(B, H, W) — uint8, values in {0, 1}.
Example class MyGPUModel(TissueMaskModel): def init(self, net): self.net = net
def process(self, batch): tensor = torch.from_numpy(batch).permute(0, 3, 1, 2).float() / 255 with torch.no_grad(): logits = self.net(tensor.cuda()) return (logits.squeeze(1).cpu().numpy() > 0.5).astype(np.uint8)
tile_spec
@property
@abstractmethod
def tile_spec() -> TileSpec | None
Returns the tile specification for this model, or None.
Subclasses must implement this property. Return None for models that operate on arbitrary tile sizes.
process
@abstractmethod
def process(request: ModelRequest) -> ModelResponse
Processes a single RGB tile into a binary mask.
Model request containing the RGB tile.
Model response containing the binary mask.