-
Notifications
You must be signed in to change notification settings - Fork 101
Mednist GAN Bundle #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b58d650
Adding GAN bundle
ericspod 0c879f9
Updates
ericspod 58141f0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2585e5d
Updates
ericspod 12091c0
Merge branch 'dev' into mednist_gan
ericspod 9dbc410
Documentation update
ericspod 72c307d
Add schema
ericspod 175c0f5
Updates
ericspod 36b4cdb
Merge branch 'dev' into mednist_gan
ericspod 506f9fc
Merge branch 'dev' into mednist_gan
ericspod c1ba909
Updating license
ericspod 111b7f6
Merge branch 'dev' into mednist_gan
yiheng-wang-nv 2b00802
Excluding bundle from verification
ericspod c947b36
Merge branch 'dev' into mednist_gan
ericspod 1b24c53
Merge branch 'dev' into mednist_gan
ericspod e6293a2
Merge branch 'dev' into mednist_gan
ericspod a41cf79
Merge branch 'dev' into mednist_gan
yiheng-wang-nv 22884ca
Updated to use generator schema
ericspod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,88 @@ | ||
| { | ||
| "imports": [ | ||
| "$import glob" | ||
| ], | ||
| "device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')", | ||
| "ckpt_path": "$@bundle_root + '/models/model.pt'", | ||
| "output_dir": "./outputs", | ||
| "latent_size": 64, | ||
| "num_samples": 10, | ||
| "network_def": { | ||
| "_target_": "Generator", | ||
| "latent_shape": "@latent_size", | ||
| "start_shape": [ | ||
| 64, | ||
| 8, | ||
| 8 | ||
| ], | ||
| "channels": [ | ||
| 32, | ||
| 16, | ||
| 8, | ||
| 1 | ||
| ], | ||
| "strides": [ | ||
| 2, | ||
| 2, | ||
| 2, | ||
| 1 | ||
| ] | ||
| }, | ||
| "network": "$@network_def.to(@device)", | ||
| "dataset": { | ||
| "_target_": "Dataset", | ||
| "data": "$[torch.rand(@latent_size) for i in range(@num_samples)]" | ||
| }, | ||
| "dataloader": { | ||
| "_target_": "DataLoader", | ||
| "dataset": "@dataset", | ||
| "batch_size": 1, | ||
| "shuffle": false, | ||
| "num_workers": 0 | ||
| }, | ||
| "inferer": { | ||
| "_target_": "SimpleInferer" | ||
| }, | ||
| "postprocessing": { | ||
| "_target_": "Compose", | ||
| "transforms": [ | ||
| { | ||
| "_target_": "Activationsd", | ||
| "keys": "pred", | ||
| "sigmoid": true | ||
| }, | ||
| { | ||
| "_target_": "SaveImaged", | ||
| "keys": "pred", | ||
| "output_dir": "@output_dir", | ||
| "output_ext": "png", | ||
| "separate_folder": false, | ||
| "scale": 255, | ||
| "output_dtype": "$np.uint8", | ||
| "meta_key_postfix": null | ||
| } | ||
| ] | ||
| }, | ||
| "handlers": [ | ||
| { | ||
| "_target_": "CheckpointLoader", | ||
| "load_path": "@ckpt_path", | ||
| "load_dict": { | ||
| "model": "@network" | ||
| } | ||
| } | ||
| ], | ||
| "evaluator": { | ||
| "_target_": "SupervisedEvaluator", | ||
| "device": "@device", | ||
| "val_data_loader": "@dataloader", | ||
| "network": "@network", | ||
| "inferer": "@inferer", | ||
| "postprocessing": "@postprocessing", | ||
| "prepare_batch": "$lambda batchdata, *_,**__: (batchdata.to(@device),None,(),{})", | ||
| "val_handlers": "@handlers" | ||
| }, | ||
| "inferring": [ | ||
|
Nic-Ma marked this conversation as resolved.
|
||
| "$@evaluator.run()" | ||
| ] | ||
| } | ||
This file contains hidden or 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,21 @@ | ||
| [loggers] | ||
| keys=root | ||
|
|
||
| [handlers] | ||
| keys=consoleHandler | ||
|
|
||
| [formatters] | ||
| keys=fullFormatter | ||
|
|
||
| [logger_root] | ||
| level=INFO | ||
| handlers=consoleHandler | ||
|
|
||
| [handler_consoleHandler] | ||
| class=StreamHandler | ||
| level=INFO | ||
| formatter=fullFormatter | ||
| args=(sys.stdout,) | ||
|
|
||
| [formatter_fullFormatter] | ||
| format=%(asctime)s - %(name)s - %(levelname)s - %(message)s |
This file contains hidden or 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,60 @@ | ||
| { | ||
| "schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_generator_20220718.json", | ||
| "version": "0.1.0", | ||
|
yiheng-wang-nv marked this conversation as resolved.
|
||
| "changelog": { | ||
| "0.1.0": "Initial version" | ||
| }, | ||
| "monai_version": "0.9.0", | ||
| "pytorch_version": "1.10.0", | ||
| "numpy_version": "1.21.0", | ||
| "optional_packages_version": { | ||
| "pytorch-ignite": "0.4.8", | ||
| "pillow": "8.4.0" | ||
| }, | ||
| "task": "Generate random hand images from the MedNIST dataset", | ||
| "description": "This example of a GAN generator produces hand xray images like those in the MedNIST dataset", | ||
| "authors": "MONAI Team", | ||
| "copyright": "Copyright (c) MONAI Consortium", | ||
| "intended_use": "This is an example of a GAN with generator discriminator networks using MONAI, suitable for demonstration purposes only.", | ||
| "data_source": "MedNIST dataset kindly made available by Dr. Bradley J. Erickson M.D., Ph.D. (Department of Radiology, Mayo Clinic)", | ||
| "data_type": "jpeg", | ||
| "network_data_format": { | ||
| "inputs": { | ||
| "latent": { | ||
|
yiheng-wang-nv marked this conversation as resolved.
|
||
| "type": "tuples", | ||
| "format": "latent", | ||
| "num_channels": 0, | ||
| "spatial_shape": [ | ||
| 64 | ||
|
Nic-Ma marked this conversation as resolved.
|
||
| ], | ||
| "dtype": "float32", | ||
| "value_range": [ | ||
| 0, | ||
| 1 | ||
| ], | ||
| "is_patch_data": false, | ||
| "channel_def": {} | ||
| } | ||
| }, | ||
| "outputs": { | ||
| "pred": { | ||
| "type": "image", | ||
| "format": "magnitude", | ||
| "num_channels": 1, | ||
| "spatial_shape": [ | ||
| 64, | ||
| 64 | ||
| ], | ||
| "dtype": "float32", | ||
| "value_range": [ | ||
| 0, | ||
| 1 | ||
| ], | ||
| "is_patch_data": false, | ||
| "channel_def": { | ||
| "0": "image" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,164 @@ | ||
| { | ||
| "imports": [ | ||
| "$from functools import partial", | ||
| "$import glob", | ||
| "$from losses import discriminator_loss", | ||
| "$from losses import generator_loss" | ||
| ], | ||
| "device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')", | ||
| "ckpt_path": "$@bundle_root + '/models/model.pt'", | ||
| "dataset_dir": "./MedNIST/Hand", | ||
| "datalist": "$list(sorted(glob.glob(@dataset_dir + '/*.jpeg')))", | ||
| "latent_size": 64, | ||
| "discriminator": { | ||
| "_target_": "Discriminator", | ||
| "in_shape": [ | ||
| 1, | ||
| 64, | ||
| 64 | ||
| ], | ||
| "channels": [ | ||
| 8, | ||
| 16, | ||
| 32, | ||
| 64, | ||
| 1 | ||
| ], | ||
| "strides": [ | ||
| 2, | ||
| 2, | ||
| 2, | ||
| 2, | ||
| 1 | ||
| ], | ||
| "num_res_units": 1, | ||
| "kernel_size": 5 | ||
| }, | ||
| "generator": { | ||
| "_target_": "Generator", | ||
| "latent_shape": "@latent_size", | ||
| "start_shape": [ | ||
| 64, | ||
| 8, | ||
| 8 | ||
| ], | ||
| "channels": [ | ||
| 32, | ||
| 16, | ||
| 8, | ||
| 1 | ||
| ], | ||
| "strides": [ | ||
| 2, | ||
| 2, | ||
| 2, | ||
| 1 | ||
| ] | ||
| }, | ||
| "dnetwork": "$@discriminator.apply(monai.networks.normal_init).to(@device)", | ||
| "gnetwork": "$@generator.apply(monai.networks.normal_init).to(@device)", | ||
| "preprocessing": { | ||
| "_target_": "Compose", | ||
| "transforms": [ | ||
| { | ||
| "_target_": "LoadImaged", | ||
| "keys": "reals" | ||
| }, | ||
| { | ||
| "_target_": "AddChanneld", | ||
| "keys": "reals" | ||
| }, | ||
| { | ||
| "_target_": "ScaleIntensityd", | ||
| "keys": "reals" | ||
| }, | ||
| { | ||
| "_target_": "RandRotated", | ||
| "keys": "reals", | ||
| "range_x": "$np.pi/12", | ||
| "prob": 0.5, | ||
| "keep_size": true | ||
| }, | ||
| { | ||
| "_target_": "RandFlipd", | ||
| "keys": "reals", | ||
| "spatial_axis": 0, | ||
| "prob": 0.5 | ||
| }, | ||
| { | ||
| "_target_": "RandZoomd", | ||
| "keys": "reals", | ||
| "min_zoom": 0.9, | ||
| "max_zoom": 1.1, | ||
| "prob": 0.5 | ||
| }, | ||
| { | ||
| "_target_": "EnsureTyped", | ||
| "keys": "reals" | ||
| } | ||
| ] | ||
| }, | ||
| "real_dataset": { | ||
| "_target_": "CacheDataset", | ||
| "data": "$[{'reals': i} for i in @datalist]", | ||
| "transform": "@preprocessing" | ||
| }, | ||
| "real_dataloader": { | ||
| "_target_": "DataLoader", | ||
| "dataset": "@real_dataset", | ||
| "batch_size": 600, | ||
| "shuffle": true, | ||
| "num_workers": 12 | ||
| }, | ||
| "doptimizer": { | ||
| "_target_": "torch.optim.Adam", | ||
| "params": "$@dnetwork.parameters()", | ||
| "lr": 0.0002, | ||
| "betas": [ | ||
| 0.5, | ||
| 0.999 | ||
| ] | ||
| }, | ||
| "goptimizer": { | ||
| "_target_": "torch.optim.Adam", | ||
| "params": "$@gnetwork.parameters()", | ||
| "lr": 0.0002, | ||
| "betas": [ | ||
| 0.5, | ||
| 0.999 | ||
| ] | ||
| }, | ||
| "handlers": [ | ||
| { | ||
| "_target_": "CheckpointSaver", | ||
| "save_dir": "$@bundle_root + '/models'", | ||
| "save_dict": { | ||
| "model": "@gnetwork" | ||
| }, | ||
| "save_interval": 0, | ||
| "save_final": true, | ||
| "epoch_level": true | ||
| } | ||
| ], | ||
| "trainer": { | ||
| "_target_": "GanTrainer", | ||
| "device": "@device", | ||
| "max_epochs": 50, | ||
| "train_data_loader": "@real_dataloader", | ||
| "g_network": "@gnetwork", | ||
| "g_optimizer": "@goptimizer", | ||
| "g_loss_function": "$partial(generator_loss, disc_net=@dnetwork)", | ||
| "d_network": "@dnetwork", | ||
| "d_optimizer": "@doptimizer", | ||
| "d_loss_function": "$partial(discriminator_loss, disc_net=@dnetwork)", | ||
| "d_train_steps": 5, | ||
| "g_update_latents": true, | ||
| "latent_shape": "@latent_size", | ||
| "key_train_metric": "$None", | ||
| "train_handlers": "@handlers" | ||
| }, | ||
| "training": [ | ||
| "$@gnetwork.conv.add_module('activation', torch.nn.Sigmoid())", | ||
|
Nic-Ma marked this conversation as resolved.
|
||
| "$@trainer.run()" | ||
| ] | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.