2016-10-07 6 views
1

これは私が、私はこのチュートリアルを使用して設定tensorflowサーバーを照会するために作成されたC#クライアントのスニップです:https://tensorflow.github.io/serving/serving_inception.htmlC#でTensorProtoを作成するには?

 var channel = new Channel("TFServer:9000", ChannelCredentials.Insecure); 

     var request = new PredictRequest(); 

     request.ModelSpec = new ModelSpec(); 
     request.ModelSpec.Name = "inception"; 

     var imgBuffer = File.ReadAllBytes(@"sample.jpg"); 

     ByteString jpeg = ByteString.CopyFrom(imgBuffer, 0, imgBuffer.Length); 

     var jpgeproto = new TensorProto(); 
     jpgeproto.StringVal.Add(jpeg); 
     jpgeproto.Dtype = DataType.DtStringRef; 


     request.Inputs.Add("images", jpgeproto); // new TensorProto{TensorContent = jpeg}); 

     PredictionClient client = new PredictionClient(channel); 

私はほとんどのクラスは、protoc

を使用してプロトファイルから生成するために必要なことが判明

私が見つけることができないのは、TensorProtoを構築する方法だけです。追加情報:Status(StatusCode = InvalidArgument、Detail = "テンソル解析エラー:画像")

サンプルクライアント(https://github.com/tensorflow/serving/blob/master/tensorflow_serving/example/inception_client.py)があります。私のPythonのスキルは最後のビットを理解するのに十分ではありません。

+0

私はあなたと同じ問題をJavaで持っています。解決策が見つかると更新されます。 – Kellen

答えて

1

私はまた、そのクライアントを別の言語(Java)で実装しました。

jpgeproto.Dtype = DataType.DtString; 

jpgeproto.Dtype = DataType.DtStringRef; 

を変更するようにしてくださいまた、あなたのテンソルプロトへの次元でテンソルの形状を追加する必要があります。ここで私のJavaでの作業ソリューションは、C#で似ているはずです。

TensorShapeProto.Dim dim = TensorShapeProto.Dim.newBuilder().setSize(1).build(); 
TensorShapeProto shape = TensorShapeProto.newBuilder().addDim(dim).build(); 
TensorProto proto = TensorProto.newBuilder() 
       .addStringVal(ByteString.copyFrom(imageBytes)) 
       .setTensorShape(shape) 
       .setDtype(DataType.DT_STRING) 
       .build(); 
ModelSpec spec = ModelSpec.newBuilder().setName("inception").build(); 
PredictRequest r = PredictRequest.newBuilder() 
       .setModelSpec(spec) 
       .putInputs("images", proto).build(); 
PredictResponse response = blockingStub.predict(r); 
関連する問題