Calling python function from KERAS.NET doesn't return

Viewed 86

I'm developing a card game that is played by a neural network. I'm using the Keras.NET library and calling model.Predict() (model is an instance of Sequential class).

This is the only part where python is called when the game is played:

public override List<float> GetResult(List<float> input)
{
    var NDArrayResult = model.Predict(
        new Numpy.NDarray<float>(input.ToArray())
            .reshape(1, inputCount, 1), 
        verbose: 0);
    float[] result = NDArrayResult.GetData<float>();
    return result.ToList();
}

I have 2 different startup projects, one is ConsoleApp, where everything goes just fine. But if I play the game in my Windows Forms app, the first few (1,2,3,4,..) python calls are successful, but then it just doesn't return from calling the python function... Sometimes it stops in Predict(), sometimes in reshape().

I tried to call this part of the code a task and wait for a period of time and then call the method again. It worked but occasionally caused the System.AccessViolationException.

Why does my code stop working after the first few attempts? How can I fix it to work in the Windows Forms application?

0 Answers
Related