我正在嘗試在谷雲ml引擎中創建批量預測作業。不幸的是,我總是得到同樣的錯誤:如何在gcloud 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找到。
我在做什麼錯在這裏?
好的,現在我很困惑,我想應該寫'實例',當我們要做批量預測工作時。認爲我忽視了這一點。 –