代码举例:
尽管你在 函数里指定了 默认值,走到这个函数的时候,也不会用这个函数定义的参数默认值,而是使用 命令行的参数默认值;
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