Package: medigan
A modular package for automated synthetic data generation.:x:Problem 1:Data scarcity in medical imaging.:x:Problem 2:Scarcity of readily reusable generative models in medical imaging.:white_check_mark:Solution:medigandataset sharing via generative models :gift:data augmentation :gift:domain adaptation :gift:synthetic data evaluation method testing with multi-model datasets :gift:mediganprovides functions for sharing and re-use of pretrained generative models in medical imaging.Features:Instead of training your own, use one a generative models frommediganto generate synthetic data.Search and find a model inmediganusing search terms (e.g. "Mammography" or "Endoscopy").Contribute your own generative model tomediganto increase its visibility, re-use, and impact.Available modelsOutput typeModalityModel typeOutput sizeBase datasetOutput examplesmodel_idHosted onReferenceBreast Calcificationmammographydcgan128x128Inbreast00001_DCGAN_MMG_CALC_ROIZenodo (5187714)Breast Massmammographydcgan128x128Optimam00002_DCGAN_MMG_MASS_ROIZenodo (5188557)Alyafi et al (2019)Breast Density Transfermammographycyclegan1332x800BCDR00003_CYCLEGAN_MMG_DENSITY_FULLZenodo (5547263)Breast Mass with Maskmammographypix2pix256x256BCDR00004_PIX2PIX_MMG_MASSES_W_MASKSZenodo (7093759)Breast Massmammographydcgan128x128BCDR00005_DCGAN_MMG_MASS_ROIZenodo (6555188)Szafranowska et al (2022)Breast Massmammographywgan-gp128x128BCDR00006_WGANGP_MMG_MASS_ROIZenodo (6554713)Szafranowska et al (2022)Brain Tumors on Flair, T1, T1c, T2 with Masksbrain MRIinpaint GAN256x256BRATS 201800007_INPAINT_BRAIN_MRIZenodo (7041737)Kim et al (2020)Breast Mass (Mal/Benign)mammographyc-dcgan128x128CBIS-DDSM00008_C-DCGAN_MMG_MASSESZenodo (6647349)Polyp with Maskendoscopypggan256x256HyperKvasir00009_PGGAN_POLYP_PATCHES_W_MASKSZenodo (6653743)Thambawita et al (2022)Polyp with Maskendoscopyfastgan256x256HyperKvasir00010_FASTGAN_POLYP_PATCHES_W_MASKSZenodo (6660711)Thambawita et al (2022)Polyp with Maskendoscopysingan≈250x250HyperKvasir00011_SINGAN_POLYP_PATCHES_W_MASKSZenodo (6667944)Thambawita et al (2022)Breast Mass (Mal/Benign)mammographyc-dcgan128x128BCDR00012_C-DCGAN_MMG_MASSESZenodo (6755693)Breast Density Transfer MLOmammographycyclegan1332x800OPTIMAM00013_CYCLEGAN_MMG_DENSITY_OPTIMAM_MLOZenodo (6818095)Breast Density Transfer CCmammographycyclegan1332x800OPTIMAM00014_CYCLEGAN_MMG_DENSITY_OPTIMAM_CCZenodo (6818103)Breast Density Transfer MLOmammographycyclegan1332x800CSAW00015_CYCLEGAN_MMG_DENSITY_CSAW_MLOZenodo (6818105)Breast Density Transfer CCmammographycyclegan1332x800CSAW00016_CYCLEGAN_MMG_DENSITY_CSAW_CCZenodo (6818107)Lung Noduleschest x-raydcgan128x128NODE2100017_DCGAN_XRAY_LUNG_NODULESZenodo (6943691)Lung Noduleschest x-raywgan-gp128x128NODE2100018_WGANGP_XRAY_LUNG_NODULESZenodo (6943761)Chest Xray Imageschest x-raypggan1024x1024ChestX-ray1400019_PGGAN_CHEST_XRAYZenodo (6943803)Chest Xray Imageschest x-raypggan1024x1024ChestX-ray1400020_PGGAN_CHEST_XRAYZenodo (7046280)Segal et al (2021)Brain T1-T2 MRI Modality Transferbrain MRIcyclegan224x192CrossMoDA 202100021_CYCLEGAN_BRAIN_MRI_T1_T2Zenodo (7074555)Joshi et al (2022)Model information can be found in themodel documentationand in theglobal.jsonmodel metadata.InstallationTo install the current release, simply run:pipinstallmediganGetting StartedExamples and notebooks are located atexamplesfolderDocumentation is available atmedigan.readthedocs.ioGeneration exampleDCGANCreate mammography calcification images using DCGAN model# import medigan and initialize GeneratorsfrommediganimportGeneratorsgenerators=Generators()# generate 6 samples with model 1 (00001_DCGAN_MMG_CALC_ROI).# Also, auto-install required model dependencies.generators.generate(model_id=1,num_samples=6,install_dependencies=True)CYCLEGANCreate mammograms translated from Low-to-High Breast Density using CYCLEGAN modelfrommediganimportGeneratorsgenerators=Generators()# model 3 is "00003_CYCLEGAN_MMG_DENSITY_FULL"generators.generate(model_id=3,num_samples=1)→Search ExampleSearch for amodelinside medigan using keywords# import medigan and initialize GeneratorsfrommediganimportGeneratorsgenerators=Generators()# list all modelsprint(generators.list_models())# search for models that have specific keywords in their configkeywords=['DCGAN','Mammography','BCDR']results=generators.find_matching_models_by_values(keywords)Get Model as DataloaderWe can directly receive atorch.utils.data.DataLoaderobject for any of medigan's generative models.frommediganimportGeneratorsgenerators=Generators()# model 4 is "00004_PIX2PIX_MMG_MASSES_W_MASKS"dataloader=generators.get_as_torch_dataloader(model_id=4,num_samples=3)Visualize the contents of the dataloader.frommatplotlibimportpyplotaspltimportnumpyasnpplt.figure()# subplot with 2 rows and len(dataloader) columnsf,img_array=plt.subplots(2,len(dataloader))forbatch_idx,data_dictinenumerate(dataloader):sample=np.squeeze(data_dict.get("sample"))mask=np.squeeze(data_dict.get("mask"))img_array[0][batch_idx].imshow(sample,interpolation='nearest',cmap='gray')img_array[1][batch_idx].imshow(mask,interpolation='nearest',cmap='gray')plt.show()Visualize A ModelWith our interface, it is possible to generate sample by manually setting the conditional inputs or latent vector values. The sample is updated in realtime, so it's possible to observe how the images changes when the parameters are modified. The visualization is available only for models with accessible input latent vector. Depending on a model, a conditional input may be also available or synthetic segmentation mask.from medigan import Generators

generators = Generators()
# model 10 is "00010_FASTGAN_POLYP_PATCHES_W_MASKS"
generators.visualize(10)Contribute A ModelCreate aninit.pyfile in your model's root folder.Next, run the following code to contribute your model to medigan.Your model will be stored onZenodo.Also, a Githubissuewill be created to add your model's metadata to medigan'sglobal.json.To do so, please provide a github access token (get one here) and a zenodo access token (get one here), as shown below. After creation, the zenodo access token may take a few minutes before being recognized in zenodo API calls.frommediganimportGeneratorsgenerators=Generators()# Contribute your modelgenerators.contribute(model_id="00100_YOUR_MODEL",# assign an IDinit_py_path="path/ending/with/__init__.py",model_weights_name="10000",model_weights_extension=".pt",generate_method_name="generate",# in __init__.pydependencies=["numpy","torch"],creator_name="YOUR_NAME",creator_affiliation="YOUR_AFFILIATION",zenodo_access_token='ZENODO_ACCESS_TOKEN',github_access_token='GITHUB_ACCESS_TOKEN',Thank you for your contribution!You will soon receive a reply in the Githubissuethat you created for your model by runninggenerators.contribute().Contributions in GeneralWe welcome contributions to medigan. Please send us an email or read thecontributing guidelinesregarding contributing to the medigan project.