批处理预测Vertext AI



我如何创建JSONL文件,其中包含的文件列表在谷歌云桶在顶点AI批量预测?我已经尽力了。

  1. 从桶中获取文件列表,并将其写入txt文件gsutil ls gs://bucket/dir > list.txt
  2. 转换list.txtlist.jsonl以下文本AI文档:
{"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中的列表文件导出为JSONL文件格式?

下面是一些python代码,您可以运行它们来从列表中创建一个工作的JSON行文件。(由于在Google ML文档中并不完全清楚,对于这个过程的新手来说,在Google Vertex AI命令shell中,您首先使用Unix命令从文件夹的内容创建列表。如果"ls"one_answers";cat"对您来说都是新的,那就找一个Unix极客吧。)如果你是在Windows/MacOS/Linux/YourFlavorOfWeirdness中运行python脚本的新手,有各种各样的网络教程告诉你该怎么做。首先,将此代码片段保存为"googleparse.py">

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

% python3 googleparse1.py -o googleparse. pyjsonl 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**")

最新更新