U-Net for Lung Segmentation (Model 3B – Hard Example Fine-Tuning)

This model performs lung segmentation on grayscale chest X-ray images using a custom deep learning architecture based on U-Net.
It integrates modern components like ASPP, Squeeze-and-Excitation (SE) blocks, and dilated residual convolutions to improve accuracy and generalization in complex medical imaging tasks.

This version (Model 3B) was fine-tuned specifically on hard examples, i.e., structurally difficult or degraded images with known weaknesses from earlier models.


πŸ”§ Architecture Overview

Base Architecture: Extended U-Net
Encoder: 6-level hierarchical encoder with:

  • Dilated residual blocks (multi-scale context, ResNet-style)
  • SE blocks (channel-wise attention)
  • MaxPooling2D at each stage

Bridge: ASPP module with dilation rates of 6, 12, 18 + Global Average Pooling

Decoder:

  • Upsampling layers with skip connections
  • Re-applied dilated residual blocks
  • Progressive channel reduction (1024 β†’ 32)

Output Layer:

  • Final 1Γ—1 Conv2D + Sigmoid
  • Binary mask with pixel values in [0, 1]

πŸ§ͺ Training Configuration

Component Setting
Optimizer Adam (lr = 1e-4)
Loss Function Combined Dice + Binary Crossentropy
Scheduler ReduceLROnPlateau (patience = 3)
Early Stopping Monitored on val_loss
Epochs (initial phase) 20
CLAHE Preprocessing Yes (local contrast enhancement)

🎯 Hard Example Fine-Tuning (Model 3B)

After baseline training, this model was further fine-tuned on a subset of 300 challenging samples, automatically selected based on their lowest Dice scores out of 21,165 predictions. These cases included:

  • Heavily rotated or skewed images
  • Very noisy or low-contrast scans
  • Fragmented lung regions and anatomical irregularities

Only model weights were updated – no changes were made to the architecture. Training was resumed using the saved model_3.h5.


πŸ“Š Results (Epoch 50)

Metric Value
Train Dice 0.9818
Train IoU 0.9643
Validation Dice 0.9594
Validation IoU 0.9226
Combined Loss 0.0590
Learning Rate (final) 2.5e-06

βœ… Performance Summary

  • Model demonstrates strong segmentation accuracy on complex or degraded images.
  • CLAHE preprocessing significantly improved edge detection and contrast in ambiguous regions.
  • Evaluation across full test set yielded:
    • Avg Dice Score: 0.9768
    • Avg IoU Score: 0.9551
    • Avg Combined Loss: 0.0649

πŸ” Usage

from huggingface_hub import hf_hub_download
import tensorflow as tf

# Download model file
model_path = hf_hub_download(repo_id="username/model-3b-lung-segmentation", filename="entwickeltes_masken_model.h5")

# Load model
model = tf.keras.models.load_model(model_path, compile=False)
model.compile(...)  # Add loss/metrics if needed
Downloads last month
5
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support