【发布时间】:2018-01-12 16:41:52
【问题描述】:
我正在尝试在 google cloud ml-engine 中创建批量预测作业。不幸的是,我总是遇到同样的错误:
{
insertId: "wr85wwg6shs9ek"
logName: "projects/tensorflow-test-1-168615/logs/ml.googleapis.com%2Ftest_job_23847239"
receiveTimestamp: "2017-08-04T16:07:29.524193256Z"
resource: {
labels: {
job_id: "test_job_23847239"
project_id: "tensorflow-test-1-168615"
task_name: "service"
}
type: "ml_job"
}
severity: "ERROR"
textPayload: "TypeError: decoding Unicode is not supported"
timestamp: "2017-08-04T16:07:29.524193256Z"
}
我在 java 中创建文件并使用以下代码将其上传到存储桶:
BufferedImage bufferedImage = ImageIO.read(new URL(media.getUrl()));
int[][][] imageMatrix = convertToImageToMatrix(bufferedImage);
String imageString = matrixToString(imageMatrix);
String inputContent = "{\"instances\": [{\"inputs\": " + imageString + "}]}";
byte[] inputBytes = inputContent.getBytes(Charset.forName("UTF-8"));
Blob inputBlob = mlInputBucket.create(media.getId().toString() + ".json", inputBytes, "application/json");
inputPaths.add("gs://" + Properties.getCloudBucketNameInputs() + "/" + inputBlob.getName());
在这段代码中,我下载了图像,将其转换为 uint8 矩阵并将矩阵格式化为 json 字符串。该文件被创建并存在于存储桶中。我也验证了,json文件是有效的。
在下一步中,我收集所有创建的文件并开始预测作业:
GoogleCloudMlV1PredictionInput input = new GoogleCloudMlV1PredictionInput();
input.setDataFormat("TEXT");
input.setVersionName("projects/" + DatastoreOptions.getDefaultProjectId() + "/models/" + Properties.getMlEngineModelName() + "/versions/" + Properties.getMlEngineModelVersion());
input.setRegion(Properties.getMlEngineRegion());
input.setOutputPath("gs://" + Properties.getCloudBucketNameOutputs() + "/" + jobId);
input.setInputPaths(inputPaths);
GoogleCloudMlV1Job job = new GoogleCloudMlV1Job();
job.setJobId(jobId);
job.setPredictionInput(input);
engine.projects().jobs().create("projects/" + DatastoreOptions.getDefaultProjectId() , job).execute();
最后,作业被创建,但结果是从头开始的。
我也尝试使用 gcloud sdk 启动工作,但结果是一样的。但是当我修改文件以删除instances 对象并匹配online prediction 的正确格式时,它可以工作(为了使其工作,我需要从输入中删除大部分行,因为有效负载配额用于在线预测)。
我正在使用来自object detection 的训练有素的宠物模型。我创建的输入文件之一可以在 here 找到。
我在这里做错了什么?
【问题讨论】:
标签: tensorflow tensorflow-serving google-cloud-ml-engine