From 315276b6c5690a3eee91839828bedc42e659e957 Mon Sep 17 00:00:00 2001 From: Virginia Date: Thu, 12 Dec 2024 09:45:06 +0000 Subject: [PATCH] Modification of metadata to remove generative package requirement, no longer necessary. On inference, modification of the entry point from save_jpg to run to allow for run to be called alone, and truncation of loading statements which are too long. Modification of the README to include command example changes. --- .../configs/inference.json | 8 +++++--- .../configs/metadata.json | 3 +-- .../docs/README.md | 10 +++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/models/cxr_image_synthesis_latent_diffusion_model/configs/inference.json b/models/cxr_image_synthesis_latent_diffusion_model/configs/inference.json index a45d0ff3..6578e3ea 100644 --- a/models/cxr_image_synthesis_latent_diffusion_model/configs/inference.json +++ b/models/cxr_image_synthesis_latent_diffusion_model/configs/inference.json @@ -45,7 +45,8 @@ "with_decoder_nonlocal_attn": false }, "load_autoencoder_path": "$@model_dir + '/autoencoder.pth'", - "load_autoencoder": "$@autoencoder_def.load_old_state_dict(torch.load(@load_autoencoder_path)) if bool(@load_old) else @autoencoder_def.load_state_dict(torch.load(@load_autoencoder_path))", + "load_autoencoder_func": "$@autoencoder_def.load_old_state_dict if bool(@load_old) else @autoencoder_def.load_state_dict", + "load_autoencoder": "$@load_autoencoder_func(torch.load(@load_autoencoder_path))", "autoencoder": "$@autoencoder_def.to(@device)", "diffusion_def": { "_target_": "monai.networks.nets.DiffusionModelUNet", @@ -76,7 +77,8 @@ "cross_attention_dim": 1024 }, "load_diffusion_path": "$@model_dir + '/diffusion_model.pth'", - "load_diffusion": "$@diffusion_def.load_old_state_dict(torch.load(@load_diffusion_path)) if bool(@load_old) else @diffusion_def.load_state_dict(torch.load(@load_diffusion_path))", + "load_diffusion_func": "$@diffusion_def.load_old_state_dict if bool(@load_old) else @diffusion_def.load_state_dict", + "load_diffusion": "$@load_diffusion_func(torch.load(@load_diffusion_path))", "diffusion": "$@diffusion_def.to(@device)", "scheduler": { "_target_": "monai.networks.schedulers.DDIMScheduler", @@ -103,6 +105,6 @@ "_requires_": "@create_output_dir", "output_dir": "@output_dir" }, - "save_jpg": "$@saver.save(@sample, @out_file)", + "run": "$@saver.save(@sample, @out_file)", "save": "$torch.save(@sample, @output_dir + '/' + @out_file + '.pt')" } diff --git a/models/cxr_image_synthesis_latent_diffusion_model/configs/metadata.json b/models/cxr_image_synthesis_latent_diffusion_model/configs/metadata.json index 020005e3..5c9f6596 100644 --- a/models/cxr_image_synthesis_latent_diffusion_model/configs/metadata.json +++ b/models/cxr_image_synthesis_latent_diffusion_model/configs/metadata.json @@ -9,7 +9,6 @@ "numpy_version": "1.22.4", "optional_packages_version": { "nibabel": "4.0.1", - "generative": "0.1.0", "transformers": "4.26.1" }, "task": "Chest X-ray image synthesis", @@ -26,7 +25,7 @@ "format": "magnitude", "modality": "CXR", "num_channels": 3, - "spatial_shape": [ + "spatial_shape": [77, 64, 64 ], diff --git a/models/cxr_image_synthesis_latent_diffusion_model/docs/README.md b/models/cxr_image_synthesis_latent_diffusion_model/docs/README.md index ac87910e..c0d90a0a 100644 --- a/models/cxr_image_synthesis_latent_diffusion_model/docs/README.md +++ b/models/cxr_image_synthesis_latent_diffusion_model/docs/README.md @@ -36,19 +36,19 @@ the image sticks to a given text input (the common range is between 1-21). Examples: ```shell -$ python -m monai.bundle run save_jpg --config_file configs/inference.json --prompt "Big right-sided pleural effusion" --guidance_scale 7.0 +$ python -m monai.bundle run --config_file configs/inference.json --prompt "Big right-sided pleural effusion" --guidance_scale 7.0 ``` ```shell -$ python -m monai.bundle run save_jpg --config_file configs/inference.json --prompt "Small right-sided pleural effusion" --guidance_scale 7.0 +$ python -m monai.bundle run --config_file configs/inference.json --prompt "Small right-sided pleural effusion" --guidance_scale 7.0 ``` ```shell -$ python -m monai.bundle run save_jpg --config_file configs/inference.json --prompt "Bilateral pleural effusion" --guidance_scale 7.0 +$ python -m monai.bundle run --config_file configs/inference.json --prompt "Bilateral pleural effusion" --guidance_scale 7.0 ``` ```shell -$ python -m monai.bundle run save_jpg --config_file configs/inference.json --prompt "Cardiomegaly" --guidance_scale 7.0 +$ python -m monai.bundle run --config_file configs/inference.json --prompt "Cardiomegaly" --guidance_scale 7.0 ``` ## Using a new version of the model @@ -58,7 +58,7 @@ to avoid the function load_old_state_dict being called instead of load_state_dic required to load the checkpoint from the original GenerativeModels repository. ```shell -$ python -m monai.bundle run save_jpg --config_file configs/inference.json --prompt "Pleural effusion." --guidance_scale 7.0 --load_old 0 +$ python -m monai.bundle run --config_file configs/inference.json --prompt "Pleural effusion." --guidance_scale 7.0 --load_old 0 ``` ## References