其实我一直知道vscode可以再命令行下进行debug。
比如
python aaa.py --bb=1 --cc=2
以前的做法是 去aaa.py 写死bb和cc
然后直接debug。
直到今天我遇到这个:
hydra
@hydra.main(version_base=None, config_name='/home/justin/Desktop/code/python_project/WASB-SBDT-main/src', config_path='configs')
def main(cfg: DictConfig
):# 进这个方法的时候,cfg里面以及把配置都放到字典了,但我不理解的是,为什么有runner 这个二维的dict存在@todoprint(OmegaConf.to_yaml(cfg))print(cfg)if cfg['output_dir'] is None:cfg['output_dir'] = HydraConfig.get().run.dirmkdir_if_missing(cfg['output_dir'])print("---------------",cfg)runner = select_runner(cfg)runner.run()
我不知道他是如何传进来的参数。
python main.py --config-name=eval --model-path=xxxx
就更加不知道如何写死了。
.vscode
所以要这样处理:
.task
{"version": "2.0.0","tasks": [{"label": "Run Python Script","type": "shell","command": "python","args": ["src/main.py","--config-name=eval","dataset=basketball", "model=wasb", "detector.model_path=../wasb_basketball_best.pth.tar",],"group": {"kind": "build","isDefault": true},"problemMatcher": []}]
}
{"version": "0.2.0","configurations": [{"name": "Python: Main Debug","type": "python","request": "launch","program": "${workspaceFolder}/src/main.py","args": ["--config-name=eval", "dataset=basketball", "model=wasb", "detector.model_path=../wasb_basketball_best.pth.tar"],"console": "integratedTerminal"}]
}
args 写上你自己的参数
然后直接f5调试即可。