Architecture
A modular, secure design built for medical image segmentation with production deployment in mind.
U-Net Model Architecture
Encoder-Decoder with Skip Connections
- 1Input: RGB image [3, 256, 256]
- 2Encoder: 3-level downsampling with max pooling
- 3Bottleneck: Deep feature extraction at lowest resolution
- 4Decoder: 3-level upsampling with skip connections
- 5Output: Logits [1, 256, 256]
- 6Loss: BCE + 0.5 × Dice
Module Structure
model.pyU-Net architecture
data.pyDataset loading and augmentation
train.pyTraining and finetuning loops
losses.pyDice loss implementation
policy.py3-state decision logic and policy locking
eval.pyThreshold calibration and test bucketing
predict.pySingle-image and batch inference
gallery.pyTP/FN/FP/TN bucket visualization grids
export.pyONNX export with sigmoid wrapper and metadata
stats.pyWound metrics (area, perimeter, circularity, color)
viz.pyVisualization utilities
config.pyPath configuration and dataclasses
io.pySecure file I/O, path validation, checkpoint loading
validation.pyInput validation and sanitization
constants.pyApplication-wide constants and limits
log.pyCentralized logging configuration
cli.pyCommand-line interface
Security Features
Safe Model Loading
Uses weights_only=True (PyTorch 2.6+) to prevent arbitrary code execution from malicious checkpoint files.
Path Traversal Protection
All file paths are validated through validate_path() to prevent directory traversal attacks.
Input Validation
All user inputs (thresholds, sizes, learning rates, etc.) are validated with proper bounds checking.
Constants Module
Centralized constants with predefined limits (e.g., MAX_IMAGE_SIZE, MAX_EPOCHS).
Data Format
CSV Dataset Format
new_id
image_001
image_002
image_003
...
CSV files with new_id column mapping to image/mask filenames.
Directory Structure
project/
images/
image_001.png
image_002.png
masks/
image_001.png
image_002.png
dataset.csv