Update: fix mask passing in validation, add MedicalVisualizationCallback, optimize for 2xH800
Browse files- code/configs_medical/PixelGen_Medical_CVC_B16_CrossAttn.yaml +10 -2
- code/configs_medical/PixelGen_Medical_CVC_B8_Spatial.yaml +10 -2
- code/configs_medical/PixelGen_Medical_CVC_S8_Spatial.yaml +10 -2
- code/configs_medical/PixelGen_Medical_Kvasir_B16_CrossAttn.yaml +10 -2
- code/configs_medical/PixelGen_Medical_Kvasir_B8_Spatial.yaml +10 -2
- code/configs_medical/PixelGen_Medical_Kvasir_S8_Spatial.yaml +10 -2
- code/configs_medical/PixelGen_Medical_OCTA500_B16_CrossAttn.yaml +9 -1
- code/configs_medical/PixelGen_Medical_OCTA500_L16_Global.yaml +10 -2
- code/configs_medical/PixelGen_Medical_OCTA500_XL16_Global.yaml +10 -2
- code/configs_medical/PixelGen_Medical_REFUGE2_B16_CrossAttn.yaml +10 -2
- code/configs_medical/PixelGen_Medical_REFUGE2_B8_Spatial.yaml +10 -2
- code/configs_medical/PixelGen_Medical_REFUGE2_S8_Spatial.yaml +10 -2
- code/run_ablation.sh +36 -30
- code/src/callbacks/medical_visualization.py +190 -0
- code/src/diffusion/base/sampling.py +2 -2
- code/src/lightning_model.py +13 -2
code/configs_medical/PixelGen_Medical_CVC_B16_CrossAttn.yaml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# PixelGen Medical - CVC-ClinicDB Polyp Segmentation - Binary mask-conditional colonoscopy image generation
|
| 2 |
# Model: JiTMedical-B/16, mask_mode=cross_attention
|
|
|
|
| 3 |
seed_everything: 1234
|
| 4 |
tags:
|
| 5 |
exp: &exp PixelGen_Medical_CVC_B16_CrossAttn
|
|
@@ -34,6 +35,13 @@ trainer:
|
|
| 34 |
init_args:
|
| 35 |
save_dir: val_samples
|
| 36 |
save_compressed: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
plugins:
|
| 38 |
- src.plugins.bd_env.BDEnvironment
|
| 39 |
|
|
@@ -123,7 +131,7 @@ data:
|
|
| 123 |
resolution: 256
|
| 124 |
max_num_instances: 612
|
| 125 |
noise_scale: 1.0
|
| 126 |
-
train_batch_size:
|
| 127 |
train_num_workers: 4
|
| 128 |
-
pred_batch_size:
|
| 129 |
pred_num_workers: 1
|
|
|
|
| 1 |
# PixelGen Medical - CVC-ClinicDB Polyp Segmentation - Binary mask-conditional colonoscopy image generation
|
| 2 |
# Model: JiTMedical-B/16, mask_mode=cross_attention
|
| 3 |
+
# Optimized for 2x H800 80GB
|
| 4 |
seed_everything: 1234
|
| 5 |
tags:
|
| 6 |
exp: &exp PixelGen_Medical_CVC_B16_CrossAttn
|
|
|
|
| 35 |
init_args:
|
| 36 |
save_dir: val_samples
|
| 37 |
save_compressed: true
|
| 38 |
+
- class_path: src.callbacks.medical_visualization.MedicalVisualizationCallback
|
| 39 |
+
init_args:
|
| 40 |
+
every_n_steps: 5000
|
| 41 |
+
num_samples: 8
|
| 42 |
+
num_sampling_steps: 50
|
| 43 |
+
cfg_scale: 2.0
|
| 44 |
+
save_dir: training_vis
|
| 45 |
plugins:
|
| 46 |
- src.plugins.bd_env.BDEnvironment
|
| 47 |
|
|
|
|
| 131 |
resolution: 256
|
| 132 |
max_num_instances: 612
|
| 133 |
noise_scale: 1.0
|
| 134 |
+
train_batch_size: 96
|
| 135 |
train_num_workers: 4
|
| 136 |
+
pred_batch_size: 32
|
| 137 |
pred_num_workers: 1
|
code/configs_medical/PixelGen_Medical_CVC_B8_Spatial.yaml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# PixelGen Medical - CVC-ClinicDB Polyp Segmentation - Binary mask-conditional colonoscopy image generation
|
| 2 |
# Model: JiTMedical-B/8, mask_mode=spatial
|
|
|
|
| 3 |
seed_everything: 1234
|
| 4 |
tags:
|
| 5 |
exp: &exp PixelGen_Medical_CVC_B8_Spatial
|
|
@@ -34,6 +35,13 @@ trainer:
|
|
| 34 |
init_args:
|
| 35 |
save_dir: val_samples
|
| 36 |
save_compressed: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
plugins:
|
| 38 |
- src.plugins.bd_env.BDEnvironment
|
| 39 |
|
|
@@ -123,7 +131,7 @@ data:
|
|
| 123 |
resolution: 256
|
| 124 |
max_num_instances: 612
|
| 125 |
noise_scale: 1.0
|
| 126 |
-
train_batch_size:
|
| 127 |
train_num_workers: 4
|
| 128 |
-
pred_batch_size:
|
| 129 |
pred_num_workers: 1
|
|
|
|
| 1 |
# PixelGen Medical - CVC-ClinicDB Polyp Segmentation - Binary mask-conditional colonoscopy image generation
|
| 2 |
# Model: JiTMedical-B/8, mask_mode=spatial
|
| 3 |
+
# Optimized for 2x H800 80GB
|
| 4 |
seed_everything: 1234
|
| 5 |
tags:
|
| 6 |
exp: &exp PixelGen_Medical_CVC_B8_Spatial
|
|
|
|
| 35 |
init_args:
|
| 36 |
save_dir: val_samples
|
| 37 |
save_compressed: true
|
| 38 |
+
- class_path: src.callbacks.medical_visualization.MedicalVisualizationCallback
|
| 39 |
+
init_args:
|
| 40 |
+
every_n_steps: 5000
|
| 41 |
+
num_samples: 8
|
| 42 |
+
num_sampling_steps: 50
|
| 43 |
+
cfg_scale: 2.0
|
| 44 |
+
save_dir: training_vis
|
| 45 |
plugins:
|
| 46 |
- src.plugins.bd_env.BDEnvironment
|
| 47 |
|
|
|
|
| 131 |
resolution: 256
|
| 132 |
max_num_instances: 612
|
| 133 |
noise_scale: 1.0
|
| 134 |
+
train_batch_size: 32
|
| 135 |
train_num_workers: 4
|
| 136 |
+
pred_batch_size: 32
|
| 137 |
pred_num_workers: 1
|
code/configs_medical/PixelGen_Medical_CVC_S8_Spatial.yaml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# PixelGen Medical - CVC-ClinicDB Polyp Segmentation - Binary mask-conditional colonoscopy image generation
|
| 2 |
# Model: JiTMedical-S/8, mask_mode=spatial
|
|
|
|
| 3 |
seed_everything: 1234
|
| 4 |
tags:
|
| 5 |
exp: &exp PixelGen_Medical_CVC_S8_Spatial
|
|
@@ -34,6 +35,13 @@ trainer:
|
|
| 34 |
init_args:
|
| 35 |
save_dir: val_samples
|
| 36 |
save_compressed: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
plugins:
|
| 38 |
- src.plugins.bd_env.BDEnvironment
|
| 39 |
|
|
@@ -123,7 +131,7 @@ data:
|
|
| 123 |
resolution: 256
|
| 124 |
max_num_instances: 612
|
| 125 |
noise_scale: 1.0
|
| 126 |
-
train_batch_size:
|
| 127 |
train_num_workers: 4
|
| 128 |
-
pred_batch_size:
|
| 129 |
pred_num_workers: 1
|
|
|
|
| 1 |
# PixelGen Medical - CVC-ClinicDB Polyp Segmentation - Binary mask-conditional colonoscopy image generation
|
| 2 |
# Model: JiTMedical-S/8, mask_mode=spatial
|
| 3 |
+
# Optimized for 2x H800 80GB
|
| 4 |
seed_everything: 1234
|
| 5 |
tags:
|
| 6 |
exp: &exp PixelGen_Medical_CVC_S8_Spatial
|
|
|
|
| 35 |
init_args:
|
| 36 |
save_dir: val_samples
|
| 37 |
save_compressed: true
|
| 38 |
+
- class_path: src.callbacks.medical_visualization.MedicalVisualizationCallback
|
| 39 |
+
init_args:
|
| 40 |
+
every_n_steps: 5000
|
| 41 |
+
num_samples: 8
|
| 42 |
+
num_sampling_steps: 50
|
| 43 |
+
cfg_scale: 2.0
|
| 44 |
+
save_dir: training_vis
|
| 45 |
plugins:
|
| 46 |
- src.plugins.bd_env.BDEnvironment
|
| 47 |
|
|
|
|
| 131 |
resolution: 256
|
| 132 |
max_num_instances: 612
|
| 133 |
noise_scale: 1.0
|
| 134 |
+
train_batch_size: 64
|
| 135 |
train_num_workers: 4
|
| 136 |
+
pred_batch_size: 32
|
| 137 |
pred_num_workers: 1
|
code/configs_medical/PixelGen_Medical_Kvasir_B16_CrossAttn.yaml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# PixelGen Medical - Kvasir-SEG Polyp Segmentation - Binary mask-conditional colonoscopy image generation
|
| 2 |
# Model: JiTMedical-B/16, mask_mode=cross_attention
|
|
|
|
| 3 |
seed_everything: 1234
|
| 4 |
tags:
|
| 5 |
exp: &exp PixelGen_Medical_Kvasir_B16_CrossAttn
|
|
@@ -34,6 +35,13 @@ trainer:
|
|
| 34 |
init_args:
|
| 35 |
save_dir: val_samples
|
| 36 |
save_compressed: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
plugins:
|
| 38 |
- src.plugins.bd_env.BDEnvironment
|
| 39 |
|
|
@@ -123,7 +131,7 @@ data:
|
|
| 123 |
resolution: 256
|
| 124 |
max_num_instances: 1000
|
| 125 |
noise_scale: 1.0
|
| 126 |
-
train_batch_size:
|
| 127 |
train_num_workers: 4
|
| 128 |
-
pred_batch_size:
|
| 129 |
pred_num_workers: 1
|
|
|
|
| 1 |
# PixelGen Medical - Kvasir-SEG Polyp Segmentation - Binary mask-conditional colonoscopy image generation
|
| 2 |
# Model: JiTMedical-B/16, mask_mode=cross_attention
|
| 3 |
+
# Optimized for 2x H800 80GB
|
| 4 |
seed_everything: 1234
|
| 5 |
tags:
|
| 6 |
exp: &exp PixelGen_Medical_Kvasir_B16_CrossAttn
|
|
|
|
| 35 |
init_args:
|
| 36 |
save_dir: val_samples
|
| 37 |
save_compressed: true
|
| 38 |
+
- class_path: src.callbacks.medical_visualization.MedicalVisualizationCallback
|
| 39 |
+
init_args:
|
| 40 |
+
every_n_steps: 5000
|
| 41 |
+
num_samples: 8
|
| 42 |
+
num_sampling_steps: 50
|
| 43 |
+
cfg_scale: 2.0
|
| 44 |
+
save_dir: training_vis
|
| 45 |
plugins:
|
| 46 |
- src.plugins.bd_env.BDEnvironment
|
| 47 |
|
|
|
|
| 131 |
resolution: 256
|
| 132 |
max_num_instances: 1000
|
| 133 |
noise_scale: 1.0
|
| 134 |
+
train_batch_size: 96
|
| 135 |
train_num_workers: 4
|
| 136 |
+
pred_batch_size: 32
|
| 137 |
pred_num_workers: 1
|
code/configs_medical/PixelGen_Medical_Kvasir_B8_Spatial.yaml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# PixelGen Medical - Kvasir-SEG Polyp Segmentation - Binary mask-conditional colonoscopy image generation
|
| 2 |
# Model: JiTMedical-B/8, mask_mode=spatial
|
|
|
|
| 3 |
seed_everything: 1234
|
| 4 |
tags:
|
| 5 |
exp: &exp PixelGen_Medical_Kvasir_B8_Spatial
|
|
@@ -34,6 +35,13 @@ trainer:
|
|
| 34 |
init_args:
|
| 35 |
save_dir: val_samples
|
| 36 |
save_compressed: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
plugins:
|
| 38 |
- src.plugins.bd_env.BDEnvironment
|
| 39 |
|
|
@@ -123,7 +131,7 @@ data:
|
|
| 123 |
resolution: 256
|
| 124 |
max_num_instances: 1000
|
| 125 |
noise_scale: 1.0
|
| 126 |
-
train_batch_size:
|
| 127 |
train_num_workers: 4
|
| 128 |
-
pred_batch_size:
|
| 129 |
pred_num_workers: 1
|
|
|
|
| 1 |
# PixelGen Medical - Kvasir-SEG Polyp Segmentation - Binary mask-conditional colonoscopy image generation
|
| 2 |
# Model: JiTMedical-B/8, mask_mode=spatial
|
| 3 |
+
# Optimized for 2x H800 80GB
|
| 4 |
seed_everything: 1234
|
| 5 |
tags:
|
| 6 |
exp: &exp PixelGen_Medical_Kvasir_B8_Spatial
|
|
|
|
| 35 |
init_args:
|
| 36 |
save_dir: val_samples
|
| 37 |
save_compressed: true
|
| 38 |
+
- class_path: src.callbacks.medical_visualization.MedicalVisualizationCallback
|
| 39 |
+
init_args:
|
| 40 |
+
every_n_steps: 5000
|
| 41 |
+
num_samples: 8
|
| 42 |
+
num_sampling_steps: 50
|
| 43 |
+
cfg_scale: 2.0
|
| 44 |
+
save_dir: training_vis
|
| 45 |
plugins:
|
| 46 |
- src.plugins.bd_env.BDEnvironment
|
| 47 |
|
|
|
|
| 131 |
resolution: 256
|
| 132 |
max_num_instances: 1000
|
| 133 |
noise_scale: 1.0
|
| 134 |
+
train_batch_size: 32
|
| 135 |
train_num_workers: 4
|
| 136 |
+
pred_batch_size: 32
|
| 137 |
pred_num_workers: 1
|
code/configs_medical/PixelGen_Medical_Kvasir_S8_Spatial.yaml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# PixelGen Medical - Kvasir-SEG Polyp Segmentation - Binary mask-conditional colonoscopy image generation
|
| 2 |
# Model: JiTMedical-S/8, mask_mode=spatial
|
|
|
|
| 3 |
seed_everything: 1234
|
| 4 |
tags:
|
| 5 |
exp: &exp PixelGen_Medical_Kvasir_S8_Spatial
|
|
@@ -34,6 +35,13 @@ trainer:
|
|
| 34 |
init_args:
|
| 35 |
save_dir: val_samples
|
| 36 |
save_compressed: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
plugins:
|
| 38 |
- src.plugins.bd_env.BDEnvironment
|
| 39 |
|
|
@@ -123,7 +131,7 @@ data:
|
|
| 123 |
resolution: 256
|
| 124 |
max_num_instances: 1000
|
| 125 |
noise_scale: 1.0
|
| 126 |
-
train_batch_size:
|
| 127 |
train_num_workers: 4
|
| 128 |
-
pred_batch_size:
|
| 129 |
pred_num_workers: 1
|
|
|
|
| 1 |
# PixelGen Medical - Kvasir-SEG Polyp Segmentation - Binary mask-conditional colonoscopy image generation
|
| 2 |
# Model: JiTMedical-S/8, mask_mode=spatial
|
| 3 |
+
# Optimized for 2x H800 80GB
|
| 4 |
seed_everything: 1234
|
| 5 |
tags:
|
| 6 |
exp: &exp PixelGen_Medical_Kvasir_S8_Spatial
|
|
|
|
| 35 |
init_args:
|
| 36 |
save_dir: val_samples
|
| 37 |
save_compressed: true
|
| 38 |
+
- class_path: src.callbacks.medical_visualization.MedicalVisualizationCallback
|
| 39 |
+
init_args:
|
| 40 |
+
every_n_steps: 5000
|
| 41 |
+
num_samples: 8
|
| 42 |
+
num_sampling_steps: 50
|
| 43 |
+
cfg_scale: 2.0
|
| 44 |
+
save_dir: training_vis
|
| 45 |
plugins:
|
| 46 |
- src.plugins.bd_env.BDEnvironment
|
| 47 |
|
|
|
|
| 131 |
resolution: 256
|
| 132 |
max_num_instances: 1000
|
| 133 |
noise_scale: 1.0
|
| 134 |
+
train_batch_size: 64
|
| 135 |
train_num_workers: 4
|
| 136 |
+
pred_batch_size: 32
|
| 137 |
pred_num_workers: 1
|
code/configs_medical/PixelGen_Medical_OCTA500_B16_CrossAttn.yaml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# PixelGen Medical - OCTA500 OCT Retinal Layer Segmentation - 6-class mask-conditional image generation
|
| 2 |
# Model: JiTMedical-B/16, mask_mode=cross_attention
|
|
|
|
| 3 |
seed_everything: 1234
|
| 4 |
tags:
|
| 5 |
exp: &exp PixelGen_Medical_OCTA500_B16_CrossAttn
|
|
@@ -34,6 +35,13 @@ trainer:
|
|
| 34 |
init_args:
|
| 35 |
save_dir: val_samples
|
| 36 |
save_compressed: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
plugins:
|
| 38 |
- src.plugins.bd_env.BDEnvironment
|
| 39 |
|
|
@@ -123,7 +131,7 @@ data:
|
|
| 123 |
resolution: 256
|
| 124 |
max_num_instances: 5000
|
| 125 |
noise_scale: 1.0
|
| 126 |
-
train_batch_size:
|
| 127 |
train_num_workers: 4
|
| 128 |
pred_batch_size: 32
|
| 129 |
pred_num_workers: 1
|
|
|
|
| 1 |
# PixelGen Medical - OCTA500 OCT Retinal Layer Segmentation - 6-class mask-conditional image generation
|
| 2 |
# Model: JiTMedical-B/16, mask_mode=cross_attention
|
| 3 |
+
# Optimized for 2x H800 80GB
|
| 4 |
seed_everything: 1234
|
| 5 |
tags:
|
| 6 |
exp: &exp PixelGen_Medical_OCTA500_B16_CrossAttn
|
|
|
|
| 35 |
init_args:
|
| 36 |
save_dir: val_samples
|
| 37 |
save_compressed: true
|
| 38 |
+
- class_path: src.callbacks.medical_visualization.MedicalVisualizationCallback
|
| 39 |
+
init_args:
|
| 40 |
+
every_n_steps: 5000
|
| 41 |
+
num_samples: 8
|
| 42 |
+
num_sampling_steps: 50
|
| 43 |
+
cfg_scale: 2.0
|
| 44 |
+
save_dir: training_vis
|
| 45 |
plugins:
|
| 46 |
- src.plugins.bd_env.BDEnvironment
|
| 47 |
|
|
|
|
| 131 |
resolution: 256
|
| 132 |
max_num_instances: 5000
|
| 133 |
noise_scale: 1.0
|
| 134 |
+
train_batch_size: 96
|
| 135 |
train_num_workers: 4
|
| 136 |
pred_batch_size: 32
|
| 137 |
pred_num_workers: 1
|
code/configs_medical/PixelGen_Medical_OCTA500_L16_Global.yaml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# PixelGen Medical - OCTA500 OCT Retinal Layer Segmentation - 6-class mask-conditional image generation
|
| 2 |
# Model: JiTMedical-L/16, mask_mode=global
|
|
|
|
| 3 |
seed_everything: 1234
|
| 4 |
tags:
|
| 5 |
exp: &exp PixelGen_Medical_OCTA500_L16_Global
|
|
@@ -34,6 +35,13 @@ trainer:
|
|
| 34 |
init_args:
|
| 35 |
save_dir: val_samples
|
| 36 |
save_compressed: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
plugins:
|
| 38 |
- src.plugins.bd_env.BDEnvironment
|
| 39 |
|
|
@@ -123,7 +131,7 @@ data:
|
|
| 123 |
resolution: 256
|
| 124 |
max_num_instances: 5000
|
| 125 |
noise_scale: 1.0
|
| 126 |
-
train_batch_size:
|
| 127 |
train_num_workers: 4
|
| 128 |
-
pred_batch_size:
|
| 129 |
pred_num_workers: 1
|
|
|
|
| 1 |
# PixelGen Medical - OCTA500 OCT Retinal Layer Segmentation - 6-class mask-conditional image generation
|
| 2 |
# Model: JiTMedical-L/16, mask_mode=global
|
| 3 |
+
# Optimized for 2x H800 80GB
|
| 4 |
seed_everything: 1234
|
| 5 |
tags:
|
| 6 |
exp: &exp PixelGen_Medical_OCTA500_L16_Global
|
|
|
|
| 35 |
init_args:
|
| 36 |
save_dir: val_samples
|
| 37 |
save_compressed: true
|
| 38 |
+
- class_path: src.callbacks.medical_visualization.MedicalVisualizationCallback
|
| 39 |
+
init_args:
|
| 40 |
+
every_n_steps: 5000
|
| 41 |
+
num_samples: 8
|
| 42 |
+
num_sampling_steps: 50
|
| 43 |
+
cfg_scale: 2.0
|
| 44 |
+
save_dir: training_vis
|
| 45 |
plugins:
|
| 46 |
- src.plugins.bd_env.BDEnvironment
|
| 47 |
|
|
|
|
| 131 |
resolution: 256
|
| 132 |
max_num_instances: 5000
|
| 133 |
noise_scale: 1.0
|
| 134 |
+
train_batch_size: 48
|
| 135 |
train_num_workers: 4
|
| 136 |
+
pred_batch_size: 32
|
| 137 |
pred_num_workers: 1
|
code/configs_medical/PixelGen_Medical_OCTA500_XL16_Global.yaml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# PixelGen Medical - OCTA500 OCT Retinal Layer Segmentation - 6-class mask-conditional image generation
|
| 2 |
# Model: JiTMedical-XL/16, mask_mode=global
|
|
|
|
| 3 |
seed_everything: 1234
|
| 4 |
tags:
|
| 5 |
exp: &exp PixelGen_Medical_OCTA500_XL16_Global
|
|
@@ -34,6 +35,13 @@ trainer:
|
|
| 34 |
init_args:
|
| 35 |
save_dir: val_samples
|
| 36 |
save_compressed: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
plugins:
|
| 38 |
- src.plugins.bd_env.BDEnvironment
|
| 39 |
|
|
@@ -123,7 +131,7 @@ data:
|
|
| 123 |
resolution: 256
|
| 124 |
max_num_instances: 5000
|
| 125 |
noise_scale: 1.0
|
| 126 |
-
train_batch_size:
|
| 127 |
train_num_workers: 4
|
| 128 |
-
pred_batch_size:
|
| 129 |
pred_num_workers: 1
|
|
|
|
| 1 |
# PixelGen Medical - OCTA500 OCT Retinal Layer Segmentation - 6-class mask-conditional image generation
|
| 2 |
# Model: JiTMedical-XL/16, mask_mode=global
|
| 3 |
+
# Optimized for 2x H800 80GB
|
| 4 |
seed_everything: 1234
|
| 5 |
tags:
|
| 6 |
exp: &exp PixelGen_Medical_OCTA500_XL16_Global
|
|
|
|
| 35 |
init_args:
|
| 36 |
save_dir: val_samples
|
| 37 |
save_compressed: true
|
| 38 |
+
- class_path: src.callbacks.medical_visualization.MedicalVisualizationCallback
|
| 39 |
+
init_args:
|
| 40 |
+
every_n_steps: 5000
|
| 41 |
+
num_samples: 8
|
| 42 |
+
num_sampling_steps: 50
|
| 43 |
+
cfg_scale: 2.0
|
| 44 |
+
save_dir: training_vis
|
| 45 |
plugins:
|
| 46 |
- src.plugins.bd_env.BDEnvironment
|
| 47 |
|
|
|
|
| 131 |
resolution: 256
|
| 132 |
max_num_instances: 5000
|
| 133 |
noise_scale: 1.0
|
| 134 |
+
train_batch_size: 32
|
| 135 |
train_num_workers: 4
|
| 136 |
+
pred_batch_size: 32
|
| 137 |
pred_num_workers: 1
|
code/configs_medical/PixelGen_Medical_REFUGE2_B16_CrossAttn.yaml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# PixelGen Medical - REFUGE2 Optic Disc/Cup Segmentation - 3-class mask-conditional fundus image generation
|
| 2 |
# Model: JiTMedical-B/16, mask_mode=cross_attention
|
|
|
|
| 3 |
seed_everything: 1234
|
| 4 |
tags:
|
| 5 |
exp: &exp PixelGen_Medical_REFUGE2_B16_CrossAttn
|
|
@@ -34,6 +35,13 @@ trainer:
|
|
| 34 |
init_args:
|
| 35 |
save_dir: val_samples
|
| 36 |
save_compressed: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
plugins:
|
| 38 |
- src.plugins.bd_env.BDEnvironment
|
| 39 |
|
|
@@ -125,7 +133,7 @@ data:
|
|
| 125 |
resolution: 256
|
| 126 |
max_num_instances: 1000
|
| 127 |
noise_scale: 1.0
|
| 128 |
-
train_batch_size:
|
| 129 |
train_num_workers: 4
|
| 130 |
-
pred_batch_size:
|
| 131 |
pred_num_workers: 1
|
|
|
|
| 1 |
# PixelGen Medical - REFUGE2 Optic Disc/Cup Segmentation - 3-class mask-conditional fundus image generation
|
| 2 |
# Model: JiTMedical-B/16, mask_mode=cross_attention
|
| 3 |
+
# Optimized for 2x H800 80GB
|
| 4 |
seed_everything: 1234
|
| 5 |
tags:
|
| 6 |
exp: &exp PixelGen_Medical_REFUGE2_B16_CrossAttn
|
|
|
|
| 35 |
init_args:
|
| 36 |
save_dir: val_samples
|
| 37 |
save_compressed: true
|
| 38 |
+
- class_path: src.callbacks.medical_visualization.MedicalVisualizationCallback
|
| 39 |
+
init_args:
|
| 40 |
+
every_n_steps: 5000
|
| 41 |
+
num_samples: 8
|
| 42 |
+
num_sampling_steps: 50
|
| 43 |
+
cfg_scale: 2.0
|
| 44 |
+
save_dir: training_vis
|
| 45 |
plugins:
|
| 46 |
- src.plugins.bd_env.BDEnvironment
|
| 47 |
|
|
|
|
| 133 |
resolution: 256
|
| 134 |
max_num_instances: 1000
|
| 135 |
noise_scale: 1.0
|
| 136 |
+
train_batch_size: 96
|
| 137 |
train_num_workers: 4
|
| 138 |
+
pred_batch_size: 32
|
| 139 |
pred_num_workers: 1
|
code/configs_medical/PixelGen_Medical_REFUGE2_B8_Spatial.yaml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# PixelGen Medical - REFUGE2 Optic Disc/Cup Segmentation - 3-class mask-conditional fundus image generation
|
| 2 |
# Model: JiTMedical-B/8, mask_mode=spatial
|
|
|
|
| 3 |
seed_everything: 1234
|
| 4 |
tags:
|
| 5 |
exp: &exp PixelGen_Medical_REFUGE2_B8_Spatial
|
|
@@ -34,6 +35,13 @@ trainer:
|
|
| 34 |
init_args:
|
| 35 |
save_dir: val_samples
|
| 36 |
save_compressed: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
plugins:
|
| 38 |
- src.plugins.bd_env.BDEnvironment
|
| 39 |
|
|
@@ -125,7 +133,7 @@ data:
|
|
| 125 |
resolution: 256
|
| 126 |
max_num_instances: 1000
|
| 127 |
noise_scale: 1.0
|
| 128 |
-
train_batch_size:
|
| 129 |
train_num_workers: 4
|
| 130 |
-
pred_batch_size:
|
| 131 |
pred_num_workers: 1
|
|
|
|
| 1 |
# PixelGen Medical - REFUGE2 Optic Disc/Cup Segmentation - 3-class mask-conditional fundus image generation
|
| 2 |
# Model: JiTMedical-B/8, mask_mode=spatial
|
| 3 |
+
# Optimized for 2x H800 80GB
|
| 4 |
seed_everything: 1234
|
| 5 |
tags:
|
| 6 |
exp: &exp PixelGen_Medical_REFUGE2_B8_Spatial
|
|
|
|
| 35 |
init_args:
|
| 36 |
save_dir: val_samples
|
| 37 |
save_compressed: true
|
| 38 |
+
- class_path: src.callbacks.medical_visualization.MedicalVisualizationCallback
|
| 39 |
+
init_args:
|
| 40 |
+
every_n_steps: 5000
|
| 41 |
+
num_samples: 8
|
| 42 |
+
num_sampling_steps: 50
|
| 43 |
+
cfg_scale: 2.0
|
| 44 |
+
save_dir: training_vis
|
| 45 |
plugins:
|
| 46 |
- src.plugins.bd_env.BDEnvironment
|
| 47 |
|
|
|
|
| 133 |
resolution: 256
|
| 134 |
max_num_instances: 1000
|
| 135 |
noise_scale: 1.0
|
| 136 |
+
train_batch_size: 32
|
| 137 |
train_num_workers: 4
|
| 138 |
+
pred_batch_size: 32
|
| 139 |
pred_num_workers: 1
|
code/configs_medical/PixelGen_Medical_REFUGE2_S8_Spatial.yaml
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# PixelGen Medical - REFUGE2 Optic Disc/Cup Segmentation - 3-class mask-conditional fundus image generation
|
| 2 |
# Model: JiTMedical-S/8, mask_mode=spatial
|
|
|
|
| 3 |
seed_everything: 1234
|
| 4 |
tags:
|
| 5 |
exp: &exp PixelGen_Medical_REFUGE2_S8_Spatial
|
|
@@ -34,6 +35,13 @@ trainer:
|
|
| 34 |
init_args:
|
| 35 |
save_dir: val_samples
|
| 36 |
save_compressed: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
plugins:
|
| 38 |
- src.plugins.bd_env.BDEnvironment
|
| 39 |
|
|
@@ -125,7 +133,7 @@ data:
|
|
| 125 |
resolution: 256
|
| 126 |
max_num_instances: 1000
|
| 127 |
noise_scale: 1.0
|
| 128 |
-
train_batch_size:
|
| 129 |
train_num_workers: 4
|
| 130 |
-
pred_batch_size:
|
| 131 |
pred_num_workers: 1
|
|
|
|
| 1 |
# PixelGen Medical - REFUGE2 Optic Disc/Cup Segmentation - 3-class mask-conditional fundus image generation
|
| 2 |
# Model: JiTMedical-S/8, mask_mode=spatial
|
| 3 |
+
# Optimized for 2x H800 80GB
|
| 4 |
seed_everything: 1234
|
| 5 |
tags:
|
| 6 |
exp: &exp PixelGen_Medical_REFUGE2_S8_Spatial
|
|
|
|
| 35 |
init_args:
|
| 36 |
save_dir: val_samples
|
| 37 |
save_compressed: true
|
| 38 |
+
- class_path: src.callbacks.medical_visualization.MedicalVisualizationCallback
|
| 39 |
+
init_args:
|
| 40 |
+
every_n_steps: 5000
|
| 41 |
+
num_samples: 8
|
| 42 |
+
num_sampling_steps: 50
|
| 43 |
+
cfg_scale: 2.0
|
| 44 |
+
save_dir: training_vis
|
| 45 |
plugins:
|
| 46 |
- src.plugins.bd_env.BDEnvironment
|
| 47 |
|
|
|
|
| 133 |
resolution: 256
|
| 134 |
max_num_instances: 1000
|
| 135 |
noise_scale: 1.0
|
| 136 |
+
train_batch_size: 64
|
| 137 |
train_num_workers: 4
|
| 138 |
+
pred_batch_size: 32
|
| 139 |
pred_num_workers: 1
|
code/run_ablation.sh
CHANGED
|
@@ -1,59 +1,60 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
# PixelGen Medical - Ablation Study Training Commands
|
| 3 |
-
# All experiments: 100k steps,
|
| 4 |
# Organized by dataset, then by experiment type
|
|
|
|
| 5 |
|
| 6 |
# ═══════════════════════════════════════════════════════════════
|
| 7 |
# CVC-ClinicDB (550 train images, binary polyp masks)
|
| 8 |
# ═══════════════════════════════════════════════════════════════
|
| 9 |
|
| 10 |
-
# CVC - S/8 Spatial (39M
|
| 11 |
-
torchrun --nproc_per_node=
|
| 12 |
|
| 13 |
-
# CVC - B/8 Spatial (131M
|
| 14 |
-
torchrun --nproc_per_node=
|
| 15 |
|
| 16 |
-
# CVC - B/16 CrossAttn (159M
|
| 17 |
-
torchrun --nproc_per_node=
|
| 18 |
|
| 19 |
# ═══════════════════════════════════════════════════════════════
|
| 20 |
# Kvasir-SEG (900 train images, binary polyp masks)
|
| 21 |
# ═══════════════════════════════════════════════════════════════
|
| 22 |
|
| 23 |
-
# Kvasir - S/8 Spatial (39M
|
| 24 |
-
torchrun --nproc_per_node=
|
| 25 |
|
| 26 |
-
# Kvasir - B/8 Spatial (131M
|
| 27 |
-
torchrun --nproc_per_node=
|
| 28 |
|
| 29 |
-
# Kvasir - B/16 CrossAttn (159M
|
| 30 |
-
torchrun --nproc_per_node=
|
| 31 |
|
| 32 |
# ═══════════════════════════════════════════════════════════════
|
| 33 |
# REFUGE2 (720 train images, 3-class fundus masks)
|
| 34 |
# ═══════════════════════════════════════════════════════════════
|
| 35 |
|
| 36 |
-
# REFUGE2 - S/8 Spatial (39M
|
| 37 |
-
torchrun --nproc_per_node=
|
| 38 |
|
| 39 |
-
# REFUGE2 - B/8 Spatial (131M
|
| 40 |
-
torchrun --nproc_per_node=
|
| 41 |
|
| 42 |
-
# REFUGE2 - B/16 CrossAttn (159M
|
| 43 |
-
torchrun --nproc_per_node=
|
| 44 |
|
| 45 |
# ═══════════════════════════════════════════════════════════════
|
| 46 |
# OCTA500 (108k train images, 6-class layer masks)
|
| 47 |
# ═══════════════════════════════════════════════════════════════
|
| 48 |
|
| 49 |
-
# OCTA500 - B/16 CrossAttn (159M
|
| 50 |
-
torchrun --nproc_per_node=
|
| 51 |
|
| 52 |
-
# OCTA500 - L/16 Global (458M
|
| 53 |
-
torchrun --nproc_per_node=
|
| 54 |
|
| 55 |
-
# OCTA500 - XL/16 Global (676M
|
| 56 |
-
torchrun --nproc_per_node=
|
| 57 |
|
| 58 |
# ═══════════════════════════════════════════════════════════════
|
| 59 |
# Evaluation (FID / Precision / Recall)
|
|
@@ -62,21 +63,26 @@ torchrun --nproc_per_node=8 main.py fit --config configs_medical/PixelGen_Medica
|
|
| 62 |
|
| 63 |
# CVC evaluations
|
| 64 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset cvc --model S/8 --mask_mode spatial --ckpt medical_workdirs/exp_PixelGen_Medical_CVC_S8_Spatial/PATH_TO_CKPT --cfg
|
|
|
|
| 65 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset cvc --model B/8 --mask_mode spatial --ckpt medical_workdirs/exp_PixelGen_Medical_CVC_B8_Spatial/PATH_TO_CKPT --cfg
|
|
|
|
| 66 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset cvc --model B/16 --mask_mode cross_attention --ckpt medical_workdirs/exp_PixelGen_Medical_CVC_B16_CrossAttn/PATH_TO_CKPT --cfg
|
| 67 |
|
| 68 |
# Kvasir evaluations
|
| 69 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset kvasir --model S/8 --mask_mode spatial --ckpt medical_workdirs/exp_PixelGen_Medical_Kvasir_S8_Spatial/PATH_TO_CKPT --cfg
|
|
|
|
| 70 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset kvasir --model B/8 --mask_mode spatial --ckpt medical_workdirs/exp_PixelGen_Medical_Kvasir_B8_Spatial/PATH_TO_CKPT --cfg
|
|
|
|
| 71 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset kvasir --model B/16 --mask_mode cross_attention --ckpt medical_workdirs/exp_PixelGen_Medical_Kvasir_B16_CrossAttn/PATH_TO_CKPT --cfg
|
| 72 |
|
| 73 |
# REFUGE2 evaluations
|
| 74 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset refuge2 --model S/8 --mask_mode spatial --ckpt medical_workdirs/exp_PixelGen_Medical_REFUGE2_S8_Spatial/PATH_TO_CKPT --cfg
|
|
|
|
| 75 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset refuge2 --model B/8 --mask_mode spatial --ckpt medical_workdirs/exp_PixelGen_Medical_REFUGE2_B8_Spatial/PATH_TO_CKPT --cfg
|
|
|
|
| 76 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset refuge2 --model B/16 --mask_mode cross_attention --ckpt medical_workdirs/exp_PixelGen_Medical_REFUGE2_B16_CrossAttn/PATH_TO_CKPT --cfg
|
| 77 |
|
| 78 |
-
# OCTA500 evaluations (evaluate_medical.py does not yet support OCTA500
|
| 79 |
-
#
|
| 80 |
-
# torchrun --nproc_per_node=
|
| 81 |
-
# torchrun --nproc_per_node=
|
| 82 |
-
# torchrun --nproc_per_node=8 main.py predict --config configs_medical/PixelGen_Medical_OCTA500_XL16_Global.yaml --ckpt_path PATH_TO_CKPT
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
# PixelGen Medical - Ablation Study Training Commands
|
| 3 |
+
# All experiments: 100k steps, 2x H800 80GB
|
| 4 |
# Organized by dataset, then by experiment type
|
| 5 |
+
# Visualization saved to training_vis/ every 5000 steps
|
| 6 |
|
| 7 |
# ═══════════════════════════════════════════════════════════════
|
| 8 |
# CVC-ClinicDB (550 train images, binary polyp masks)
|
| 9 |
# ═══════════════════════════════════════════════════════════════
|
| 10 |
|
| 11 |
+
# CVC - S/8 Spatial (39M, bs=64/gpu)
|
| 12 |
+
torchrun --nproc_per_node=2 main.py fit --config configs_medical/PixelGen_Medical_CVC_S8_Spatial.yaml
|
| 13 |
|
| 14 |
+
# CVC - B/8 Spatial (131M, bs=32/gpu)
|
| 15 |
+
torchrun --nproc_per_node=2 main.py fit --config configs_medical/PixelGen_Medical_CVC_B8_Spatial.yaml
|
| 16 |
|
| 17 |
+
# CVC - B/16 CrossAttn (159M, bs=96/gpu)
|
| 18 |
+
torchrun --nproc_per_node=2 main.py fit --config configs_medical/PixelGen_Medical_CVC_B16_CrossAttn.yaml
|
| 19 |
|
| 20 |
# ═══════════════════════════════════════════════════════════════
|
| 21 |
# Kvasir-SEG (900 train images, binary polyp masks)
|
| 22 |
# ═══════════════════════════════════════════════════════════════
|
| 23 |
|
| 24 |
+
# Kvasir - S/8 Spatial (39M, bs=64/gpu)
|
| 25 |
+
torchrun --nproc_per_node=2 main.py fit --config configs_medical/PixelGen_Medical_Kvasir_S8_Spatial.yaml
|
| 26 |
|
| 27 |
+
# Kvasir - B/8 Spatial (131M, bs=32/gpu)
|
| 28 |
+
torchrun --nproc_per_node=2 main.py fit --config configs_medical/PixelGen_Medical_Kvasir_B8_Spatial.yaml
|
| 29 |
|
| 30 |
+
# Kvasir - B/16 CrossAttn (159M, bs=96/gpu)
|
| 31 |
+
torchrun --nproc_per_node=2 main.py fit --config configs_medical/PixelGen_Medical_Kvasir_B16_CrossAttn.yaml
|
| 32 |
|
| 33 |
# ═══════════════════════════════════════════════════════════════
|
| 34 |
# REFUGE2 (720 train images, 3-class fundus masks)
|
| 35 |
# ═══════════════════════════════════════════════════════════════
|
| 36 |
|
| 37 |
+
# REFUGE2 - S/8 Spatial (39M, bs=64/gpu)
|
| 38 |
+
torchrun --nproc_per_node=2 main.py fit --config configs_medical/PixelGen_Medical_REFUGE2_S8_Spatial.yaml
|
| 39 |
|
| 40 |
+
# REFUGE2 - B/8 Spatial (131M, bs=32/gpu)
|
| 41 |
+
torchrun --nproc_per_node=2 main.py fit --config configs_medical/PixelGen_Medical_REFUGE2_B8_Spatial.yaml
|
| 42 |
|
| 43 |
+
# REFUGE2 - B/16 CrossAttn (159M, bs=96/gpu)
|
| 44 |
+
torchrun --nproc_per_node=2 main.py fit --config configs_medical/PixelGen_Medical_REFUGE2_B16_CrossAttn.yaml
|
| 45 |
|
| 46 |
# ═══════════════════════════════════════════════════════════════
|
| 47 |
# OCTA500 (108k train images, 6-class layer masks)
|
| 48 |
# ═══════════════════════════════════════════════════════════════
|
| 49 |
|
| 50 |
+
# OCTA500 - B/16 CrossAttn (159M, bs=96/gpu)
|
| 51 |
+
torchrun --nproc_per_node=2 main.py fit --config configs_medical/PixelGen_Medical_OCTA500_B16_CrossAttn.yaml
|
| 52 |
|
| 53 |
+
# OCTA500 - L/16 Global (458M, bs=48/gpu)
|
| 54 |
+
torchrun --nproc_per_node=2 main.py fit --config configs_medical/PixelGen_Medical_OCTA500_L16_Global.yaml
|
| 55 |
|
| 56 |
+
# OCTA500 - XL/16 Global (676M, bs=32/gpu)
|
| 57 |
+
torchrun --nproc_per_node=2 main.py fit --config configs_medical/PixelGen_Medical_OCTA500_XL16_Global.yaml
|
| 58 |
|
| 59 |
# ═══════════════════════════════════════════════════════════════
|
| 60 |
# Evaluation (FID / Precision / Recall)
|
|
|
|
| 63 |
|
| 64 |
# CVC evaluations
|
| 65 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset cvc --model S/8 --mask_mode spatial --ckpt medical_workdirs/exp_PixelGen_Medical_CVC_S8_Spatial/PATH_TO_CKPT --cfg
|
| 66 |
+
|
| 67 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset cvc --model B/8 --mask_mode spatial --ckpt medical_workdirs/exp_PixelGen_Medical_CVC_B8_Spatial/PATH_TO_CKPT --cfg
|
| 68 |
+
|
| 69 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset cvc --model B/16 --mask_mode cross_attention --ckpt medical_workdirs/exp_PixelGen_Medical_CVC_B16_CrossAttn/PATH_TO_CKPT --cfg
|
| 70 |
|
| 71 |
# Kvasir evaluations
|
| 72 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset kvasir --model S/8 --mask_mode spatial --ckpt medical_workdirs/exp_PixelGen_Medical_Kvasir_S8_Spatial/PATH_TO_CKPT --cfg
|
| 73 |
+
|
| 74 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset kvasir --model B/8 --mask_mode spatial --ckpt medical_workdirs/exp_PixelGen_Medical_Kvasir_B8_Spatial/PATH_TO_CKPT --cfg
|
| 75 |
+
|
| 76 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset kvasir --model B/16 --mask_mode cross_attention --ckpt medical_workdirs/exp_PixelGen_Medical_Kvasir_B16_CrossAttn/PATH_TO_CKPT --cfg
|
| 77 |
|
| 78 |
# REFUGE2 evaluations
|
| 79 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset refuge2 --model S/8 --mask_mode spatial --ckpt medical_workdirs/exp_PixelGen_Medical_REFUGE2_S8_Spatial/PATH_TO_CKPT --cfg
|
| 80 |
+
|
| 81 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset refuge2 --model B/8 --mask_mode spatial --ckpt medical_workdirs/exp_PixelGen_Medical_REFUGE2_B8_Spatial/PATH_TO_CKPT --cfg
|
| 82 |
+
|
| 83 |
CUDA_VISIBLE_DEVICES=0 python scripts/evaluate_medical.py --dataset refuge2 --model B/16 --mask_mode cross_attention --ckpt medical_workdirs/exp_PixelGen_Medical_REFUGE2_B16_CrossAttn/PATH_TO_CKPT --cfg
|
| 84 |
|
| 85 |
+
# OCTA500 evaluations (evaluate_medical.py does not yet support OCTA500)
|
| 86 |
+
# torchrun --nproc_per_node=2 main.py predict --config configs_medical/PixelGen_Medical_OCTA500_B16_CrossAttn.yaml --ckpt_path PATH_TO_CKPT
|
| 87 |
+
# torchrun --nproc_per_node=2 main.py predict --config configs_medical/PixelGen_Medical_OCTA500_L16_Global.yaml --ckpt_path PATH_TO_CKPT
|
| 88 |
+
# torchrun --nproc_per_node=2 main.py predict --config configs_medical/PixelGen_Medical_OCTA500_XL16_Global.yaml --ckpt_path PATH_TO_CKPT
|
|
|
code/src/callbacks/medical_visualization.py
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Medical Visualization Callback
|
| 2 |
+
# Saves mask + generated image grids during training for visual quality monitoring
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
import torch
|
| 6 |
+
import numpy as np
|
| 7 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 8 |
+
import lightning.pytorch as pl
|
| 9 |
+
from lightning.pytorch import Callback
|
| 10 |
+
from lightning_utilities.core.rank_zero import rank_zero_info
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class MedicalVisualizationCallback(Callback):
|
| 14 |
+
"""
|
| 15 |
+
Periodically generates and saves visualization grids during training.
|
| 16 |
+
|
| 17 |
+
Each grid shows: [Mask | Generated (CFG) | Generated (No-CFG)]
|
| 18 |
+
for a fixed set of masks, allowing visual comparison across training.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
def __init__(
|
| 22 |
+
self,
|
| 23 |
+
every_n_steps: int = 5000,
|
| 24 |
+
num_samples: int = 8,
|
| 25 |
+
num_sampling_steps: int = 50,
|
| 26 |
+
cfg_scale: float = 2.0,
|
| 27 |
+
save_dir: str = "training_vis",
|
| 28 |
+
t_eps: float = 0.05,
|
| 29 |
+
):
|
| 30 |
+
super().__init__()
|
| 31 |
+
self.every_n_steps = every_n_steps
|
| 32 |
+
self.num_samples = num_samples
|
| 33 |
+
self.num_sampling_steps = num_sampling_steps
|
| 34 |
+
self.cfg_scale = cfg_scale
|
| 35 |
+
self.save_dir = save_dir
|
| 36 |
+
self.t_eps = t_eps
|
| 37 |
+
self._fixed_noise = None
|
| 38 |
+
self._fixed_masks = None
|
| 39 |
+
|
| 40 |
+
def _shift_respace_fn(self, t, shift=1.0):
|
| 41 |
+
return t / (t + (1 - t) * shift)
|
| 42 |
+
|
| 43 |
+
@torch.no_grad()
|
| 44 |
+
def _sample(self, model, noise, mask, cfg_scale=None):
|
| 45 |
+
"""Euler sampling with optional CFG, directly passing mask to model."""
|
| 46 |
+
bs = noise.shape[0]
|
| 47 |
+
timesteps = torch.linspace(0.0, 1 - 1.0 / self.num_sampling_steps, self.num_sampling_steps)
|
| 48 |
+
timesteps = torch.cat([timesteps, torch.tensor([1.0])], dim=0)
|
| 49 |
+
timesteps = self._shift_respace_fn(timesteps, 1.0).to(noise.device)
|
| 50 |
+
y = torch.zeros(bs, dtype=torch.long, device=noise.device)
|
| 51 |
+
x = noise
|
| 52 |
+
|
| 53 |
+
for i in range(len(timesteps) - 1):
|
| 54 |
+
t_cur = timesteps[i]
|
| 55 |
+
t_next = timesteps[i + 1]
|
| 56 |
+
dt = t_next - t_cur
|
| 57 |
+
t_batch = t_cur.repeat(bs)
|
| 58 |
+
|
| 59 |
+
if cfg_scale is not None and cfg_scale > 1.0:
|
| 60 |
+
# CFG: concat unconditional + conditional
|
| 61 |
+
cfg_x = torch.cat([x, x], dim=0)
|
| 62 |
+
cfg_t = t_batch.repeat(2)
|
| 63 |
+
cfg_y = torch.cat([y, y], dim=0)
|
| 64 |
+
cfg_mask = torch.cat([torch.zeros_like(mask), mask], dim=0)
|
| 65 |
+
pred = model(cfg_x, cfg_t, cfg_y, mask=cfg_mask)
|
| 66 |
+
pred_v = (pred - cfg_x) / (1.0 - cfg_t.view(-1, 1, 1, 1)).clamp_min(self.t_eps)
|
| 67 |
+
v_uncond, v_cond = pred_v.chunk(2)
|
| 68 |
+
v = v_uncond + cfg_scale * (v_cond - v_uncond)
|
| 69 |
+
else:
|
| 70 |
+
# No CFG
|
| 71 |
+
pred = model(x, t_batch, y, mask=mask)
|
| 72 |
+
v = (pred - x) / (1.0 - t_batch.view(-1, 1, 1, 1)).clamp_min(self.t_eps)
|
| 73 |
+
|
| 74 |
+
x = x + v * dt
|
| 75 |
+
|
| 76 |
+
return x.clamp(-1, 1) * 0.5 + 0.5 # [-1,1] -> [0,1]
|
| 77 |
+
|
| 78 |
+
def _mask_to_rgb(self, mask_tensor):
|
| 79 |
+
"""Convert single-channel mask [1, H, W] to RGB [H, W, 3] uint8."""
|
| 80 |
+
m = mask_tensor[0].cpu().numpy()
|
| 81 |
+
unique_vals = np.unique(m)
|
| 82 |
+
|
| 83 |
+
if len(unique_vals) <= 3:
|
| 84 |
+
# Multi-class: colorize (e.g., REFUGE2: 0=black, ~0.5=blue, ~1.0=red)
|
| 85 |
+
rgb = np.zeros((*m.shape, 3), dtype=np.uint8)
|
| 86 |
+
rgb[m < 0.1] = [0, 0, 0] # background
|
| 87 |
+
rgb[(m >= 0.1) & (m < 0.7)] = [0, 120, 255] # class 1 (blue)
|
| 88 |
+
rgb[m >= 0.7] = [255, 60, 60] # class 2 (red)
|
| 89 |
+
else:
|
| 90 |
+
# Binary or continuous: grayscale
|
| 91 |
+
m_uint8 = (m * 255).astype(np.uint8)
|
| 92 |
+
rgb = np.stack([m_uint8] * 3, axis=-1)
|
| 93 |
+
|
| 94 |
+
return rgb
|
| 95 |
+
|
| 96 |
+
def _make_grid(self, masks, gen_cfg, gen_nocfg, step):
|
| 97 |
+
"""Create visualization grid: Mask | CFG | No-CFG."""
|
| 98 |
+
n = masks.shape[0]
|
| 99 |
+
h, w = masks.shape[2], masks.shape[3]
|
| 100 |
+
pad = 4
|
| 101 |
+
col_labels = ["Mask", f"CFG={self.cfg_scale}", "No-CFG"]
|
| 102 |
+
n_cols = len(col_labels)
|
| 103 |
+
header_h = 30
|
| 104 |
+
|
| 105 |
+
canvas_w = n_cols * w + (n_cols + 1) * pad
|
| 106 |
+
canvas_h = n * h + (n + 1) * pad + header_h
|
| 107 |
+
canvas = np.ones((canvas_h, canvas_w, 3), dtype=np.uint8) * 40
|
| 108 |
+
|
| 109 |
+
# Header
|
| 110 |
+
try:
|
| 111 |
+
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 16)
|
| 112 |
+
except (IOError, OSError):
|
| 113 |
+
font = ImageFont.load_default()
|
| 114 |
+
|
| 115 |
+
img_pil = Image.fromarray(canvas)
|
| 116 |
+
draw = ImageDraw.Draw(img_pil)
|
| 117 |
+
for col_idx, label in enumerate(col_labels):
|
| 118 |
+
x_pos = pad + col_idx * (w + pad) + w // 2
|
| 119 |
+
draw.text((x_pos, 6), label, fill=(255, 255, 255), font=font, anchor="mt")
|
| 120 |
+
# Step info
|
| 121 |
+
draw.text((canvas_w - 10, 6), f"step={step}", fill=(180, 180, 180), font=font, anchor="rt")
|
| 122 |
+
canvas = np.array(img_pil)
|
| 123 |
+
|
| 124 |
+
for row in range(n):
|
| 125 |
+
y_pos = header_h + pad + row * (h + pad)
|
| 126 |
+
|
| 127 |
+
# Mask column
|
| 128 |
+
mask_rgb = self._mask_to_rgb(masks[row])
|
| 129 |
+
x_pos = pad
|
| 130 |
+
canvas[y_pos:y_pos + h, x_pos:x_pos + w] = mask_rgb
|
| 131 |
+
|
| 132 |
+
# CFG generated
|
| 133 |
+
img_cfg = (gen_cfg[row].permute(1, 2, 0).cpu().numpy() * 255).clip(0, 255).astype(np.uint8)
|
| 134 |
+
x_pos = pad + (w + pad)
|
| 135 |
+
canvas[y_pos:y_pos + h, x_pos:x_pos + w] = img_cfg
|
| 136 |
+
|
| 137 |
+
# No-CFG generated
|
| 138 |
+
img_nocfg = (gen_nocfg[row].permute(1, 2, 0).cpu().numpy() * 255).clip(0, 255).astype(np.uint8)
|
| 139 |
+
x_pos = pad + 2 * (w + pad)
|
| 140 |
+
canvas[y_pos:y_pos + h, x_pos:x_pos + w] = img_nocfg
|
| 141 |
+
|
| 142 |
+
return canvas
|
| 143 |
+
|
| 144 |
+
def on_train_batch_end(self, trainer, pl_module, outputs, batch, batch_idx):
|
| 145 |
+
step = trainer.global_step
|
| 146 |
+
if step == 0 or step % self.every_n_steps != 0:
|
| 147 |
+
return
|
| 148 |
+
if not trainer.is_global_zero:
|
| 149 |
+
return
|
| 150 |
+
|
| 151 |
+
# Initialize fixed noise and masks from first validation batch
|
| 152 |
+
if self._fixed_masks is None:
|
| 153 |
+
eval_dl = trainer.datamodule.val_dataloader()
|
| 154 |
+
for eval_batch in eval_dl:
|
| 155 |
+
xT, y, metadata = eval_batch
|
| 156 |
+
mask = metadata.get('mask', None) if isinstance(metadata, dict) else None
|
| 157 |
+
if mask is None:
|
| 158 |
+
rank_zero_info("[MedicalVis] No mask in eval batch, skipping visualization")
|
| 159 |
+
return
|
| 160 |
+
n = min(self.num_samples, mask.shape[0])
|
| 161 |
+
self._fixed_masks = mask[:n].to(pl_module.device)
|
| 162 |
+
self._fixed_noise = torch.randn(
|
| 163 |
+
n, 3, pl_module.denoiser.input_size, pl_module.denoiser.input_size,
|
| 164 |
+
device=pl_module.device, generator=torch.Generator(device=pl_module.device).manual_seed(42)
|
| 165 |
+
)
|
| 166 |
+
break
|
| 167 |
+
|
| 168 |
+
if self._fixed_masks is None:
|
| 169 |
+
return
|
| 170 |
+
|
| 171 |
+
# Generate samples using EMA model
|
| 172 |
+
model = pl_module.ema_denoiser
|
| 173 |
+
was_training = model.training
|
| 174 |
+
model.eval()
|
| 175 |
+
|
| 176 |
+
noise = self._fixed_noise
|
| 177 |
+
masks = self._fixed_masks
|
| 178 |
+
|
| 179 |
+
gen_cfg = self._sample(model, noise, masks, cfg_scale=self.cfg_scale)
|
| 180 |
+
gen_nocfg = self._sample(model, noise, masks, cfg_scale=None)
|
| 181 |
+
|
| 182 |
+
if was_training:
|
| 183 |
+
model.train()
|
| 184 |
+
|
| 185 |
+
# Save grid
|
| 186 |
+
save_path = os.path.join(trainer.default_root_dir, self.save_dir)
|
| 187 |
+
os.makedirs(save_path, exist_ok=True)
|
| 188 |
+
grid = self._make_grid(masks, gen_cfg, gen_nocfg, step)
|
| 189 |
+
Image.fromarray(grid).save(os.path.join(save_path, f"vis_step_{step:06d}.png"))
|
| 190 |
+
rank_zero_info(f"[MedicalVis] Saved visualization at step {step}")
|
code/src/diffusion/base/sampling.py
CHANGED
|
@@ -24,8 +24,8 @@ class BaseSampler(nn.Module):
|
|
| 24 |
def _impl_sampling(self, net, noise, condition, uncondition):
|
| 25 |
raise NotImplementedError
|
| 26 |
|
| 27 |
-
def forward(self, net, noise, condition, uncondition, return_x_trajs=False, return_v_trajs=False):
|
| 28 |
-
x_trajs, v_trajs = self._impl_sampling(net, noise, condition, uncondition)
|
| 29 |
if return_x_trajs and return_v_trajs:
|
| 30 |
return x_trajs[-1], x_trajs, v_trajs
|
| 31 |
elif return_x_trajs:
|
|
|
|
| 24 |
def _impl_sampling(self, net, noise, condition, uncondition):
|
| 25 |
raise NotImplementedError
|
| 26 |
|
| 27 |
+
def forward(self, net, noise, condition, uncondition, return_x_trajs=False, return_v_trajs=False, **kwargs):
|
| 28 |
+
x_trajs, v_trajs = self._impl_sampling(net, noise, condition, uncondition, **kwargs)
|
| 29 |
if return_x_trajs and return_v_trajs:
|
| 30 |
return x_trajs[-1], x_trajs, v_trajs
|
| 31 |
elif return_x_trajs:
|
code/src/lightning_model.py
CHANGED
|
@@ -147,11 +147,22 @@ class LightningModel(pl.LightningModule):
|
|
| 147 |
with torch.no_grad():
|
| 148 |
condition, uncondition = self.conditioner(y, metadata)
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
# sample images
|
| 151 |
if self.eval_original_model:
|
| 152 |
-
samples = self.diffusion_sampler(self.denoiser, xT, condition, uncondition)
|
| 153 |
else:
|
| 154 |
-
samples = self.diffusion_sampler(self.ema_denoiser, xT, condition, uncondition)
|
| 155 |
|
| 156 |
samples = self.vae.decode(samples)
|
| 157 |
# fp32 -1,1 -> uint8 0,255
|
|
|
|
| 147 |
with torch.no_grad():
|
| 148 |
condition, uncondition = self.conditioner(y, metadata)
|
| 149 |
|
| 150 |
+
# Extract mask for direct conditioning (spatial/cross_attention modes)
|
| 151 |
+
mask = None
|
| 152 |
+
if isinstance(metadata, dict):
|
| 153 |
+
mask = metadata.get('mask', None)
|
| 154 |
+
elif isinstance(metadata, (list, tuple)):
|
| 155 |
+
masks = [m.get('mask', None) for m in metadata if isinstance(m, dict)]
|
| 156 |
+
if len(masks) > 0 and masks[0] is not None:
|
| 157 |
+
mask = torch.stack(masks, dim=0)
|
| 158 |
+
if mask is not None:
|
| 159 |
+
mask = mask.to(xT.device)
|
| 160 |
+
|
| 161 |
# sample images
|
| 162 |
if self.eval_original_model:
|
| 163 |
+
samples = self.diffusion_sampler(self.denoiser, xT, condition, uncondition, mask=mask)
|
| 164 |
else:
|
| 165 |
+
samples = self.diffusion_sampler(self.ema_denoiser, xT, condition, uncondition, mask=mask)
|
| 166 |
|
| 167 |
samples = self.vae.decode(samples)
|
| 168 |
# fp32 -1,1 -> uint8 0,255
|