GithubHelp home page GithubHelp logo

ganslate-team / ganslate Goto Github PK

View Code? Open in Web Editor NEW
32.0 4.0 3.0 95 MB

Simple and extensible GAN image-to-image translation framework. Supports natural and medical images.

Home Page: https://ganslate.readthedocs.io

License: Other

Python 98.82% Shell 0.92% Dockerfile 0.26%
gan image-to-image-translation cyclegan pix2pix revgan cut contrastive-unpaired-translation natural-images medical-images image-translation

ganslate's Introduction

DOI

Python package

ganslate - a simple and extensible GAN image-to-image translation framework

For comprehensive documentation, visit: https://ganslate.readthedocs.io/en/latest/

Note: The documentation is still in progress! Suggestions and contributions are welcome!

ganslate is a PyTorch framework which aims to make GAN image-to-image translation more accessible to both beginner and advanced project with:

Features

  • 2D and 3D support
  • Mixed precision
  • Distributed training
  • Tensorboard and Weights&Biases logging
  • Natural and medical image support
  • A range of generator and discriminator architectures

Available GANs

Projects

ganslate was used in:

  • Project 1
  • Project 2

Citation

If you used ganslate in your project, please cite:

@software{ibrahim_hadzic_2021_5494572,
  author       = {Ibrahim Hadzic and
                  Suraj Pai and
                  Chinmay Rao and
                  Jonas Teuwen},
  title        = {ganslate-team/ganslate: Initial public release},
  month        = sep,
  year         = 2021,
  publisher    = {Zenodo},
  version      = {v0.1.0},
  doi          = {10.5281/zenodo.5494572},
  url          = {https://doi.org/10.5281/zenodo.5494572}
}

ganslate's People

Contributors

cnmy-ro avatar github-actions[bot] avatar ibro45 avatar jonasteuwen avatar surajpaib avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ganslate's Issues

Add methods to ignore terminal slices in the CBCT FOV

This is important to handle the case when terminal slices of a CBCT scan have artifacts or incomplete anatomical representation. This can potentially corrupt training and should ideally be removed in the dataloader pre-registration.

Possible methods:

  • Manually ignore some percentile of slices
  • Seems to be the case in the NKI dataset that the full FOV can be identified using an almost perfect circle - owing to the fan beam FOV, maybe this can be leveraged to ignore the slices.

Separate the z-score function

Separate the current z-score function so that :

  • one is is general, per-datapoint, normalization
  • another one for per-slice normalization based on stats calculated from the whole volume

Loss masking for certain values such as out of bounds

Proposed solution:

The loss functions must be modified to have the loss reduction to none so that per voxel loss is obtained. Once this is obtained,

  1. Create a mask based on matching with the certain value for the input image.
  2. Used masked_select to mask the loss to obtain a 1D tensor: https://pytorch.org/docs/stable/generated/torch.masked_select.html
  3. Reduce this 1D tensor obtaining an appropriate loss.

This loss masking needs to go into L1, SSIM and all the GAN losses.

No permissions to push into origin branch

Hi ~ friends ~ I write some code:

1.body_mask.py:if apply_bound is False,output the original size of image

2.cut_lung_from_background.py:It can cut lung from the background stable.

But I can not push to origin/zhixiang branch.Maybe its permissions issue?

Code are in here now:
https://github.com/ZhixiangWang-CN/Radiomics/blob/master/ImageSegmentation/body_mask.py
https://github.com/ZhixiangWang-CN/Radiomics/blob/master/ImageSegmentation/cut_lung_from_background.py

Inference script

Implement an inference script along with necessary config that will be dataloader and model agnostic.

Simplified Inference Architecture

Usecases:

  1. The Inferer can be called as Validator during training

  2. A separate inference config might not be necessary as most of the parameters are defined in train_config.yaml. Needed parameters for inference should be made mandatory as CLI arguments or fed through config. However, a mandatory separate config should not be needed. A design decision on what parameters need to provided need to be made.

    if cli.config:
        inference_conf = OmegaConf.load(cli.pop("config"))
        inference_conf = OmegaConf.merge(inference_conf, cli)
    else:
        inference_conf = cli

    # Fetch the config that was used during training of this specific run
    train_conf = Path(inference_conf.logging.checkpoint_dir) / "training_config.yaml"

Maybe conf here points to train_conf itself and separate inference_conf and train_conf are not needed

Brainstorm about flags in the EvalConfig

Does this need to inherit from dataset in the TrainConfig?

There could be cases where you want to run evaluation with different parameters in the dataset -> For example, with bound to avoid checking out of patient body areas although the training still includes it. For now, these are two separate configs and care should be taken to define it as you need it.

Test

project_dir: "./projects/nki_cervix_cbct_to_ct"
use_cuda: True
n_iters: 200000
n_iters_decay: 0
batch_size: 1

logging:
checkpoint_dir: ./checkpoints/cbct_ex3/
wandb:
project: "NKI_CBCT_CT"
log_freq: 50
checkpoint_freq: 10000

dataset:
name: "CBCTtoCTDataset"
root: /home/rt/workspace_suraj/cervix_resampled
hounsfield_units_range: [-1024, 2048]
num_workers: 4
patch_size: [32, 32, 32]

gan:
name: "PiCycleGAN"

generator:
name: Vnet3D
in_channels: 1
use_memory_saving: False
use_inverse: True
is_separable: False
down_blocks: [2, 2, 3]
up_blocks: [3, 3, 3]

discriminator:
name: "PatchGAN3D"
n_layers: 2
in_channels: 1

optimizer:
lambda_A: 25.0
lambda_B: 25.0
lambda_identity: 0.0
lambda_inverse: 0.0
proportion_ssim: 0.84
lr_D: 0.0001
lr_G: 0.0002

metrics calculation not working for batch_size > 1

@surajpaib the ValTest metric calculation isn't compatible with bigger than 1 batch size. Problem is that the batch dimension is squeezed, which works fine for BS=1, but not otherwise. the scikit metrics don't operate on batches, so it'll be necessary to loop over the batch and average the metrics

https://github.com/Maastro-CDS-Imaging-Group/midaGAN/blob/06d6c419fca81327008d2a2cdbf92f126cff1c19/midaGAN/utils/metrics/val_test_metrics.py#L14
https://github.com/Maastro-CDS-Imaging-Group/midaGAN/blob/06d6c419fca81327008d2a2cdbf92f126cff1c19/midaGAN/utils/metrics/val_test_metrics.py#L64
Also, is this slice num alright for regular images or? @surajpaib

Decide if metrics should be masked with patient body.

Case: Due to the masking of patient body while computing metrics, a lot of values are zero skewing the true metric values. Decide if while taking the mean of the metric, the mask should be applied over the elements.

Weights and Biases throws login error

While running on a new machine, weights and biases throws a login error if results are chosen to not be visualized. This needs to be fixed. Maybe upgrade wandb version

Val-Test metrics need to work accurately across batches and across data points

With the current implementation if the batch size is 2 and data points are 5:

The final averaging is done in this way,
(average of first batch metrics with 2 data points + average of second batch metrics with 2 data points + third batch metric with only one data point ) / 3

For batch size 1, the implementation works this way,
( first data point metric + .... + 5th data point metric)/5

These values are not synonymous and need to be fixed so that the same values are given no matter what the implementation detail.

empty out __init__.py's

__init__.pys should contain no code except for necessary imports to be able to access some modules more easily

metrics all over the place in GAN implementations

see if it can be improved so that is general and that it is a single call, preferably in BaseGAN, and takes care if it's a cycle-consistency model or not and so on.

rn the problem is that the calculation of metrics is located in different places in GANs (see CycleGAN, RevGAN), which makes it not very readable and a pain to remember and place properly in new GAN implementations.

Better logging names for losses, metric, G and D, and visuals

Chinmay Rao 8:14 PM
I have some suggestions. Let me know what you think. First, regarding the naming conventions of the networks. I found them a bit confusing.
From the current code, G_A is the generator for A->B, for example. Maybe, we can change it to G_AB.
Also currently, D_A seems to be the discriminator that takes real_B and fake_B as inputs (i.e. domain B). Maybe, we can instead call it D_B, since it works in domain B. This would be similar as in the paper - domain Y and D_Y
If we can change the names, then we can have naming conventions for loggable (metrics, losses, predictions) based on them (edited)

Ibrahim Hadzic 8:16 PM
i agree. This D_A think must have been a mistake in naming i guess, which just propagated to everything
8:16
G
8:16
G_AB makes perfect sense
8:16
also, do you think these names as such are good
8:17
or would you prefer generator_ab instead of G_AB
8:17
i think that the latter, while not being great regarding the python conventions, is still more easily readable
8:17
in this case
๐Ÿ‘
1

Chinmay Rao 8:17 PM
I agree. IMO, G_AB is good
New
8:21
For the loggable stuff -------------------------
Maybe have a naming format like (ignore the spaces) ==> mode - type - specific_component
For example, I'd suggest the following changes -----------------------------------
Loggable losses:
loss_G_A --> train-loss-adv_G_AB
loss_D_A --> train-loss-adv_D_B
loss_cycle_A --> train-loss-cycle_ABA
2. Logable predictions:
Train D_A_fake --> train-pred-D_A_fake
3. Loggable metrics:
mse --> val-mse-A (i.e. MSE between fake A and reference A)

Ibrahim Hadzic 8:28 PM
i would actually leave out "train" from train-loss-adv_G_AB but otherwise yes

Ibrahim Hadzic 8:30 PM
for the point 3, i agree with "val" but I'm wondering about "A". We're calculating only A->B and a lot of stuff is done that way in the framework only for A->B, like testing let's say, because B->A is gonna be the case only for cycle-consistency models
๐Ÿ‘
1

1 reply
Today at 8:32 PMView thread

Ibrahim Hadzic 8:31 PM
so you have a prob with generalizability
๐Ÿ‘
1

8:31
but if you really need to do B->A, you could manually take care of it lets say, but that's not elegant

Enforce only image_size or patch_size

Is it necessary to enforce that the dataset uses image_size (instead of load_size) or patch_size to indicate what's the size of the inputs? What would benefit from it?

multi_dataset breaks interpolation

E.g.

    
val:
    freq: 1000

    multi_dataset:
        lungs:
            name: "CBCTtoCTValTestDataset"
            root: "/workspace/train_val/val"
        
        phantoms:
            name: "CBCTtoCTValTestDataset"
            root: "/workspace/train_val/val_phantom"

test:
    dataset: "${val.multi_dataset}"
    sliding_window: "${val.sliding_window}"

build_loader selects a single dataset from multi_dataset, assigns it to dataset and sets multi_dataset to None. This breaks interpolation when it's referring to multi_dataset.

Error:

omegaconf.errors.ConfigKeyError: str interpolation key 'val.multi_dataset' not found               
        full_key: test.dataset                                                                                                   
        reference_type=Optional[Dict[Union[str, Enum], Any]]                                                                      
        object_type=dict 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.