1

在学习一段python代码的时候,出现了一些问题。

代码如下:</p>

parser = argparse.ArgumentParser()

parser.add_argument('--config_path', type=str, default="",
                    help='the location of the data folder')

parser.add_argument('--data_path', type=str, required=True, default="/mnt/Dataset/xView2/v2",
                    help='the location of the data folder')
parser.add_argument('--ckpt_path', type=str, required=True, default="",
                    help='Path to checkpoint')
parser.add_argument('--result_dir', type=str, required=True, default="",
                    help='Path to save result submit and compare iamges')
parser.add_argument('--is_train_data', action='store_true', dest='is_train_data',
                    help='')
parser.add_argument('--is_use_gpu', action='store_true', dest='is_use_gpu',
                    help='')

args = parser.parse_args()

错误如下:</p>

runfile('D:/aaa/New_file/test_net.py', wdir='D:/aaa/New_file')
Reloaded modules: models, models.dual_hrnet, xview2, utils
usage: test_net.py [-h] [--config_path CONFIG_PATH] --data_path DATA_PATH
                   --ckpt_path CKPT_PATH --result_dir RESULT_DIR
                   [--is_train_data] [--is_use_gpu]
test_net.py: error: the following arguments are required: --data_path, --ckpt_path, --result_dir
An exception has occurred, use %tb to see the full traceback.

SystemExit: 2


%tb
Traceback (most recent call last):

  File "D:\aaa\New_file\test_net.py", line 41, in <module>
    args = parser.parse_args(args=[])

  File "D:\Anaconda\envs\tensorflow\lib\argparse.py", line 1755, in parse_args
    args, argv = self.parse_known_args(args, namespace)

  File "D:\Anaconda\envs\tensorflow\lib\argparse.py", line 1787, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)

  File "D:\Anaconda\envs\tensorflow\lib\argparse.py", line 2022, in _parse_known_args
    ', '.join(required_actions))

  File "D:\Anaconda\envs\tensorflow\lib\argparse.py", line 2508, in error
    self.exit(2, _('%(prog)s: error: %(message)s\n') % args)

  File "D:\Anaconda\envs\tensorflow\lib\argparse.py", line 2495, in exit
    _sys.exit(status)

SystemExit: 2

我尝试更改args = parser.parse_args()args = parser.parse_args(args=[]),但仍然出现同样的问题。我想可能是因为我没有正确设置 default="" 的值,不幸的是我不知道如何修改。

4

0 回答 0