Spaces:
Sleeping
Sleeping
GitHub Actions
commited on
Commit
·
e5cff8a
1
Parent(s):
af59988
Auto-deploy from GitHub: 72cccbee3dae4c70208de787ce5200a2489a645b
Browse files- src/config.py +2 -24
src/config.py
CHANGED
|
@@ -5,9 +5,8 @@ All hyperparameters and paths are defined here for easy modification.
|
|
| 5 |
|
| 6 |
from pathlib import Path
|
| 7 |
|
| 8 |
-
|
| 9 |
# Project Paths
|
| 10 |
-
# =============================================================================
|
| 11 |
PROJECT_ROOT = Path(__file__).parent.parent
|
| 12 |
DATA_DIR = PROJECT_ROOT / "data" / "raw"
|
| 13 |
PROCESSED_DIR = PROJECT_ROOT / "data" / "processed"
|
|
@@ -16,9 +15,8 @@ OUTPUT_DIR = PROJECT_ROOT / "outputs"
|
|
| 16 |
FIGURES_DIR = OUTPUT_DIR / "figures"
|
| 17 |
LOGS_DIR = OUTPUT_DIR / "logs"
|
| 18 |
|
| 19 |
-
|
| 20 |
# Data Configuration
|
| 21 |
-
# =============================================================================
|
| 22 |
IMAGE_SIZE = 224 # EfficientNet-B0 input size
|
| 23 |
BATCH_SIZE = 32
|
| 24 |
NUM_WORKERS = 4 # DataLoader workers
|
|
@@ -31,68 +29,48 @@ IMAGENET_STD = [0.229, 0.224, 0.225]
|
|
| 31 |
CLASS_NAMES = ["NORMAL", "PNEUMONIA"]
|
| 32 |
NUM_CLASSES = 1 # Binary classification with sigmoid
|
| 33 |
|
| 34 |
-
# =============================================================================
|
| 35 |
# Model Configuration
|
| 36 |
-
# =============================================================================
|
| 37 |
MODEL_NAME = "efficientnet_b0"
|
| 38 |
DROPOUT_RATE = 0.3
|
| 39 |
PRETRAINED = True
|
| 40 |
|
| 41 |
-
# =============================================================================
|
| 42 |
# Training Configuration - Stage 1 (Frozen Backbone)
|
| 43 |
-
# =============================================================================
|
| 44 |
STAGE1_EPOCHS = 5
|
| 45 |
STAGE1_LR = 1e-4
|
| 46 |
STAGE1_FREEZE_BACKBONE = True
|
| 47 |
|
| 48 |
-
# =============================================================================
|
| 49 |
# Training Configuration - Stage 2 (Fine-tuning)
|
| 50 |
-
# =============================================================================
|
| 51 |
STAGE2_EPOCHS = 15
|
| 52 |
STAGE2_LR = 1e-5
|
| 53 |
STAGE2_FREEZE_BACKBONE = False
|
| 54 |
|
| 55 |
-
# =============================================================================
|
| 56 |
# Optimizer Configuration
|
| 57 |
-
# =============================================================================
|
| 58 |
WEIGHT_DECAY = 1e-4
|
| 59 |
BETAS = (0.9, 0.999)
|
| 60 |
|
| 61 |
-
# =============================================================================
|
| 62 |
# Scheduler Configuration
|
| 63 |
-
# =============================================================================
|
| 64 |
SCHEDULER_PATIENCE = 3
|
| 65 |
SCHEDULER_FACTOR = 0.5
|
| 66 |
SCHEDULER_MIN_LR = 1e-7
|
| 67 |
|
| 68 |
-
# =============================================================================
|
| 69 |
# Early Stopping Configuration
|
| 70 |
-
# =============================================================================
|
| 71 |
EARLY_STOP_PATIENCE = 7
|
| 72 |
EARLY_STOP_MIN_DELTA = 0.001
|
| 73 |
|
| 74 |
-
# =============================================================================
|
| 75 |
# Model Checkpointing
|
| 76 |
-
# =============================================================================
|
| 77 |
CHECKPOINT_PATH = MODEL_DIR / "best_model.pt"
|
| 78 |
SAVE_BEST_ONLY = True
|
| 79 |
MONITOR_METRIC = "val_loss"
|
| 80 |
|
| 81 |
-
# =============================================================================
|
| 82 |
# Weights & Biases Configuration
|
| 83 |
-
# =============================================================================
|
| 84 |
WANDB_PROJECT = "pneumonia-detection"
|
| 85 |
WANDB_ENTITY = None # Set to your W&B username if needed
|
| 86 |
|
| 87 |
-
# =============================================================================
|
| 88 |
# Inference Configuration
|
| 89 |
-
# =============================================================================
|
| 90 |
CONFIDENCE_THRESHOLD = 0.5 # For binary classification
|
| 91 |
GRADCAM_TARGET_LAYER = "features" # EfficientNet feature extractor
|
| 92 |
|
| 93 |
-
# =============================================================================
|
| 94 |
# Random Seed (for reproducibility)
|
| 95 |
-
# =============================================================================
|
| 96 |
SEED = 42
|
| 97 |
|
| 98 |
|
|
|
|
| 5 |
|
| 6 |
from pathlib import Path
|
| 7 |
|
| 8 |
+
|
| 9 |
# Project Paths
|
|
|
|
| 10 |
PROJECT_ROOT = Path(__file__).parent.parent
|
| 11 |
DATA_DIR = PROJECT_ROOT / "data" / "raw"
|
| 12 |
PROCESSED_DIR = PROJECT_ROOT / "data" / "processed"
|
|
|
|
| 15 |
FIGURES_DIR = OUTPUT_DIR / "figures"
|
| 16 |
LOGS_DIR = OUTPUT_DIR / "logs"
|
| 17 |
|
| 18 |
+
|
| 19 |
# Data Configuration
|
|
|
|
| 20 |
IMAGE_SIZE = 224 # EfficientNet-B0 input size
|
| 21 |
BATCH_SIZE = 32
|
| 22 |
NUM_WORKERS = 4 # DataLoader workers
|
|
|
|
| 29 |
CLASS_NAMES = ["NORMAL", "PNEUMONIA"]
|
| 30 |
NUM_CLASSES = 1 # Binary classification with sigmoid
|
| 31 |
|
|
|
|
| 32 |
# Model Configuration
|
|
|
|
| 33 |
MODEL_NAME = "efficientnet_b0"
|
| 34 |
DROPOUT_RATE = 0.3
|
| 35 |
PRETRAINED = True
|
| 36 |
|
|
|
|
| 37 |
# Training Configuration - Stage 1 (Frozen Backbone)
|
|
|
|
| 38 |
STAGE1_EPOCHS = 5
|
| 39 |
STAGE1_LR = 1e-4
|
| 40 |
STAGE1_FREEZE_BACKBONE = True
|
| 41 |
|
|
|
|
| 42 |
# Training Configuration - Stage 2 (Fine-tuning)
|
|
|
|
| 43 |
STAGE2_EPOCHS = 15
|
| 44 |
STAGE2_LR = 1e-5
|
| 45 |
STAGE2_FREEZE_BACKBONE = False
|
| 46 |
|
|
|
|
| 47 |
# Optimizer Configuration
|
|
|
|
| 48 |
WEIGHT_DECAY = 1e-4
|
| 49 |
BETAS = (0.9, 0.999)
|
| 50 |
|
|
|
|
| 51 |
# Scheduler Configuration
|
|
|
|
| 52 |
SCHEDULER_PATIENCE = 3
|
| 53 |
SCHEDULER_FACTOR = 0.5
|
| 54 |
SCHEDULER_MIN_LR = 1e-7
|
| 55 |
|
|
|
|
| 56 |
# Early Stopping Configuration
|
|
|
|
| 57 |
EARLY_STOP_PATIENCE = 7
|
| 58 |
EARLY_STOP_MIN_DELTA = 0.001
|
| 59 |
|
|
|
|
| 60 |
# Model Checkpointing
|
|
|
|
| 61 |
CHECKPOINT_PATH = MODEL_DIR / "best_model.pt"
|
| 62 |
SAVE_BEST_ONLY = True
|
| 63 |
MONITOR_METRIC = "val_loss"
|
| 64 |
|
|
|
|
| 65 |
# Weights & Biases Configuration
|
|
|
|
| 66 |
WANDB_PROJECT = "pneumonia-detection"
|
| 67 |
WANDB_ENTITY = None # Set to your W&B username if needed
|
| 68 |
|
|
|
|
| 69 |
# Inference Configuration
|
|
|
|
| 70 |
CONFIDENCE_THRESHOLD = 0.5 # For binary classification
|
| 71 |
GRADCAM_TARGET_LAYER = "features" # EfficientNet feature extractor
|
| 72 |
|
|
|
|
| 73 |
# Random Seed (for reproducibility)
|
|
|
|
| 74 |
SEED = 42
|
| 75 |
|
| 76 |
|