运行 VS单元测试下的CNTK模型
Running a CNTK model under a VS unit test
我已经使用 C# 训练了一个 CNTK 模型,现在我想 运行 针对包装器 class 测试用例,这样我们就可以在有人用一个不适合的模型替换模型时检测到问题'它的表现也一样好,并且还对神经网络与我们的旧模型进行了重复比较。但是,当我尝试 运行 测试时,我得到:
Result StackTrace:
at CNTK.CNTKLibPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_CNTKLib(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate)
at CNTK.CNTKLibPINVOKE.SWIGExceptionHelper..cctor()
--- End of inner exception stack trace ---
...
System.TypeInitializationException: The type initializer for 'CNTK.CNTKLibPINVOKE' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'Cntk.Core.CSBinding-2.3.1.dll': A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)
我从独立的控制台应用程序中得到了同样的错误,并通过确保控制台应用程序和 class 库都构建为 x64 来修复它。我对测试项目进行了相同的更改,另外将测试架构设置为 x64(测试 > 测试设置 > 默认处理器架构 > x64),但没有骰子。
我正在使用 CNTK (2.3.1) 的 GPU 版本,但对于单元测试上下文它应该使用 CPU。我已经验证 Cntk.Core.CSBinding-2.3.1.dll 存在于 bin 目录中。
有什么想法吗?有人试过吗?
如果您使用的是 NUnit,我见过很多这样的情况。 CNTK 包中有一堆本机 DLL,测试运行器找不到它们,因为工作目录设置为某个临时目录,而不是输出文件夹。我的解决方案是在每次测试开始时将所有必需的 DLL 复制到工作目录。我在相关 [TestFixture] 的 [SetUp] 方法中执行此操作。
如果你使用的是不同的测试框架,可能也会有类似的问题。
我在使用 NUnit 时遇到了同样的问题。将以下代码添加到测试设置中,解决了我的问题。
[SetUp]
public void Setup()
{
Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory;
}
我已经使用 C# 训练了一个 CNTK 模型,现在我想 运行 针对包装器 class 测试用例,这样我们就可以在有人用一个不适合的模型替换模型时检测到问题'它的表现也一样好,并且还对神经网络与我们的旧模型进行了重复比较。但是,当我尝试 运行 测试时,我得到:
Result StackTrace:
at CNTK.CNTKLibPINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_CNTKLib(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate)
at CNTK.CNTKLibPINVOKE.SWIGExceptionHelper..cctor()
--- End of inner exception stack trace ---
...
System.TypeInitializationException: The type initializer for 'CNTK.CNTKLibPINVOKE' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'Cntk.Core.CSBinding-2.3.1.dll': A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)
我从独立的控制台应用程序中得到了同样的错误,并通过确保控制台应用程序和 class 库都构建为 x64 来修复它。我对测试项目进行了相同的更改,另外将测试架构设置为 x64(测试 > 测试设置 > 默认处理器架构 > x64),但没有骰子。
我正在使用 CNTK (2.3.1) 的 GPU 版本,但对于单元测试上下文它应该使用 CPU。我已经验证 Cntk.Core.CSBinding-2.3.1.dll 存在于 bin 目录中。
有什么想法吗?有人试过吗?
如果您使用的是 NUnit,我见过很多这样的情况。 CNTK 包中有一堆本机 DLL,测试运行器找不到它们,因为工作目录设置为某个临时目录,而不是输出文件夹。我的解决方案是在每次测试开始时将所有必需的 DLL 复制到工作目录。我在相关 [TestFixture] 的 [SetUp] 方法中执行此操作。
如果你使用的是不同的测试框架,可能也会有类似的问题。
我在使用 NUnit 时遇到了同样的问题。将以下代码添加到测试设置中,解决了我的问题。
[SetUp]
public void Setup()
{
Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory;
}