【问题标题】:how to implement command line argument in google colabortary?如何在 google colaboratory 中实现命令行参数?
【发布时间】:2020-09-25 01:04:33
【问题描述】:

我尝试在 python 中实现命令行参数,

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-d", "--dataset", required=True,
    help="path to input dataset")
ap.add_argument("-p", "--plot", type=str, default="plot.png",
    help="path to output loss/accuracy plot")
ap.add_argument("-m", "--model", type=str,
    default="mask_detector.model",
    help="path to output face mask detector model")
args = vars(ap.parse_args())

错误

用法:ipykernel_launcher.py [-h] -d DATASET [-p PLOT] [-m MODEL] ipykernel_launcher.py:错误:需要以下参数:-d/--dataset 发生异常,使用 %tb 查看完整的回溯。

系统退出:2

【问题讨论】:

  • 如果您根据需要设置 -d,则必须在运行代码时提供它
  • 我希望this 有所帮助。我不会关闭以防万一。
  • 从错误消息中可以明显看出:您的工具调用没有包含带有值的命令行选项 -d。尝试在调用 parse_args 之前打印 sys.argv,以查看从调用到选项处理器的原因。

标签: python command-line deep-learning conv-neural-network google-colaboratory


【解决方案1】:

您可以这样做(只需将“!”放在任何新文件的命令前,并将脚本文件和数据集的路径放在命令中)

!python  '/content/drive/My Drive/face-mask-detector/train_mask_detector.py' --dataset  '/content/drive/My Drive/face-mask-detector/dataset' 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-10
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 1970-01-01
    相关资源
    最近更新 更多