question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

python results different from tensorflowsharp

See original GitHub issue

I use tensorflowsharp to locate items on a conveyor belt - it works 😃 but the results i see on a python (anaconda) are much better than the tensorflowharp

python image is python results

when i run tensorflowsharp with my inference graph i get tensorflowsharp results

To get here i changed the tnsorflosharp object detection sample like this

_catalogPath = "C:/Users/user 67/Downloads/TensorFlowSharp-master/Examples/ExampleObjectDetection/bin/Debug/demo/inferencegraph/labelmap.pbtxt";
         if (_catalogPath == null) {
  _catalogPath = DownloadDefaultTexts (_currentDir);
 }
_modelPath = "C:/Users/user 67/Downloads/TensorFlowSharp-master/Examples/ExampleObjectDetection/bin/Debug/demo/inferencegraph/frozen_inference_graph.pb";
         if (_modelPath == null) {
  _modelPath = DownloadDefaultModel (_currentDir);
 }

the .pb file is too large to be here i will try to upload it later

all of this in a slightly nicer form in a link link

in the tensorflosharp console differ in that in the original i get some lines of warnings (5-6) while if i try to load my file i get this tensorflosharp results.txt tensorflowsharp does not say if it is an error or just reading of .pb file contents

windows 10 .net 4.7.1

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:13

github_iconTop GitHub Comments

2reactions
SignalRTcommented, Aug 14, 2018

Thank you for your answer. I arrive to the same solution redoing the code following the python version:

private static TFGraph ConstructGraphToNormalizeImage( out TFOutput input, out TFOutput output, TFDataType destinationDataType = TFDataType.Float) { var graph = new TFGraph();

        input = graph.Placeholder(TFDataType.String);

        output = graph.Cast(
                    graph.ExpandDims(
                            input: graph.Cast(graph.DecodeJpeg(contents: input, channels: 3), DstT: TFDataType.Float),
                            dim: graph.Const(0, "make_batch")
                   )
                   , destinationDataType
                );

        return graph;
    }

The output from the Object Detection demo it’s the same that in the Python version.

2reactions
erlontedcommented, Aug 14, 2018

Before the execution the image is resized based in the model training, you need to change it based in your model before execute take a look when converting an image to tensor see my code const int W = 300; const int H = 300; const float Mean = 0; const float Scale = 1;

  graph = new TFGraph();
  input = graph.Placeholder(TFDataType.String);

  if (resizeTensor)
  {
    output = graph.Cast(graph.Div(
      x: graph.Sub(
        x: graph.ResizeBilinear(
          images: graph.ExpandDims(
            input: graph.Cast(
              graph.DecodeJpeg(contents: input, channels: 3), DstT: TFDataType.Float),
            dim: graph.Const(0, "make_batch")),
          size: graph.Const(new int[] { W, H }, "size")),
        y: graph.Const(Mean, "mean")),
      y: graph.Const(Scale, "scale")), destinationDataType);
  }
  else
  {
    output = graph.Cast(
     graph.ExpandDims(
     input: graph.Cast(
       graph.DecodeJpeg(contents: input, channels: 3), DstT: TFDataType.Float),
     dim: graph.Const(0, "make_batch")), destinationDataType);

  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Same Tensorflow model giving different results on Android ...
I am trying to run a Tensorflow model on my Android application, but the same trained model gives different results (wrong inference) ...
Read more >
Errors with Tensorflowsharp output = runner.Run() on ...
I've written a YOLO object detection model that tests out properly when inferenced in Python or with TFSharp in Visual Studio only.
Read more >
Mr_Mao/TensorFlowSharp
TensorFlowSharp is a good runtime to run your existing models, ... NET which takes a different approach than TensorFlowSharp, it uses the Python...
Read more >
TensorFlow - Creating C# Applications using ...
Training a CNN Model using TensorFlow and Python ... Convolutional neural networks (CNN) if trained properly can give spectacular results.
Read more >
Introduction to graphs and tf.function
A Function is a Python callable that builds TensorFlow graphs from ... tf.function applies to a function and all other functions it calls:....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found