2025-12-05 09:50:50 +02:00
|
|
|
"""
|
|
|
|
|
Data models for the microscopy object detection application.
|
|
|
|
|
These dataclasses represent the database entities.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
from datetime import datetime
|
2025-12-05 15:51:16 +02:00
|
|
|
from typing import Optional, Dict, Tuple, List
|
2025-12-05 09:50:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
|
class Model:
|
|
|
|
|
"""Represents a trained model."""
|
|
|
|
|
|
|
|
|
|
id: Optional[int]
|
|
|
|
|
model_name: str
|
|
|
|
|
model_version: str
|
|
|
|
|
model_path: str
|
|
|
|
|
base_model: str
|
|
|
|
|
created_at: datetime
|
|
|
|
|
training_params: Optional[Dict]
|
|
|
|
|
metrics: Optional[Dict]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
|
class Image:
|
|
|
|
|
"""Represents an image in the database."""
|
|
|
|
|
|
|
|
|
|
id: Optional[int]
|
|
|
|
|
relative_path: str
|
|
|
|
|
filename: str
|
|
|
|
|
width: int
|
|
|
|
|
height: int
|
|
|
|
|
captured_at: Optional[datetime]
|
|
|
|
|
added_at: datetime
|
|
|
|
|
checksum: Optional[str]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
|
class Detection:
|
|
|
|
|
"""Represents a detection result."""
|
|
|
|
|
|
|
|
|
|
id: Optional[int]
|
|
|
|
|
image_id: int
|
|
|
|
|
model_id: int
|
|
|
|
|
class_name: str
|
|
|
|
|
bbox: Tuple[float, float, float, float] # (x_min, y_min, x_max, y_max)
|
|
|
|
|
confidence: float
|
2025-12-05 15:51:16 +02:00
|
|
|
segmentation_mask: Optional[
|
|
|
|
|
List[List[float]]
|
|
|
|
|
] # List of polygon coordinates [[x1,y1], [x2,y2], ...]
|
2025-12-05 09:50:50 +02:00
|
|
|
detected_at: datetime
|
|
|
|
|
metadata: Optional[Dict]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
|
class Annotation:
|
|
|
|
|
"""Represents a manual annotation."""
|
|
|
|
|
|
|
|
|
|
id: Optional[int]
|
|
|
|
|
image_id: int
|
|
|
|
|
class_name: str
|
|
|
|
|
bbox: Tuple[float, float, float, float] # (x_min, y_min, x_max, y_max)
|
2025-12-05 15:51:16 +02:00
|
|
|
segmentation_mask: Optional[
|
|
|
|
|
List[List[float]]
|
|
|
|
|
] # List of polygon coordinates [[x1,y1], [x2,y2], ...]
|
2025-12-05 09:50:50 +02:00
|
|
|
annotator: str
|
|
|
|
|
created_at: datetime
|
|
|
|
|
verified: bool
|