dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
9.02k stars 1.88k forks source link

Get Error when Loading Model. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: Unable to load DLL 'tensorflow' or one of its dependencies #4112

Closed RussellKirkwood closed 4 years ago

RussellKirkwood commented 5 years ago

ITransformer trainedModel = mlContext.Model.Load(stream, out modelInputSchema); When loading Model into ITransformer I get the following error:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: Unable to load DLL 'tensorflow' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E) at Tensorflow.c_api.TF_NewGraph() at Tensorflow.Graph..ctor() at Microsoft.ML.Transforms.Dnn.DnnUtils.LoadTFSession(IExceptionContext ectx, Byte[] modelBytes, String modelFile) at Microsoft.ML.Transforms.TensorFlowTransformer.Create(IHostEnvironment env, ModelLoadContext ctx) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstanceCore(Object[] ctorArgs) at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstance(IHostEnvironment env, Object args, Object[] extra) at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes](IHostEnvironment env, Type signatureType, TRes& result, String name, String options, Object[] extra) at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes,TSig](IHostEnvironment env, TRes& result, String name, String options, Object[] extra) at Microsoft.ML.ModelLoadContext.TryLoadModelCore[TRes,TSig](IHostEnvironment env, TRes& result, Object[] extra) at Microsoft.ML.ModelLoadContext.TryLoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, Entry ent, String dir, Object[] extra) at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, Entry ent, String dir, Object[] extra) at Microsoft.ML.ModelLoadContext.LoadModelOrNull[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, String dir, Object[] extra) at Microsoft.ML.ModelLoadContext.LoadModelOrNull[TRes,TSig](IHostEnvironment env, TRes& result, String name, Object[] extra) at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, String name, Object[] extra) at Microsoft.ML.Data.TransformerChain`1..ctor(IHostEnvironment env, ModelLoadContext ctx) at Microsoft.ML.Data.TransformerChain.Create(IHostEnvironment env, ModelLoadContext ctx)

aslotte commented 5 years ago

I'm having the same issue on a VM I've installed the required dependencies on. Does anyone have an idea of what the cause could be?

codemzs commented 4 years ago

Please upgrade to preview-2 and reopen the issue if you are still seeing this error.

ddobric commented 4 years ago

Hi @codemzs, I have the same issue with preview2.

Dependencies:

image

Error

image

Interestingly, I do not see tensorflow.dll even in my local self-contained deployment. I also checked the list of loaded modules on the local version. The only tensor related assembly is TensorFlow.NET.dll

ddobric commented 4 years ago

I have found a solution for this "issue". It is not an issue. I would rather declare it as a missing documentation.

Please take a look here: https://developers.de/2019/10/25/hosting-ml-net-in-appservice/

yasir9624 commented 4 years ago

I am having the same issue in my .NET windows forms application, can someone help please

rua26x commented 4 years ago

i think for the issue you just need to install scisharp from nuget package image

strikene commented 4 years ago

I have the same problem, but it doesn't seem to be the x86 x64 problem In my project, even if I install SCI and set fuction to x64 to start debugging, I still can't find DLL if I set debugging to anycpu, I will get DLL that cannot be loaded. Once I set debugging to x64, CLI will not load my functions. The error is system. Private. Corelib: could not load file or assembly 'myfunction, version = 1.0.0.0. What else can I do,

I think Microsoft doesn't want you to use models in function

I have installed the following packages "Microsoft.Azure.Functions.Extensions" Version="1.0.0" "Microsoft.Extensions.DependencyInjection" Version="2.2.0" "Microsoft.Extensions.ML" Version="1.4.0" "Microsoft.ML" Version="1.4.0" "Microsoft.ML.ImageAnalytics" Version="1.4.0" "Microsoft.ML.Vision" Version="1.4.0" "Microsoft.NET.Sdk.Functions" Version="1.0.29" "SciSharp.TensorFlow.Redist" Version="1.14.0"

RF1ALR%JZ }O MZ{ARCN4%C

strikene commented 4 years ago

@RussellKirkwood
I have solved this problem by doing the following 1 add packages "Microsoft.Azure.Functions.Extensions" Version="1.0.0" "Microsoft.Extensions.DependencyInjection" Version="2.2.0" "Microsoft.Extensions.ML" Version="1.4.0" "Microsoft.ML" Version="1.4.0" "Microsoft.ML.ImageAnalytics" Version="1.4.0" "Microsoft.ML.Vision" Version="1.4.0" "Microsoft.NET.Sdk.Functions" Version="1.0.29" "SciSharp.TensorFlow.Redist" Version="1.14.0" 2 change To X64 (Because tensorflow can't run on x86) 3 download function cli tool X64 ,(Because tensorflow can't run on x86)By default vs will use x86 cli for debugging you can find download link in C:\Users\youusername\AppData\Local\AzureFunctionsTools\feed- v3.json it looks like "OS": "Windows", "Architecture": "x64", "downloadLink": "https://functionscdn.azureedge.net/public/3.0.2358/Azure.Functions.Cli.min.win-x64.3.0.2358.zip", "sha2": "c4520c6b25398eb096154909fe60db4b85aaa65b31724394db1c35d6ae71f6da"

4 use X64 CLI func.EXE host start You can do this on the project property page or you can start it with your own script O E%HLANL4S5DVUIWC366 L

in my project Executble set to the X64 CLI The worikingdirectory is set to generate directory, which contains a host.json I hope it helps you

jpd21122012 commented 4 years ago

@strikene Can you help me?, I'm on Console App (.NET Core), and I've followed your instructions but the new CLI at the final just start the host and doesn't run my app

strikene commented 4 years ago

@strikene Can you help me?, I'm on Console App (.NET Core), and I've followed your instructions but the new CLI at the final just start the host and doesn't run my app

Console App do not need azure function cli Press F5 to run you apps

jpd21122012 commented 4 years ago

@strikene Got it, but when I press F5 changing to x64 says that assembly.dll not found and if I change to AnyCPU Config says the tensorflow.dll error

strikene commented 4 years ago

@strikene Got it, but when I press F5 changing to x64 says that assembly.dll not found and if I change to AnyCPU Config says the tensorflow.dll error

Can you share your project with me and remember to delete the privacy data

jpd21122012 commented 4 years ago

@strikene It's the official Proyect from Microsoft ML.NET, here's the link https://github.com/dotnet/machinelearning-samples/tree/master/samples/csharp/getting-started/DeepLearning_ImageClassification_TensorFlow

I'm trying with "DeepLearning_ImageClassification_TensorFlow" and "DeepLearning_ImageClassification_Training" proyects

SnowmanTackler commented 4 years ago

I'm also trying to run the stock sample app "TFModelScorer" (locally, not in azure) and running into issues.

When running with "Any CPU" config:

EXCEPTION ######### System.FormatException: Tensorflow exception triggered while loading model. ---> System.DllNotFoundException: Unable to load DLL 'tensorflow' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E) at Tensorflow.c_api.TF_NewGraph() at Tensorflow.Graph..ctor() at Microsoft.ML.TensorFlow.TensorFlowUtils.LoadTFSessionByModelFilePath(IExceptionContext ectx, String modelFile, Boolean metaGraph) --- End of inner exception stack trace --- at Microsoft.ML.TensorFlow.TensorFlowUtils.LoadTFSessionByModelFilePath(IExceptionContext ectx, String modelFile, Boolean metaGraph) at Microsoft.ML.TensorFlow.TensorFlowUtils.GetSession(IHostEnvironment env, String modelPath, Boolean metaGraph) at Microsoft.ML.TensorflowCatalog.LoadTensorFlowModel(ModelOperationsCatalog catalog, String modelLocation) at ImageClassification.ModelScorer.TFModelScorer.LoadModel(String dataLocation, String imagesFolder, String modelLocation) in E:\Git\temp\machinelearning-samples\samples\csharp\getting-started\DeepLearning_ImageClassification_TensorFlow\ImageClassification\ModelScorer\TFModelScorer.cs:line 67 at ImageClassification.ModelScorer.TFModelScorer.Score() in E:\Git\temp\machinelearning-samples\samples\csharp\getting-started\DeepLearning_ImageClassification_TensorFlow\ImageClassification\ModelScorer\TFModelScorer.cs:line 51 at ImageClassification.Program.Main(String[] args) in E:\Git\temp\machinelearning-samples\samples\csharp\getting-started\DeepLearning_ImageClassification_TensorFlow\ImageClassification\Program.cs:line 23

When running with "x64" config: C:\Program Files (x86)\dotnet\dotnet.exe (process 6164) exited with code -532462766. To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. Press any key to close this window . . .

I've made no changes to the sample app, and from Visual Studio's perspective, all the dependencies look alright:

vs

renwang1612 commented 4 years ago

It is the same issue I got "System.DllNotFoundException: 'Unable to load DLL 'tensorflow' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)'" when trying to run the first line var t1 = new Tensor(3);

strikene commented 4 years ago

@strikene It's the official Proyect from Microsoft ML.NET, here's the link https://github.com/dotnet/machinelearning-samples/tree/master/samples/csharp/getting-started/DeepLearning_ImageClassification_TensorFlow

I'm trying with "DeepLearning_ImageClassification_TensorFlow" and "DeepLearning_ImageClassification_Training" proyects

Hi I'm sorry to reply a little late . items in the links you provide I can run "deep learning_imageclassification_tensorflow" without any modification. I can't load "deep learning_imageclassification_training", and I can't make a valuable explanation for this so...... I didn't use the example mentioned in your link, I reorganized a core application, and the program now works.

1
you must set PlatformTarget to X64!!!!! you must use .net core 2.1 2.2 3.0 3.1!!!!!
framework can not work!!!!!!

<PackageReference Include="Microsoft.ML" Version="1.5.0-preview2" />
<PackageReference Include="Microsoft.ML.ImageAnalytics" Version="1.5.0-preview2" />
<PackageReference Include="Microsoft.ML.Vision" Version="1.5.0-preview2" />
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.1.0" />

2 code

demo.txt

I hope you can work properly.

strikene commented 4 years ago

I'm also trying to run the stock sample app "TFModelScorer" (locally, not in azure) and running into issues.

When running with "Any CPU" config:

EXCEPTION ######### System.FormatException: Tensorflow exception triggered while loading model. ---> System.DllNotFoundException: Unable to load DLL 'tensorflow' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E) at Tensorflow.c_api.TF_NewGraph() at Tensorflow.Graph..ctor() at Microsoft.ML.TensorFlow.TensorFlowUtils.LoadTFSessionByModelFilePath(IExceptionContext ectx, String modelFile, Boolean metaGraph) --- End of inner exception stack trace --- at Microsoft.ML.TensorFlow.TensorFlowUtils.LoadTFSessionByModelFilePath(IExceptionContext ectx, String modelFile, Boolean metaGraph) at Microsoft.ML.TensorFlow.TensorFlowUtils.GetSession(IHostEnvironment env, String modelPath, Boolean metaGraph) at Microsoft.ML.TensorflowCatalog.LoadTensorFlowModel(ModelOperationsCatalog catalog, String modelLocation) at ImageClassification.ModelScorer.TFModelScorer.LoadModel(String dataLocation, String imagesFolder, String modelLocation) in E:\Git\temp\machinelearning-samples\samples\csharp\getting-started\DeepLearning_ImageClassification_TensorFlow\ImageClassification\ModelScorer\TFModelScorer.cs:line 67 at ImageClassification.ModelScorer.TFModelScorer.Score() in E:\Git\temp\machinelearning-samples\samples\csharp\getting-started\DeepLearning_ImageClassification_TensorFlow\ImageClassification\ModelScorer\TFModelScorer.cs:line 51 at ImageClassification.Program.Main(String[] args) in E:\Git\temp\machinelearning-samples\samples\csharp\getting-started\DeepLearning_ImageClassification_TensorFlow\ImageClassification\Program.cs:line 23

When running with "x64" config: C:\Program Files (x86)\dotnet\dotnet.exe (process 6164) exited with code -532462766. To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. Press any key to close this window . . .

I've made no changes to the sample app, and from Visual Studio's perspective, all the dependencies look alright:

vs

add package Microsoft.ML.Vision ,Maybe solve a problem.

morasblog commented 4 years ago

follow SnowmanTackler it works When running with "x64-bits"

hjoshuaj commented 3 years ago

I am having the same issue as @strikene. I installed Visual Studio onto my desktop and cloned the packaged mentioned by @strikene. I've done all the suggestions in this forum, but I'm unable to build it (I'm getting the same errors that were mentioned in this forum). Was anyone able to make this work @RussellKirkwood, @SnowmanTackler, @jpd21122012?

kongdebug commented 3 years ago

I am having the same issue as @strikene. I installed Visual Studio onto my desktop and cloned the packaged mentioned by @strikene. I've done all the suggestions in this forum, but I'm unable to build it (I'm getting the same errors that were mentioned in this forum). Was anyone able to make this work @RussellKirkwood, @SnowmanTackler, @jpd21122012?

hey,I'm getting the same errors…Have you solved the problem now?

jpd21122012 commented 3 years ago

I am having the same issue as @strikene. I installed Visual Studio onto my desktop and cloned the packaged mentioned by @strikene. I've done all the suggestions in this forum, but I'm unable to build it (I'm getting the same errors that were mentioned in this forum). Was anyone able to make this work @RussellKirkwood, @SnowmanTackler, @jpd21122012?

hey,I'm getting the same errors…Have you solved the problem now?

Hi, I was able to run with x64 platform configuration

kongdebug commented 3 years ago

I am having the same issue as @strikene. I installed Visual Studio onto my desktop and cloned the packaged mentioned by @strikene. I've done all the suggestions in this forum, but I'm unable to build it (I'm getting the same errors that were mentioned in this forum). Was anyone able to make this work @RussellKirkwood, @SnowmanTackler, @jpd21122012?

hey,I'm getting the same errors…Have you solved the problem now?

Hi, I was able to run with x64 platform configuration

I am having the same issue as @strikene. I installed Visual Studio onto my desktop and cloned the packaged mentioned by @strikene. I've done all the suggestions in this forum, but I'm unable to build it (I'm getting the same errors that were mentioned in this forum). Was anyone able to make this work @RussellKirkwood, @SnowmanTackler, @jpd21122012?

hey,I'm getting the same errors…Have you solved the problem now?

Hi, I was able to run with x64 platform configuration

Hello, I also ran with x64 platform and used .net core 3.1…My project is the C # console program…Can you share your project with me and remember to delete the privacy data?

hjoshuaj commented 3 years ago

This helped solve my problem. I was using a CPU that did not support AVX. As soon as I switched it ran perfectly.