from pydantic import BaseModel, Field, field_validator
from pathlib import Path
from enum import Enum
TYPE_NUCLEI_DICT = {
1: "Neoplastic",
2: "Inflammatory",
3: "Connective",
4: "Dead",
5: "Epithelial",
}
class ModelType(str, Enum):
cellvit = "cellvit"
hovernet = "hovernet"
cellpose_sam = "cellpose_sam"
@classmethod
def values(cls):
return [member.value for member in cls]
def __str__(self):
return self.value
[docs]class CellSegmenterConfig(BaseModel):
"""Configuration for data preparation"""
model: ModelType = Field(..., description="Name of the cell segmentation model to use")
gpu: int = Field(0, description="GPU device ID to use for processing")
wsi_path: Path = Field(..., description="Path to the whole slide image")
patched_slide_path: Path = Field(..., description="Path to the patched slide data generated by patch extraction")
[docs] @field_validator('model')
def validate_model(cls, v: str) -> str:
if v not in ModelType.values():
raise ValueError(f"Unsupported model type: {v}. Supported models are: {ModelType.values()}")
return v
[docs] class Config:
arbitrary_types_allowed = True