TensorFlowSharp icon indicating copy to clipboard operation
TensorFlowSharp copied to clipboard

[Windows] TFGraph CPU x86 System.BadImageFormatException: 'An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)'

Open kamilk91 opened this issue 6 years ago • 1 comments
trafficstars

Describe the bug



System.BadImageFormatException: 'An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)'

To Reproduce i generated model with

https://github.com/teresawu/tensor-image-model/

^ this sample photos.

(...)

string modelFile = "tmp/output_graph.pb";

(...)
 public Bitmap Detector()
        {
            using (var graph = new TFGraph())
            {
                var model = File.ReadAllBytes(modelFile);
                graph.Import(new TFBuffer(model));
using (var session = new TFSession(graph))
                {
                    Console.WriteLine("Detecting objects");


                    var tensor = ImageUtil.CreateTensorFromImageFile(input, TFDataType.UInt8);
                    
                    var runner = session.GetRunner();


                    runner
                        .AddInput(graph["image_tensor"][0], tensor)
                        .Fetch(
                        graph["detection_boxes"][0],
                        graph["detection_scores"][0],
                        graph["detection_classes"][0],
                        graph["num_detections"][0]);
                    var output = runner.Run();

                    var boxes = (float)output[0].GetValue(jagged: false);
                    var scores = (float)output[1].GetValue(jagged: false);
                    var classes = (float)output[2].GetValue(jagged: false);
                    var num = (float)output[3].GetValue(jagged: false);

                    Bitmap edited = ie.AddBox(input, boxes, scores, classes, MIN_SCORE_FOR_OBJECT_HIGHLIGHTING);
                    return edited;
}

Note: I do not have time to create models, train models, create samples from scratch and then adding your 3-4 lines of code to a sample to debug your problem. You need to provide a complete test case.

Expected behavior Use learned model

Screenshots Not needed

Desktop (please complete the following information):

  • OS: Windows 10

Additional context When im trying to execute thiss method, Exception is throwed every time. I tried to change Build option to x64, then this step went good, but my app needs x86 build (im using other Nugets which works only on x64).

Is it correct way to use model? Maybe im doing something wrong.

When im using x64 this step working, but i have another exception. But it does not matter now.

kamilk91 avatar Jul 03 '19 12:07 kamilk91

Hi,

You cannot use x64 binary in x86. You should use x86 TF binary and it should be compiled yourself.

Or if you just try to run model, WinML would be nice alternative.

gmlwns2000 avatar Oct 29 '19 08:10 gmlwns2000