首页 > 解决方案 > 如何在 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

标签: pythoncommand-linedeep-learningconv-neural-networkgoogle-colaboratory

解决方案


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

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

推荐阅读