如何在 gcloud ml-engine 中上传用于批量预测的输入文件?

How to upload input file for batch prediction in gcloud ml-engine?

我正在尝试在 google 云 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启动job,结果还是一样。但是当我修改文件以删除 instances 对象并匹配 online prediction 的正确格式时,它起作用了(为了使其起作用,我需要从输入中删除大部分行,因为在线预测的负载配额)。

我正在使用 object detection. One of my created input files can be found here 中经过训练的宠物模型。

我哪里做错了?

我是否在 中回答了您的问题?批量预测的输入不应包含'{"instances: }'。