2

Google Cloud Platform에 배포 된 훈련 된 모델 (CNN)을 사용하여 Python 클라이언트 라이브러리 또는 gcloud 명령을 사용하여 예측을 얻을 수 있습니다.Google Cloud Machine Learning API Dot Net 클라이언트 - 예측 요청 실패

지금 예측을 얻기 위해 닷 넷 클라이언트 v1.25 (https://github.com/google/google-api-dotnet-client/tree/v1.25.0)를 사용하는 것을 시도하고있다,하지만 난 보내는있어 JSON의 형식에도 불구하고 요청이 {"error": "Missing "instances" field in request body."}과 실패 :

{"instances": [{"image":<base64ImageData>, "key":"1"}]} 

라이브러리를 사용하여 List() 메소드를 사용하여 사용 가능한 모델 목록을 가져올 수 있습니다.

using System; 
using System.Text; 
using Google.Apis.Auth.OAuth2; 
using System.IO; 
using Google.Apis.Services; 
using Google.Apis.CloudMachineLearningEngine.v1beta1.Data; 
using Newtonsoft.Json; 

namespace GoogleCloudTesting 
{ 
    Class Program 
    { 
     static void Main(string[] args) 
     { 
      GoogleCredential credential = GoogleCredential.GetApplicationDefaultAsync().Result; 

      var service = new Google.Apis.CloudMachineLearningEngine.v1beta1.CloudMachineLearningEngineService(
       new BaseClientService.Initializer() 
       { 
        HttpClientInitializer = credential, 
        ApplicationName = "Testing" 
       } 
      ); 

      string jsonImagesPath = @"c:\path\to\images.json"; // {"instances": [{"image":<base64imagedata>, "key":"1"}]} 
      string json = File.ReadAllText(jsonImagesPath); 

      var request = new GoogleCloudMlV1beta1PredictRequest 
      { 
       HttpBody = new GoogleApiHttpBody { Data = json } 
      }; 

      var predictRequest = service.Projects.Predict(request, "projects/my_project/models/my_model/versions/V1"); 
      var result = predictRequest.Execute(); 
      Console.WriteLine(result.Data); // null 
     } 
    } 
} 

감사 어떤 도움 덕분에 다음과 같이

코드입니다.

+0

base64로 인코딩 된 데이터는 JSON 객체로 대체되어야 https://cloud.google.com/ml-engine/reference/rest/v1/projects/predict GitHub의 제안에 나타낸다 'b64'라는 이름의 단일 속성이 있습니다. 그래서 아마도 다음을 사용해야합니다 : { "instances": [{ "image": { "b64": ""} "key": "1"}]} – Chris

+0

파이썬 버전과 비교하면 미묘한 차이가 있습니다 https://cloud.google.com/ml-engine/docs/how-tos/online-predict#requesting_predictions). 그러나 확실하게 해결할 수있는 .net 라이브러리를 잘 모릅니다. 차이점은 HttpBody는 파이썬에서 사용되지 않는다는 것입니다. 대신 service.Projects.Predict (body = json, name = "projects/my_project/models/my_model/versions/V1")와 같은 것이 좋습니다. 다시 말하지만 정확히 작동한다는 것을 보장 할 수는 없지만 문제는 HttpBody라고 확신합니다. – rhaertel80

+0

다음 안내를 따르십시오. https://googlecloudplatform.github.io/google-cloud-dotnet/docs/faq.html#how-can-i-trace-requests-and-responses-in-rest-based-apis HTTP 요청 헤더와 본문을 덤프합니다. 그런 다음 여기에 덤프를 게시하십시오. –

답변

0

이것은 알려진 문제입니다.

두 워크 어라운드는 issue#1068

관련 문제