Project-MONAI / GenerativeModels

MONAI Generative Models makes it easy to train, evaluate, and deploy generative models and related applications
Apache License 2.0
619 stars 87 forks source link

Brain Image Generation DDIM Scheduler Instantiation Error #395

Closed 17shiraz closed 1 year ago

17shiraz commented 1 year ago

Hi, I am an undergraduate student currently experimenting with your models to improve my understanding of LDMs.

Running the following command as suggested by @Warvito to generate sample brain images per this folder

set PYTHONPATH=$PYTHONPATH:"<path to 'GenerativeModels'>"

python -m monai.bundle run save_nii --config_file configs/inference.json --gender 1.0 --age 0.7 --ventricular_vol 0.7 --brain_vol 0.5

returns the following error on Windows:

C:\Users\mhuot\Desktop\MONAI\GenerativeModels\model-zoo\models\brain_image_synthesis_latent_diffusion_model>python -m monai.bundle run save_nii --config_file configs/inference.json --gender 1.0 --age 0.7 --ventricular_vol 0.7 --brain_vol 0.5
 - INFO - --- input summary of monai.bundle.scripts.run ---
 - INFO - > run_id: 'save_nii'
 - INFO - > config_file: 'configs/inference.json'
 - INFO - > gender: 1.0
 - INFO - > age: 0.7
 - INFO - > ventricular_vol: 0.7
 - INFO - > brain_vol: 0.5
 - INFO - ---

 - INFO - Setting logging properties based on config: configs/logging.conf.
Traceback (most recent call last):
  File "C:\Users\mhuot\anaconda3\lib\site-packages\monai\utils\module.py", line 260, in instantiate
    return component(**kwargs)
  File "C:\Users\mhuot\anaconda3\lib\site-packages\generative\networks\schedulers\ddim.py", line 86, in __init__
    super().__init__(num_train_timesteps, schedule, **schedule_args)
  File "C:\Users\mhuot\anaconda3\lib\site-packages\generative\networks\schedulers\scheduler.py", line 152, in __init__
    noise_sched = NoiseSchedules[schedule](**schedule_args)
TypeError: _linear_beta() got an unexpected keyword argument 'beta_schedule'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\mhuot\anaconda3\lib\site-packages\monai\bundle\config_item.py", line 292, in instantiate
    return instantiate(modname, mode, **args)
  File "C:\Users\mhuot\anaconda3\lib\site-packages\monai\utils\module.py", line 270, in instantiate
    raise RuntimeError(
RuntimeError: Failed to instantiate component 'generative.networks.schedulers.DDIMScheduler' with kwargs: {'beta_start': 0.0015, 'beta_end': 0.0205, 'num_train_timesteps': 1000, 'beta_schedule': 'scaled_linear', 'clip_sample': False}
 set '_mode_=debug' to enter the debugging mode.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\mhuot\anaconda3\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\mhuot\anaconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\mhuot\anaconda3\lib\site-packages\monai\bundle\__main__.py", line 30, in <module>
    fire.Fire()
  File "C:\Users\mhuot\anaconda3\lib\site-packages\fire\core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "C:\Users\mhuot\anaconda3\lib\site-packages\fire\core.py", line 475, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "C:\Users\mhuot\anaconda3\lib\site-packages\fire\core.py", line 691, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "C:\Users\mhuot\anaconda3\lib\site-packages\monai\utils\deprecate_utils.py", line 223, in _wrapper
    return func(*args, **kwargs)
  File "C:\Users\mhuot\anaconda3\lib\site-packages\monai\bundle\scripts.py", line 695, in run
    workflow.run()
  File "C:\Users\mhuot\anaconda3\lib\site-packages\monai\bundle\workflows.py", line 262, in run
    return self._run_expr(id=self.run_id)
  File "C:\Users\mhuot\anaconda3\lib\site-packages\monai\bundle\workflows.py", line 296, in _run_expr
    return self.parser.get_parsed_content(id, **kwargs) if id in self.parser else None
  File "C:\Users\mhuot\anaconda3\lib\site-packages\monai\bundle\config_parser.py", line 291, in get_parsed_content
    return self.ref_resolver.get_resolved_content(id=id, **kwargs)
  File "C:\Users\mhuot\anaconda3\lib\site-packages\monai\bundle\reference_resolver.py", line 190, in get_resolved_content
    return self._resolve_one_item(id=id, **kwargs)
  File "C:\Users\mhuot\anaconda3\lib\site-packages\monai\bundle\reference_resolver.py", line 160, in _resolve_one_item
    self._resolve_one_item(id=d, waiting_list=waiting_list, **kwargs)
  File "C:\Users\mhuot\anaconda3\lib\site-packages\monai\bundle\reference_resolver.py", line 160, in _resolve_one_item
    self._resolve_one_item(id=d, waiting_list=waiting_list, **kwargs)
  File "C:\Users\mhuot\anaconda3\lib\site-packages\monai\bundle\reference_resolver.py", line 160, in _resolve_one_item
    self._resolve_one_item(id=d, waiting_list=waiting_list, **kwargs)
  [Previous line repeated 1 more time]
  File "C:\Users\mhuot\anaconda3\lib\site-packages\monai\bundle\reference_resolver.py", line 168, in _resolve_one_item
    self.resolved_content[id] = item.instantiate() if kwargs.get("instantiate", True) else item
  File "C:\Users\mhuot\anaconda3\lib\site-packages\monai\bundle\config_item.py", line 294, in instantiate
    raise RuntimeError(f"Failed to instantiate {self}.") from e
RuntimeError: Failed to instantiate {'_target_': 'generative.networks.schedulers.DDIMScheduler', '_requires_': [<All keys matched successfully>, <All keys matched successfully>], 'beta_start': 0.0015, 'beta_end': 0.0205, 'num_train_timesteps': 1000, 'beta_schedule': 'scaled_linear', 'clip_sample': False}.

Any help or tips would be appreciated.

Warvito commented 1 year ago

Thank you for pointing that out. It is a bug introduced from the recent scheduler refactoring #285 . The code for the model zoo content was not updated as it should be. We will work on a fix for this.

yiheng-wang-nv commented 1 year ago

Hi @Can-Zhao , I think in model zoo, two bundles also need to update with new API