python - 如何修复 Keras.NET BadImageFormatException 异常?
问题描述
我使用 python 创建了一个带有 keras 的机器学习模型。我将此模型保存在一个 .h5 文件中,并希望在我的 ASP.NET Core API 中使用该文件。要加载我使用 Keras.NET 的模型。
我遇到的问题是,当我尝试调试应用程序时,出现以下错误:
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()
我读过其他人遇到这个问题。他们说我应该将我的平台目标更改为 x64。
这样做会导致以下错误:
Message:
System.BadImageFormatException : Could not load file or assembly 'Project.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. An attempt was made to load a program with an incorrect format.
Stack Trace:
ModelsTest.Test_models()
现在我的其余测试都以BadImageFromatException
. 这让我认为 python 安装为 64 位版本,.NET Core 安装为 32 位版本。为了确保不是这种情况,我重新安装了 .NET Core 的 64 位版本,但我一直收到同样的错误。
我希望有一个人可以帮助我。
解决方案
推荐阅读
- php - 如何从数组中删除所有相同或共同的值..它是不同的..?
- r - R tableGrob 热图或列中的条件格式
- c# - 图像处理循环中的内存异常(需要比 GC.collect 更好的解决方案)
- excel-formula - 返回 0 而不是 #N/A
- c++ - 无法将子类转换为父类
- c++ - 防止用户离开 std::experimental::filesystem 中的目录
- java - 如何从java中的文本文件中提取具有列约束的行数据
- c# - 如何将外键保存到多个表 asp.net mvc 实体
- react-native - 使用 react-native 构建安卓 apk
- maps - Bing Maps Tile Source Uri 构造函数设置自定义标头