forked from FirasGit/medicaldiffusion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
136 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"workbench.colorTheme": "Darcula" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
defaults: | ||
- dataset: ??? | ||
- model: ??? |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: BRATS | ||
root_dir: ??? | ||
image_channels: 1 | ||
train: True | ||
img_type: flair |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: MRNet | ||
root_dir: /data/home/firas/Desktop/work/MR_Knie/Data/MRNet/MRNet-v1.0/ | ||
image_channels: 1 | ||
task: acl | ||
plane: sagittal | ||
split: train | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
vqgan_ckpt: /data/home/firas/Desktop/work/other_groups/vq_gan_3d/checkpoints_generation/knee_mri_gen/lightning_logs/version_0/checkpoints/epoch=245-step=222000-train/recon_loss=0.81.ckpt | ||
batch_size: 40 | ||
num_workers: 30 | ||
load_milestone: False | ||
logger: wandb | ||
objective: pred_x0 | ||
diffusion_img_size: 32 | ||
diffusion_depth_size: 4 | ||
diffusion_num_channels: 8 | ||
save_and_sample_every: 400 | ||
train_lr: 1e-4 | ||
timesteps: 300 # number of steps | ||
sampling_timesteps: 250 # number of sampling timesteps (using ddim for faster inference [see citation for ddim paper]) | ||
loss_type: l1 # L1 or L2 | ||
train_num_steps: 700000 # total training steps | ||
gradient_accumulate_every: 2 # gradient accumulation steps | ||
ema_decay: 0.995 # exponential moving average decay | ||
amp: False # turn on mixed precision | ||
num_sample_rows: 1 | ||
dim_muls: [1, 2, 4, 8] | ||
|
||
|
||
# Has to be derived from VQ-GAN Latent Space | ||
diffusion_img_size: 32 | ||
diffusion_depth_size: 4 | ||
diffusion_num_channels: 8 | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import imp | ||
from vq_gan_3d.dataset.breast_uka import BreastUKA | ||
from vq_gan_3d.dataset.mrnet import MRNetDataset | ||
from vq_gan_3d.dataset.brats import BRATSDataset | ||
from vq_gan_3d.dataset.adni import ADNIDataset | ||
from medicaldiffusion.dataset.breast_uka import BreastUKA | ||
from medicaldiffusion.dataset.mrnet import MRNetDataset | ||
from medicaldiffusion.dataset.brats import BRATSDataset | ||
from medicaldiffusion.dataset.adni import ADNIDataset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from diffusion import Unet3D, GaussianDiffusion, Trainer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from dataset import * | ||
|
||
|
||
def get_dataset(cfg): | ||
if cfg.dataset.name == 'MRNet': | ||
return MRNetDataset(root_dir=cfg.dataset.root_dir, task=cfg.dataset.task, plane=cfg.dataset.plane, split=cfg.dataset.split) | ||
if cfg.dataset.name == 'BRATS': | ||
return BRATSDataset(root_dir=cfg.dataset.root_dir, train=cfg.dataset.train, img_type=cfg.dataset.img_type) | ||
if cfg.dataset.name == 'ADNI': | ||
return ADNIDataset() | ||
raise ValueError(f'{cfg.dataset.name} Dataset is not available') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from re import I | ||
from ddpm import Unet3D, GaussianDiffusion, Trainer | ||
from dataset import MRNetDataset, BRATSDataset | ||
import argparse | ||
import wandb | ||
import hydra | ||
from omegaconf import DictConfig, OmegaConf | ||
from train.dataset import get_dataset | ||
|
||
|
||
# NCCL_P2P_DISABLE=1 accelerate launch train/train_ddpm.py | ||
|
||
@hydra.main(config_path='../config', config_name='base_cfg') | ||
def run(cfg: DictConfig): | ||
model = Unet3D( | ||
dim=cfg.model.unet.diffusion_img_size, | ||
dim_mults=cfg.model.unet.dim_mults, | ||
channels=cfg.model.unet.diffusion_num_channels, | ||
).cuda() | ||
|
||
diffusion = GaussianDiffusion( | ||
model, | ||
vqgan_ckpt=cfg.model.vqgan_ckpt, | ||
image_size=cfg.model.diffusion_img_size, | ||
num_frames=cfg.model.diffusion_depth_size, | ||
channels=cfg.model.diffusion_num_channels, | ||
timesteps=cfg.model.timesteps, | ||
# sampling_timesteps=cfg.model.sampling_timesteps, | ||
loss_type=cfg.model.loss_type, | ||
# objective=cfg.objective | ||
).cuda() | ||
|
||
train_dataset = get_dataset(cfg) | ||
|
||
trainer = Trainer( | ||
diffusion, | ||
cfg=cfg, | ||
dataset=train_dataset, | ||
train_batch_size=cfg.model.batch_size, | ||
save_and_sample_every=cfg.model.save_and_sample_every, | ||
train_lr=cfg.model.train_lr, | ||
train_num_steps=cfg.model.train_num_steps, | ||
gradient_accumulate_every=cfg.model.gradient_accumulate_every, | ||
ema_decay=cfg.model.ema_decay, | ||
amp=cfg.model.amp, | ||
num_sample_rows=cfg.model.num_sample_rows, | ||
# logger=cfg.model.logger | ||
) | ||
|
||
if cfg.model.load_milestone: | ||
trainer.load(cfg.model.load_milestone) | ||
|
||
trainer.train() | ||
|
||
|
||
if __name__ == '__main__': | ||
run() | ||
|
||
# wandb.finish() | ||
|
||
# Incorporate GAN loss in DDPM training? | ||
# Incorporate GAN loss in UNET segmentation? | ||
# Maybe better if I don't use ema updates? | ||
# Use with other vqgan latent space (the one with more channels?) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters