DlibDotNet
DlibDotNet copied to clipboard
How to dockerize an app that uses this library
Summary of your issue
I created a simple console app to get facial landmarks on a Wİndows 10 machine. I get the facial landmarks of an input image and write the landmarks on an output image. The app is working without a problem. However, when I create the docker image of the console app and run the docker image I get an exception. Unhandled exception. System.TypeInitializationException: The type initializer for 'DlibDotNet.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'DlibDotNetNativeDnn' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libDlibDotNetNativeDnn: cannot open shared object file: No such file or directory at DlibDotNet.NativeMethods.LossMetric_anet_type_create() at DlibDotNet.NativeMethods..cctor() --- End of inner exception stack trace --- at DlibDotNet.NativeMethods.get_frontal_face_detector() at DlibFaceProject.Program.Main(String[] args) in /src/DlibFaceProject/Program.cs:line 18
Line 18 is the first place where we call a DLib method.
@ffrankozz
DlibDotNetNativeDnn depends on some library so you must install them into container.
ldd -v
command could tell you what libraries are missing.
And You can refer https://github.com/takuya-takeuchi/DlibDotNet/wiki/Tutorial-for-Linux to resolve issue.
@takuya-takeuchi Thank you very much for your reply. I will have a look at the link you refer to. In the mean time, where do I run that "ldd -v" command? Is it a command to run in the root of the project?
I'm not sure how you installed dlibdotnet.
but if using nuget, you can see /root/.nuget/package/dlibdotnet.
And you can find libdlibdonetnativednn.so and invoke ldd -v libdlibdotnetnativednn.so
@takuya-takeuchi Thank you for your directions. I have taken a different approach. I created a docker image from your ubuntu base file. I then created the runtime docker image using the base image.
Using the resulting image as base, I created my own app's Dockerfile.
I created the image successfully.
Everything runs smoothly... No exceptions except for one thing:
My app detects landmarks on faces. The landmarks located on the input image are saved in a jpg file named output.jpg in the root folder of the project via Dlib.SaveJpeg(img, "output.jpg").
Now the problem: The app runs as expected when we run it via dotnet run, and I see the output.jpg file created, with landmarks.
However, when I dockerize the app, everything runs smoothly again with docker image -no exceptions whatsoever- but I see NO output.jpg file in the root folder of the project. Why do you think it is not creating the output.jpg when we run the docker image.
@ffrankozz
but I see NO output.jpg file in the root folder of the project.
I think this is not dlibdotnet issue. SaveJpeg would save image file to current directory. Therefore
- Specify abosulte path to avoid confusion
- Check current actual current directory by
Console.WriteLine(System.Environment.CurrentDirectory)
when running apps - Check host machine directory if mount app directory
@takuya-takeuchi Thank you very much for the suggestions. It is strange that everything is fine with normal desktop build and run. But when dockerized, the docker image, when run, reads the input picture file, data file which are in the project root but somehow I cannot see the saved output image in the current directory. I changed the output picture saving location to somewhere in the local drive, but still no output picture there. I can read the bytes of the output file and write on the console. I am sure the output image is being created. But somehow not visible. I now it is not a dlibdotnet issue but I just wanted to share it. Perhaps, mounting app directory will help. I will try that next.