Exemple #1
0
        public void StringTestWithMultiDimStringTensorAsInputOutput()
        {
            using (var graph = new TFGraph())
                using (var session = new TFSession(graph))
                {
                    var W         = graph.Placeholder(TFDataType.String, new TFShape(-1, 2));
                    var identityW = graph.Identity(W);

                    var dataW = new string[, ] {
                        { "This is fine.", "That's ok." }, { "This is fine.", "That's ok." }
                    };
                    var bytes = new byte[2 * 2][];
                    bytes[0] = Encoding.UTF8.GetBytes(dataW[0, 0]);
                    bytes[1] = Encoding.UTF8.GetBytes(dataW[0, 1]);
                    bytes[2] = Encoding.UTF8.GetBytes(dataW[1, 0]);
                    bytes[3] = Encoding.UTF8.GetBytes(dataW[1, 1]);
                    var tensorW = TFTensor.CreateString(bytes, new TFShape(2, 2));

                    var outputTensor = session.Run(new TFOutput[] { W }, new TFTensor[] { tensorW }, new[] { identityW });

                    var outputW = TFTensor.DecodeMultiDimensionString(outputTensor[0]);
                    Assert.Equal(dataW[0, 0], Encoding.UTF8.GetString(outputW[0]));
                    Assert.Equal(dataW[0, 1], Encoding.UTF8.GetString(outputW[1]));
                    Assert.Equal(dataW[1, 0], Encoding.UTF8.GetString(outputW[2]));
                    Assert.Equal(dataW[1, 1], Encoding.UTF8.GetString(outputW[3]));
                }
        }