CNTK Cpu Eval Doesn't Load Model
Hi,
I tried using Microsoft.Research.CNTK.CpuEval-acml version 1.5 EvalWrapper on nuget and it fails to load the model path I give it. I had to revert to a version 1.4 dll for it to work.
When I execute:
var model = Helpers.LoadModel(ModelPath, OutputLayerName);
var pixelMeans = new float[Channels * ImageSize * ImageSize];
var inputLayerName = GetFirstInputLayer(model);
...
public static string GetFirstInputLayer(IEvaluateModelManagedF model)
{
var inDims = model.GetNodeDimensions(NodeGroup.nodeInput);
return inDims.First().Key;
}
I get the following exception:
An unhandled exception of type 'System.AccessViolationException' occurred in EvalWrapper.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
The same exact code works with version 1.4 of the dll. The exception is thrown on GetNodeDimensions. It seems like the model isn't loaded into memory properly.
Michael, Are you still experiencing this exception in 1.5? The modelPath property should be specified similarly to the following:
string modelFilePath = @"C:\CNTK\Models\ResNet_18.model";
model.CreateNetwork(string.Format("modelPath=\"{0}\"", modelFilePath), deviceId: -1);
Let me know.
Thanks, Gaizka
If the issue is still open: I am experiencing this problem right now.
I have Visual Studio 2015 on Windows 10, the CNTK V 2.0 Beta-5 GPU installed on my machine, use the latest stable NuGet package (1.7.3), but have also tried 2.0.0beta-5.
Right now I am trying to use model.CreateNetwork both by specifying modelFilePath as well as creating the test description form this example. And still getting the same exception.
What may I possibly do wrong.
Thanks in advance,
Kolya
@KolyaIvankov The current Nuget Package as well as the examples only work with CPU only device, as described in the Wiki page . Could you please try to download the CPU binary drop and try to run the CSEvalClient project in examples? And let me know if you have problems.
@zhouwangzw Thanks for help. I've been thinking that a CPU-only-trained model (with deviceId=-1 in the description) may then be ran from the package, even if I have a GPU binary.
Anyway, the problem persists.
I have set up a CPU version of CNTK V2.0 Beta-5 on my machine (verified this by running examples with deviceId=auto and getting it run on CPU), upgraded my VS 2013 to Update 5 version and was able to run the CSEvalClient project on 01_OheHidden and 02_OneConv examples (commented out the rest to save time on building networks).
Then, I have reinstalled the CNTK beta5 NuGet package, attaching to the startup project in my solution, and tried to load model from the aforementioned example. Still getting the same exception.
I am using a VS 15 Community right now, so I guess I won't be able to debug and see what's happening in the CNTK code.
UPD: I've succeeded to load my model in CSEvalClient though. I'm definitely still missing something there as I'm getting an exception of the kind "No Output nodes found: Cannot determine Input node dimensions due to lack of Output", but at least it's thrown at the next step.
@KolyaIvankov Have you trained your model using Python or BrainScript? If you were training the model using Python, it is not supported to load the model by using EvalBase interface in the Nuget Package. You may try with the EvalExtended interface there, as describe in #1050. We are currently working on C# Eval V2 API which supports evaluation of Python models. The new API will be available soon. Sorry for the inconvenience and stay tuned for the new API. Thanks.
@zhouwangzw I've been using BrainScript.
But, as I have mentioned above, the same problem also occurs in VS 2015 in the example with the single-node model defined manually as a string:
string modelDefinition = @"precision = ""float""
traceLevel = 1
run=NDLNetworkBuilder
NDLNetworkBuilder=[
i1 = Input(1)
o1 = Times(Constant(3), i1, tag=""output"")
FeatureNodes = (i1)
]";
and then applying:
model.CreateNetwork(modelDefinition, deviceId: -1);
I wish I could have helped figuring out the exact place where the bug occurs, but currently I lack means for that. As far as I can figure out, the problem seems to occur only in VS 2015 for now.
Thank you very much for support!
@KolyaIvankov I tried with VS2015 using Nuget Package. Both CSEvalClient.sln as well as the single-node model definition you provide worked without problem. One thing you may want to pay attention to is that each config/setting in the model definition should be a separate line, like below:
string modelDefinition = @"precision = ""float""
traceLevel = 1
run=NDLNetworkBuilder
NDLNetworkBuilder=[
i1 = Input(1)
o1 = Times(Constant(3), i1, tag=""output"")
FeatureNodes = (i1)
]";
If you still have problem, could you please share the exception message you get?
Thanks,
@zhouwangzw Ok, it seems that I have ignored the notice that the package works only with the projects aimed for x64 processors. After changing from Any CPU to x64 I don't have this issue any more.
Thanks for patience!
@KolyaIvankov Glad to know that you found the cause. Yes, CNTK has to work on the X64 platform. I am closing the issue and feel free to reopen it if needed.
I am trying CNTK Language example and able to run the windows application. But when i try to run through a web application in VS2015 and i am getting the below error.
at CNTK.CNTKLibPINVOKE.Function_LoadModel__SWIG_0(String jarg1, HandleRef jarg2) at CNTK.Function.LoadModel(String modelFile, DeviceDescriptor computeDevice) at CNTKLibraryCSEvalExamples.CNTKLibraryManagedExamples.EvaluationSingleSequenceUsingOneHot(String input) in C:\Proj\Evaluation\CNTKLibraryCSEvalCPUOnlyExamples\CNTKLibraryCSEvalExamples.cs:line 345
can you please help to resolve this issue.
@pythonMasters The error looks like that some depenent dlls cannot be found by the Web application. Have you set the PATH in your web application, as described here? The page describes the usage of EvalDll in web application. The dlls are different for CNTKLibrary SDK, but the principle is the same. We will update the sample and page to use the CNTKLibrary SDK soon.
Thanks this solution worked.
@zhouwangzw, I am facing similar issue when i publish the application to windows 2012 R2 virtual server. In VS 2015 development mode application running perfectly with the global.asax correction, i have verified the global.asax and path correction also available after publishing to the server. what could be the issue ? I know this is related to path issue but all possible things that i am able to find i have tried but no luck.
CNTK requires 64-bit support, so the process hosting CNTK library should run in 64-bit mode.
I have IIS 8.5 and default mode is 64 bit unless we tick the option to run in 32 bit mode. Is this the process what you have mentioned or some other process such worker process ? how do we make worker process to be run in 64bit and how do we check what is the current setting ?
Unable to load DLL 'CNTKLibraryCSBinding': The specified module could not be found. (Exception from HRESULT: 0x8007007E) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.DllNotFoundException: Unable to load DLL 'CNTKLibraryCSBinding': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[DllNotFoundException: Unable to load DLL 'CNTKLibraryCSBinding': The specified module could not be found. (Exception from HRESULT: 0x8007007E)] CNTK.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) +0 CNTK.SWIGExceptionHelper..cctor() +1044
[TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception.] CNTK.SWIGExceptionHelper..ctor() +0 CNTK.CNTKLibPINVOKE..cctor() +28
[TypeInitializationException: The type initializer for 'CNTK.CNTKLibPINVOKE' threw an exception.] EmISearch.CNTKLibraryManagedExamples1.EvaluationSingleSequenceUsingOneHot(String input) +4234 EmISearch.home1.buildresults(String input) +761 EmISearch.home1.Page_Load(Object sender, EventArgs e) +367 System.Web.UI.Control.LoadRecursive() +71 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178
You may want ot check IIS Manager -> Advanced Settings or C:\Windows\System32\inetsrv\config\applicationHost.config to ensure that IIS is in 64-bit mode. In addtion, please set the PATH in your web application, as described here. (The page describes the usage of EvalDll in web application. The dlls are different for CNTKLibrary SDK, but the principle is the same. We will update the sample and page to use the CNTKLibrary SDK soon).
Thanks for the information above,
Above problem got resolved after copying all the CNTK files into /bin folder of the web site and i had different versions in my laptop and web server. Both this actions solved the above issue and it's nothing to do with 64 bit since it was already on 64 bit environment (IIS and build)
But have a different problem now.
System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception. at CNTK.UtilsPINVOKE.Function_LoadModel__SWIG_0(String jarg1, HandleRef jarg2) at CNTK.Function.LoadModel(String modelFile, DeviceDescriptor computeDevice) at WebApplication1.Default.EvaluationSingleSequenceUsingOneHot(String input)
It's giving this error now. Could you please help me resolving this issue.
@shantha-Ekanayake The error is most likely related to dependent native dlls that cannot be found. Have you updated the PATH to include the bin folder as described in the page https://github.com/Microsoft/CNTK/wiki/Evaluate-a-model-in-an-Azure-WebApi#lets-get-started? ◦The directory of the created binaries in our solution needs to get added to the PATH environment of the application. This is required since our project includes native DLLs, and those are only loaded if they are reachable in the standard search path. We added the following code in the Application_Start() method in global.asax : string pathValue = Environment.GetEnvironmentVariable("PATH"); string domainBaseDir = AppDomain.CurrentDomain.BaseDirectory; string cntkPath = domainBaseDir + @"bin"; pathValue += ";" + cntkPath; Environment.SetEnvironmentVariable("PATH", pathValue);
Thanks, Zhou
Thanks Zhou, Path changes are already there in the global.asax file, Is this error something to do with versions of the DLLs, same code is running in my visual studio debug mode without any error. How do we find the issue, any debug output will help ?
@shantha-Ekanayake Which CNTK version are you using? And could you please give me a list of files available in the /bin folder?