当前位置:   article > 正文

vsCode运行python设置argparse参数_vscode跑模型时修改argparse参数

vscode跑模型时修改argparse参数

想在vsCode中调试带参数的python程序,参数设置方式。
Run->open Configurations,打开lanuch.json。在lanuch.json中添加代码后效果如下:

    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args":[
            	"train",
                "--cfg","cfg/yolo_hand/yolo_hand.cfg",
                "--data","cfg/yolo_hand/Test.data",
                "--weights","cfg/yolo_hand/yolo_hand_best.weights",
                "--batch-size","64",
                "-sr",
                "--s","0.001",
                "--prune","0"
            ]
        }
    ]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

args列表里是我们的参数和值。
备注:store_true就代表着一旦指令里写了这个参数,那么将其值设为True,没有时,默认状态下其值为False。同理:store_false代表一旦命令中有此参数,其值则变为False,默认为True。
代码中的“-sr”就是设置了action=‘store_true’,所以没有设置值。
若程序代码中有“cmd”参数,如:

parser.add_argument('cmd', type=str,  choices=['train', 'test'], help='train or test')
  • 1

则launch.json中只需写入一个“choices”的字符串,如上所示。

值为int型或者其他,也都需要加双引号。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/770925
推荐阅读
相关标签
  

闽ICP备14008679号