py: argparse 不提供命令行的值,将会一路采用默认值

代码举例:

尽管你在 函数里指定了 默认值,走到这个函数的时候,也不会用这个函数定义的参数默认值,而是使用 命令行的参数默认值;

import argparse

def test():
    non_max_suppression("no", opt.conf_thres, opt.iou_thres,
                                   multi_label=False)
#  尽管你在 函数里指定了 默认值,走到这个函数的时候,也不会用这个函数定义的参数默认值,而是使用 命令行的参数默认值;
# aka  0.3 和 0.6
def non_max_suppression(prediction="pred", conf_thres=0.005, iou_thres=0.45, multi_label=True):
    print(f"we have confiden threshhold:{conf_thres}, and iou_thres: {iou_thres}")

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('--conf-thres', type=float, default=0.3, help='object confidence threshold')
    parser.add_argument('--iou-thres', type=float, default=0.6, help='IOU threshold for NMS')
    opt = parser.parse_args()
    print(f"we have running option: {opt}")
    test()


输出

 py utils/test_opt_parse.py
we have running option: Namespace(conf_thres=0.3, iou_thres=0.6)
we have confiden threshhold:0.3, and iou_thres: 0.6

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值