【问题标题】:Argparse SystemExit: 2argparse 系统退出:2
【发布时间】:2020-06-03 11:55:20
【问题描述】:

我的代码...

import numpy as np
import argparse
import imutils
import sys
import cv2 as cv

ap = argparse.ArgumentParser()
ap.add_argument("-m", "--model", required=True,   help = "path to trained activity recognition 
model")
ap.add_argument("-c", "--classes", required=True, help = "path to class label file")
ap.add_argument("-i", "--input", type = str, default = "", help = "optional file to video file")

args = vars(ap.parse_args())

我正在关注this 教程。这里得到错误是

用法:ipykernel_launcher.py [-h] -m MODEL -c CLASSES [-i INPUT] ipykernel_launcher.py:错误:需要以下参数:-m/--model、-c/--classes

发生异常,使用 %tb 查看完整的回溯。

系统退出:2

【问题讨论】:

  • 您不能在jupyter-notebook 中使用argparse。您在启动服务器时提供的命令行值适用于服务器本身,而不是您的笔记本。此代码旨在作为“普通”python 脚本(来自 shell)运行。

标签: python-3.x tensorflow computer-vision argparse


【解决方案1】:

对于 argparse,您需要在命令行中提供参数。例如,您可以将脚本保存为script.py 并以python script.py -m somemodel -c someclass 运行以提供所需的参数。如果您使用的是 Spyder 等 IDE,它应该可以选择在某处提供命令行参数。

【讨论】:

    猜你喜欢
    • 2019-10-01
    • 2018-11-28
    • 1970-01-01
    • 2019-01-26
    • 2017-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多