Skip to content

Unable to load DLL 'tensorflow' with published WPF app #5170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ntpthinh opened this issue May 27, 2020 · 6 comments
Closed

Unable to load DLL 'tensorflow' with published WPF app #5170

ntpthinh opened this issue May 27, 2020 · 6 comments
Assignees
Labels
bug Something isn't working image Bugs related image datatype tasks question Further information is requested

Comments

@ntpthinh
Copy link

System information

  • OS version/distro: Window 10
  • .NET Version (eg., dotnet --info): .NET framework 4.7.2

Issue

  • What did you do? I'm trying sample code for image classification using MLNet.
  • What happened? Everything works fine in development environment which means that I can use model to predict label of images. However, when I tried to publish a ClickOnce application, the exception System.DllNotFoundException: Unable to load DLL 'tensorflow': The specified module could not be found keeps throwing.
  • What did you expect? I want to know how to deliver WPF application with MLNet properly

Source code / logs

System.DllNotFoundException: Unable to load DLL 'tensorflow': The specified module could not be found.
image

For source code, it is the same as https://docs.microsoft.com/en-us/dotnet/machine-learning/tutorials/image-classification but I update the code to see if all libraries is loaded correctly

WpfApp1.zip

@michaelgsharp michaelgsharp added bug Something isn't working image Bugs related image datatype tasks question Further information is requested labels May 27, 2020
@mstfbl mstfbl assigned mstfbl and michaelgsharp and unassigned mstfbl May 27, 2020
@michaelgsharp
Copy link
Contributor

I downloaded your project and it looks like there are a couple of things going on.

The tensorflow package is installed correctly, but the .dll file was not getting copied over correctly. Doing a full clean on the project should fix this issue, but if it doesn't fix it, deleting the .vs folder inside the same folder as the .sln file will fix it for sure. Doing a build after that resolves the tensor flow issue.

In ML.Net 1.4 we also have a bug where CpuMathNative doesn't get loaded correctly. This is fixed in the latest 1.5 release of ML.Net, so I also recommend you update to version 1.5.

The project is not including the assets folder. I am not sure if they were manually copied to the output folder, or if you removed them before uploading to save space, but make sure the assets and sub-folders are added to the project as well.

Doing these things fixes the runtime issues and allows you to do a publish like normal.

Closing this for now, if you still have questions or problems please re-open the ticket.

@ntpthinh
Copy link
Author

ntpthinh commented May 28, 2020

I followed your suggestion but it is still not working. Did you try the published version in other computers which don't have the environment (like brand-new client computer)? Because in my case, the publish app works on my local computer but not on others.

I did update to ML.Net 1.5 and copy asset folder to the project but temporarily removed to show you the code
<Content Include="assets\*\*"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content>

Besides, I don't really get how the app finds its library as I see tensorflow presented here but it keeps saying tensorflow not found. If you have time, please point me out the document. Thank you
image

@harishsk harishsk reopened this May 29, 2020
@michaelgsharp
Copy link
Contributor

I can repro this as well if I deploy/run on a non-development computer. It has something to do with the dll dependency and the click-once deployment. I'm looking more into that.

@michaelgsharp
Copy link
Contributor

The DLL is getting transferred over to the target machine, but its unable to find it. I am trying to trace down why its not looking in the correct spot.

@michaelgsharp
Copy link
Contributor

Alright, the issue is that you have the incorrect version of the SciSharp.TensorFlow.Redist nuget installed. Change the version to be 1.14.0 and it will work. I was able to verify that on my machine that was reproducing the error. I am going to close issue as resolved, but if after changing the version you still have issue please reopen the ticket so we can continue to look into it.

@ntpthinh
Copy link
Author

ntpthinh commented Jun 2, 2020

After changing SciSharp.TensorFlow.Redist to 1.14.0, it works on other computer too. It takes me some times to confirm since I tested it on cloud computer and the error message changed to "Unable to load 'tensorflow': A dynamic link library(DLL) initialization routine failed. I don't know if the problem is mine or on your side but it works on other physical computers. Thank you for your time.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working image Bugs related image datatype tasks question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants