コード例 #1
0
            private void UpdateCacheIfNeeded(long position, ITensorValueGetter[] srcTensorGetters, string[] activeOutputColNames, OutputCache outputCache)
            {
                if (outputCache.Position != position)
                {
                    if (_parent.Graph.graph_key != tf.get_default_graph().graph_key)
                    {
                        _parent.Session.graph.as_default();
                    }
                    Runner runner = new Runner(_parent.Session, _parent.Inputs.ToArray(), _parent.Outputs.ToArray());

                    // Feed inputs to the graph.
                    for (int i = 0; i < _parent.Inputs.Length; i++)
                    {
                        runner.AddInput(srcTensorGetters[i].GetTensor(), i);
                    }

                    // Execute the graph.
                    var tensors = runner.Run();
                    runner.Dispose();

                    Contracts.Assert(tensors.Length > 0);

                    for (int j = 0; j < activeOutputColNames.Length; j++)
                    {
                        if (outputCache.Outputs.TryGetValue(activeOutputColNames[j], out Tensor outTensor))
                        {
                            outTensor.Dispose();
                        }

                        outputCache.Outputs[activeOutputColNames[j]] = tensors[j];
                    }
                    outputCache.Position = position;
                }
            }