I created a machine learning model with keras using python. I saved this model in a .h5 file and want to use that file in my ASP.NET Core API. To load the model I am using Keras.NET.
The problem I am encountering is that when I try to debug the application I get the following error:
Message: System.BadImageFormatException : An attempt was made to load a program with an incorrect format. (0x8007000B) Stack Trace: Runtime.Py_IsInitialized() Runtime.Initialize(Boolean initSigs) PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv, Boolean initSigs) PythonEngine.Initialize(Boolean setSysArgv, Boolean initSigs) PythonEngine.Initialize() Keras.InstallAndImport(String module) <.cctor>b__27_0() Lazy`1.ViaFactory(LazyThreadSafetyMode mode) Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) Lazy`1.CreateValue() Lazy`1.get_Value() Keras.get_Instance() Sequential.ctor()
I have read about other people encountering this problem. They say that I should change my Platform Target to x64.
Doing that leads to the following error:
Message: System.BadImageFormatException : Could not load file or assembly 'Project.Core, Version=220.127.116.11, Culture=neutral, PublicKeyToken=null'. An attempt was made to load a program with an incorrect format. Stack Trace: ModelsTest.Test_models()
Now the rest of my tests are failing with a
BadImageFromatException. This let me to think that python is installed as a 64 bit version and .NET Core as a 32 bit. To make sure this is not the case I reinstalled the 64 bit version of .NET Core but I keep getting the same error.
I hope someone can help me.
User contributions licensed under CC BY-SA 3.0