emgucv / emgutf

Emgu TF is a cross platform .Net wrapper for the Google Tensorflow library. Allows Tensorflow functions to be called from .NET compatible languages such as C#, VB, VC++, IronPython.

Home Page:https://www.emgu.com/wiki/index.php/Emgu_TF

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

System.AccessViolationException: 'Attempted to read or write protected memory.

michealChin opened this issue · comments

Hi,

Below is my code

`
Emgu.TF.Lite.Interpreter interpreter = null;
public MyConstructor(){

        Emgu.TF.Lite.FlatBufferModel bb = new Emgu.TF.Lite.FlatBufferModel("abc.tflite");
        interpreter = new Emgu.TF.Lite.Interpreter(bb);
        interpreter.SetNumThreads(32);            
        interpreter.AllocateTensors();            
}
    public float[] getEmbedding(Bitmap image)
    {
        double mean = 0.0f;
        float scale = 1.0f;
        double std = 1;
        bool flipUpsideDown = false;
        bool swapBR = false;

        //interpreter.in
        int[] input = interpreter.InputIndices;
        var inputTensor = interpreter.Inputs[0];

        int[] output = interpreter.InputIndices;
        var outputTensor = interpreter.Outputs[0];

        //NativeImageIO.ReadImageFileToTensor<float>(imageFile, inputTensor.DataPointer, height, width, mean, scale, flipUpsideDown, swapBR);
        NormalizeImage(image, out mean, out std);
        scale = 1.0f / (float)std;

        NativeImageIO.ReadBitmapToTensor<float>(image, inputTensor.DataPointer,image.Height,image.Width,(float)mean,scale,flipUpsideDown,swapBR);
        DateTime start = DateTime.Now;
        interpreter.Invoke();            
        DateTime end = DateTime.Now;
        System.TimeSpan diff = end - start;
        double milliseconds = (diff.TotalMilliseconds / 1000.0);
        Console.WriteLine("time invoke:" + milliseconds.ToString());
        //MessageBox.Show($"time invoke {milliseconds.ToString()}");
        float[] outputData = outputTensor.Data as float[];
        image.Dispose();

        return outputData;
    }`

I call the getEmbedding for 5 times and it was working fine, but when I called the 6th times, it suddenly pop up this error message may I know what is the problem?

duplicate #63