【问题标题】:Batch predictions Vertext AI批量预测 Vertex AI
【发布时间】:2022-04-04 12:08:56
【问题描述】:

如何在 Google Cloud Bucket 中创建包含文件列表的 JSONL 文件,以便在 Vertex AI 中进行批量预测? 到目前为止我所尝试的。

  1. 从bucket中获取文件列表并写入txt文件 gsutil ls gs://bucket/dir > list.txt
  2. Vertext AI docs之后将list.txt转换为list.jsonl
{"content": "gs://sourcebucket/datasets/images/source_image1.jpg", "mimeType": "image/jpeg"}
{"content": "gs://sourcebucket/datasets/images/source_image2.jpg", "mimeType": "image/jpeg"}

创建批量预测后,出现此错误:cannot be parsed as JSONL. 如何更正此 JSONL 文件的格式? 另外,有没有办法直接将bucket中的list文件导出为JSONL文件格式?

【问题讨论】:

    标签: python gsutil google-cloud-automl google-cloud-vertex-ai


    【解决方案1】:

    这里有一些 Python 代码,您可以运行该代码来从列表中创建一个有效的 JSON 行文件。 (由于在 Google ML 文档中并不完全清楚,对于此过程的新手,在 Google Vertex AI 命令外壳中,您首先使用 Unix 命令从文件夹的内容创建列表。如果“ls”和“猫”对你来说是新的,发现自己是一个 Unix 极客。)如果你不熟悉在 Windows/MacOS/Linux/YourFlavorOfWeirdness 中运行 python 脚本,那么有各种各样的互联网教程告诉你该怎么做。首先,将此代码 sn-p 保存为“googleparse.py”

    假设输入文件为“googlelist.txt”,指定输出为googleparse.jsonl,在命令提示符中输入以下内容。

    % python3 googleparse1.py -o googleparse.jsonl googlelist.txt

    #
    # googleparse.py by Cyberchuck2000:
    #
    # Parse a list of images from the Google Cloud and format
    # into the Google parse format
    #
    import argparse
    
    parser = argparse.ArgumentParser(description='Produce JSONL files for Google Parse')
    parser.add_argument('inputfilename')
    parser.add_argument('-o',dest='outputfilename', default='googleparse.jsonl')
    
    prefix = '{"content": \''
    suffix = '\', "mimeType": "image/jpeg"}'
    
    args = parser.parse_args()
    if args.inputfilename is not None:
        print('The file name is {}, output is {}'.format(args.inputfilename,args.outputfilename))
    else:
        print('Oh well ; No args, no problems')
    
    with open(args.inputfilename) as inputf:
        lines = inputf.readlines()
    
    with open(args.outputfilename, 'w') as writef:
        for line in lines:
            line = line.strip()
            outline = prefix + line + suffix + "\n"
            writef.write(outline)
    
    print("**DONE**")
    

    【讨论】:

      猜你喜欢
      • 2021-11-19
      • 2021-12-09
      • 2021-12-24
      • 2021-10-29
      • 2021-12-23
      • 2023-01-03
      • 2021-09-17
      • 2022-01-01
      • 2021-12-26
      相关资源
      最近更新 更多