יום חמישי, 9 באוגוסט 2018

Tensorflowsharp does not reproduce the results of python

using EdjeElectronics example and code I was able to train a date (the fruit) object detector. the proces works fine on python producing this 
almost what i need and much better than i could do on my own
now I came to the implementation task and used Tensorflowsharp as my starting point
this produces these 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);
}

here is the source image:
Im at a loss as to what is the reason for the difference
the python runs a tensorflow 1.8 version?

well the answer was simple but not obvious
you should replace ConstructGraphToNormalizeImage (in ImageUtil.cs) with this code
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;
        }
or change the W , H, Mean and scale to the numbers the model was trained in the first place.

I could not find a source defining these constants for the models i used. so the code without constans is my choice.




 
Locations of visitors to this page