已经不止一次,使用argparse中设置默认路径后总是不起作用,而且在代码中设置也不行,只能在终端中设置,请问这是为什么。代码如下:
def parse_args():
parser = argparse.ArgumentParser(
description='Simple testing funtion for Monodepthv2 models.')
parser.add_argument('--image_path', type=str,default='F:\\monodepth2-master\\image\\input\\class1.jpg',
help='path to a test image or folder of images', required=True)
parser.add_argument('--model_name', type=str,
help='name of a pretrained model to use',
choices=[
"weights_8",
"mono_640x192",
"stereo_640x192",
"mono+stereo_640x192",
"mono_no_pt_640x192",
"stereo_no_pt_640x192",
"mono+stereo_no_pt_640x192",
"mono_1024x320",
"stereo_1024x320",
"mono+stereo_1024x320"])
parser.add_argument('--ext', type=str,
help='image extension to search for in folder', default="jpg")
parser.add_argument("--no_cuda",
help='if set, disables CUDA',
action='store_true')
parser.add_argument("--pred_metric_depth",
help='if set, predicts metric depth instead of disparity. (This only '
'makes sense for stereo-trained KITTI models).',
action='store_true')
return parser.parse_args()
if name == 'main':
# parse_args().image_path="F://monodepth2-master//image//input//class1.jpg"
args = parse_args()
args.image_path="F://monodepth2-master//image//input//class1.jpg"
args.model_name="weights_8"
test_simple(args)
直接运行会出现报错:
usage: test_simple.py [-h] --image_path IMAGE_PATH
[--model_name {weights_8,mono_640x192,stereo_640x192,mono+stereo_640x192,mono_no_pt_640x192,stereo_no_pt_640x192,mono+stereo_no_pt_640x192,mono_1024x320,stereo_1024x320,mono+stereo_1024x320}]
[--ext EXT] [--no_cuda] [--pred_metric_depth]
test_simple.py: error: the following arguments are required: --image_path
模型参数设置是管用的,就是路径不行,路径格式也尝试过了,双斜杠,反斜杠,相对路径都试了,都不行,想知道怎么回事