0

In Keras4Delphi I succesfully stored the output of a neural network into a variable. Now I want to simply read it from a Delphi array (in Delphi 10.3 Rio), not in string format but in a Double array type, from the numpy array format of Python. I get an error (Invalid variant operation) with the code I thought that should work.

I tried the following code (for XOR test in Keras4Delphi):

var x_test, y_test : TNDarray;

str_v : string;

y_out : TArray;

begin

x_test := TNumPy.npArray( [ [ 0, 1 ] ] );

y_test := model.Predict(x_test);

str_v := model.Predict(x_test).ToString; // --> works fine.

y_out := y_test.AsArrayofDouble; // --> Invalid variant operation, for : "y_out := model.Predict(x_test).AsArrayofDouble" also same error.

end.

Should I try another function instead of "AsArrayofDouble" to get the network output in a Delphi Double array? I searched for a proper function for hours but didn't find any.

7
  • Delphi do people still use that?, No offense but you might have more luck / fun with languages such as C# Python Java or c++ to get your work done in recent surveys only 3% of the devs use it. I've coded in lots of languages but even to me (i'm senior) thats an old language. You may get this done though should you want to these days? Commented Jan 15, 2024 at 23:24
  • Hi. A friend of mine always says to me I should use Python instead of Delphi/Pascal. Yet, I prefer Delphi because I've programmed in that language for more than 20 years. Commented Jan 16, 2024 at 15:07
  • I've fixed the error by myself! I had to write several new functions in PythonEngine.pas and in Python.Utils.pas. Now it works!! I get the neural network output in Variant array format with 64 bit Double. Commented Jan 16, 2024 at 15:09
  • 1
    Possibly I could upload the complete code of the working Keras4Delphi to my GitHub. When someone's interested let me know. Commented Jan 16, 2024 at 15:13
  • @Peter sadly the inventor of the Pascal language that is the base of Delphi died at the beginning of this month. RIP Niklaus Wirth. Commented Jan 16, 2024 at 16:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.