首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >批预测Vertext AI

批预测Vertext AI
EN

Stack Overflow用户
提问于 2021-09-14 09:01:41
回答 1查看 292关注 0票数 1

如何创建包含GoogleCloud桶中文件列表的JSONL文件,以便在顶点AI中进行批预测?到目前为止我尝试过的。

  1. 从桶中获取文件列表并将其写入txt文件gsutil ls gs://bucket/dir > list.txt
  2. 按照list.txtlist.jsonl转换为Vertext AI文档
代码语言:javascript
复制
{"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文件的格式?另外,是否可以直接将存储桶中的列表文件导出为JSONL文件格式?

EN

回答 1

Stack Overflow用户

发布于 2022-04-04 04:03:18

下面是您可以运行的一些python代码,以便从列表中创建一个可以工作的JSON行文件。(由于在Google文档中并不完全清楚,对于这个过程中的新手来说,在Google命令shell中,首先可以使用Unix命令从文件夹的内容创建列表。如果"ls“和"cat”对你来说是新的,那就给自己找一个Unix吧。)如果您是在Windows/MacOS/Linux/YourFlavorOfWeirdness中运行python脚本的新手,那么就有各种各样的网络教程要做什么。首先,将此代码段保存为"googleparse.py“

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

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

代码语言:javascript
复制
#
# 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**")
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69174883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档