在使用vscode调试python工程时,一些python代码含有较多的输入变量,可将代码的输入变量写入到launch.json中,帮助调试。
例如一段python的输入命令如下:
python demo/demo.py \
--config-file configs/ade20k-150/maskformer_R50_bs16_160k.yaml \
--input images/ADE/ADE_test_00000001.jpg \
--opts MODEL.WEIGHTS weights/MaskFormer_R50_512x512.pkl
新建一个launch.json
launch.json的默认值如下:
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python 调试程序: 当前文件",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
"program"是主函数的文件路径。
"args"是输入的参数的值。
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python 调试程序: 当前文件",
"type": "debugpy",
"request": "launch",
"program": "demo/demo.py",
"console": "integratedTerminal",
"args": ["--config-file", "configs/ade20k-150/maskformer_R50_bs16_160k.yaml",
"--input", "images/ADE/ADE_test_00000001.jpg",
"--opts", "MODEL.WEIGHTS", "weights/MaskFormer_R50_512x512.pkl"]
}
]
}