【发布时间】:2021-11-16 15:33:48
【问题描述】:
我得到了一个基于 GCP 中的 AutoML 表的训练和部署模型。
它在 PowerShell 中回答以下请求:
$env:GOOGLE_APPLICATION_CREDENTIALS="[MY-SERVICE-ACCOUNT-KEY-FILE].json"
$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile [MY-REQUEST-FILE].json `
-Uri "https://eu-automl.googleapis.com/v1beta1/projects/[MY-PROJECT-ID]/locations/eu/models/[MY-MODEL-ID]:predict" | Select-Object -Expand Content
对应回复:
{
"payload": [
{
"tables": {
"score": 0.9930415,
"value": "Low"
}
},
{
"tables": {
"score": 0.006626979,
"value": "Medium"
}
},
{
"tables": {
"score": 0.0003314384,
"value": "High"
}
}
]
}
一切都好。现在我想按照文档here 使用 Google.Cloud.AutoML.V1 .NET 库从 C# 进行调用。
<PackageReference Include="Google.Cloud.AutoML.V1" Version="2.3.0" />
// Create client
PredictionServiceClient predictionServiceClient = PredictionServiceClient.Create();
// Initialize request argument(s)
ModelName name = ModelName.FromProjectLocationModel([MY-PROJECT-ID], "eu", [MY-MODEL-ID]);
ExamplePayload payload = new ExamplePayload();
IDictionary<string, string> @params = new Dictionary<string, string> { { "feature_importance", "true" }, };
// Make the request
PredictResponse response = predictionServiceClient.Predict(name, payload, @params);
终端:
Unhandled Exception: Grpc.Core.RpcException: Status(StatusCode="InvalidArgument", Detail="List of found errors: 1.Field: name; Message: The provided location ID doesn't match the endpoint. For automl.googleapis.com, the valid location ID is `us-central1`. For eu-automl.googleapis.com, the valid location ID is `eu`. 2.Field: payload.payload; Message: Required field not set. ", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1632383996.440000000","description":"Error received from peer ipv4:216.58.211.10:443","file":"..\..\..\src\core\lib\surface\call.cc","file_line":1067,"grpc_message":"List of found errors:\t1.Field: name; Message: The provided location ID doesn't match the endpoint. For automl.googleapis.com, the valid location ID is `us-central1`. For eu-automl.googleapis.com, the valid location ID is `eu`.\t2.Field: payload.payload; Message: Required field not set.\t","grpc_status":3}")
at Grpc.Core.Internal.AsyncCall`2.UnaryCall(TRequest msg) in /var/local/git/grpc/src/csharp/Grpc.Core/Internal/AsyncCall.cs:line 78
at Grpc.Core.DefaultCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request) in /var/local/git/grpc/src/csharp/Grpc.Core/DefaultCallInvoker.cs:line 46
at Grpc.Core.Interceptors.InterceptingCallInvoker.<BlockingUnaryCall>b__3_0[TRequest,TResponse](TRequest req, ClientInterceptorContext`2 ctx) in /var/local/git/grpc/src/csharp/Grpc.Core.Api/Interceptors/InterceptingCallInvoker.cs:line 51
at Grpc.Core.ClientBase.ClientBaseConfiguration.ClientBaseConfigurationInterceptor.BlockingUnaryCall[TRequest,TResponse](TRequest request, ClientInterceptorContext`2 context, BlockingUnaryCallContinuation`2 continuation) in /var/local/git/grpc/src/csharp/Grpc.Core.Api/ClientBase.cs:line 174
at Grpc.Core.Interceptors.InterceptingCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request) in /var/local/git/grpc/src/csharp/Grpc.Core.Api/Interceptors/InterceptingCallInvoker.cs:line 48
at Google.Cloud.AutoML.V1.PredictionService.PredictionServiceClient.Predict(PredictRequest request, CallOptions options) in /_/apis/Google.Cloud.AutoML.V1/Google.Cloud.AutoML.V1/PredictionServiceGrpc.g.cs:line 281
at Google.Api.Gax.Grpc.ApiCall.GrpcCallAdapter`2.CallSync(TRequest request, CallSettings callSettings) in /_/Google.Api.Gax.Grpc/ApiCall.cs:line 92
at Google.Api.Gax.Grpc.ApiCallRetryExtensions.<>c__DisplayClass1_0`2.<WithRetry>b__0(TRequest request, CallSettings callSettings) in /_/Google.Api.Gax.Grpc/ApiCallRetryExtensions.cs:line 78
at Predict.Program.predict1(String project, String location, String model) in
知道如何进行吗?
【问题讨论】:
标签: c# .net google-cloud-platform google-cloud-automl