首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google Cloud Machine Learning API Dot Net Client -预测请求失败

Google Cloud Machine Learning API Dot Net Client -预测请求失败
EN

Stack Overflow用户
提问于 2017-04-26 23:29:30
回答 1查看 370关注 0票数 2

我在Google Cloud平台上部署了一个经过训练的模型(CNN),我可以使用Python客户端库或gcloud命令从该模型获得预测结果。

我现在正在尝试使用Dot Net client v1.25 (https://github.com/google/google-api-dotnet-client/tree/v1.25.0)来获取预测,但是使用{"error": "Missing "instances" field in request body."}的请求失败了,尽管我发送的JSON是这样的:

代码语言:javascript
复制
   {"instances": [{"image":<base64ImageData>, "key":"1"}]}

我可以使用这个库通过List()方法获得可用模型的列表。

代码如下:

代码语言:javascript
复制
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
        }
    }
}

感谢您的帮助,谢谢。

EN

回答 1

Stack Overflow用户

发布于 2017-07-20 17:16:53

这是一个已知的问题。

github issue#1068中显示了两个解决方法

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43638529

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档