python - 如何在 google colaborary 中实现命令行参数?
问题描述
我试图在 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
解决方案
您可以这样做(只需将“!”放在任何新文件上的命令之前,并将脚本文件和数据集的路径放在命令中)
!python '/content/drive/My Drive/face-mask-detector/train_mask_detector.py' --dataset '/content/drive/My Drive/face-mask-detector/dataset'
推荐阅读
- json - 由 Pubsub 触发的云函数
- android - 如何使用串口从 android Pos 终端的内置打印机打印数据
- tensorflow - 与“通道最后”相比,“通道优先”的训练准确度非常低
- api - 何时应该使用 Stripe Invoice API 更改 next_payment_attempt 值?
- android - Android:更改导航抽屉应用程序中的当前内容,而不在抽屉菜单中显示项目
- python - 使用三个参数最小化 scipy 中的函数返回初始猜测
- javascript - 从相关实体获取最小列值
- apache-nifi - APACHE NIFI 错误消息:'dd/MM/yyyy hh:mm:ss',无法转换为时间戳"
- javascript - 如何在不加载整个子对象的情况下获取 Firebase 实时数据库密钥
- java - 带有 Open JDK 和 Tomcat 9.0 的 Struts 2 的 Servlet API 转换问题