TensorFlowSharp icon indicating copy to clipboard operation
TensorFlowSharp copied to clipboard

Help Needed, NullReferenceException when calling runner.AddInput()

Open andyl1992 opened this issue 7 years ago • 2 comments

I am trying to infer with a pre-trained model i have created with keras/tensorflow. I am adapting code from the examples to try and achieve. I believe i have adapted the ImageUtils class correctly for my model but i am not sure about the rest.

I am getting a NullReferenceException when calling runner.AddInput()

TensorFlow.TFGraph.this[string].get returned null

        var graph = new TFGraph();
        var model = File.ReadAllBytes("220318model321flat.pb");
        graph.Import(model);

        if (graph == null)
        {
            Console.WriteLine("graph empty");
        }
        

        using (var session = new TFSession(graph))
        {
            
            var tensor = ImageUtil.CreateTensorFromImageFile("2.png", TFDataType.UInt8);
            Console.WriteLine(tensor.GetTensorDimension(1).ToString() + tensor.GetTensorDimension(2).ToString());

            if (tensor == null)
            {
                Console.WriteLine("tensor empty");
            }

            var runner = session.GetRunner();
            runner.AddInput(graph["input"][0], tensor).Fetch(graph["output"][0]);
            

            var output = runner.Run();
            var result = output[0];
            
        }

Any help would be much appreciated, thank you.

andyl1992 avatar Mar 25 '18 15:03 andyl1992

This means that the specified operation ("input") does not exist in your graph. You can get a list of all operations by calling graph.GetEnumerator().

raulbojalil avatar Apr 09 '18 18:04 raulbojalil

For future reference, a tutorial from Tensorflow documentation defined the variables input as "Placeholder" and output as "final_result"

coelhojs avatar May 15 '19 17:05 coelhojs