Emgu TF Download And Installation

From Emgu CV: OpenCV in .NET (C#, VB, C++ and more)
Revision as of 17:49, 25 January 2021 by Canming (talk | contribs)
Jump to navigation Jump to search

Windows

Nuget

Using nuget package manager is probably the easiest way to include Emgu TF library in your project.

Open Source Release

  • From your project, right click on "References" and select "Manager Nuget Packages..." option. It will open up nuget package manager. In package source, make sure that "nuget.org" is selected. (If you are using the commercial release, please check the instruction in the commercial download area for instructions to setup the commercial release nuget repository.)
Emgu TF
  • Under "Browse", enter the search text "emgu.tf.runtime" and you should be able to find the Emgu.TF.runtime.windows nuget package.

Please make sure the package is created by "Emgu Corporation" for the official release.

  • Click the "Install" button. Nuget will download Emgu.TF.runtime.windows and configure the project for you.
Emgu TF Lite
  • Under "Browse", enter the search text "emgu.tf.lite.runtime" and you should be able to find the Emgu.TF.Lite.runtime.windows nuget package.

Please make sure the package is created by "Emgu Corporation" for the official release.

  • Click the "Install" button. Nuget will download Emgu.TF.Lite.runtime.windows and configure the project for you.

Commercial Release

  • If you are using the commercial release, please check the instruction in the commercial download area for instructions to setup the commercial release nuget repository.
  • Commercial release download link can be found in the "Download Instructions" at the bottom of your purchase complete page. It is also available on the product delivery email, under the "CUSTOMER SERVICE" session, it appears as a link under "Your Order Data". Please click on the link to access the Commercial release download session.
  • If you have the Professional / Ultimate license. The instruction can be found in "windows/nuget.txt" file.
  • If you have the Windows only license. The instructions can be found in "nuget.txt" file
  • Once the commercial nuget repository is set up, you can browse it, there should be serveral packages: Emgu.TF.runtime.windows-CR is the commercial release runtime of TF without CUDA; Emgu.TF.runtime.windows.cuda-CR is the commercial release runtime of TF with CUDA support. Emgu.TF.Lite.runtime.windows-CR is the commercial release runtime of TF Lite.
  • Click the "Install" button. Nuget will download Emgu commercial release and configure the project for you.

The type initializer for 'Emgu.TF.TfInvoke' threw an exception.

If you see this exception, please check the following

Are you missing any dependency?

Download Dependency Walker and use it to open the "tfextern.dll" or "tfliteextern.dll" file. Check if any dependency is missing.

Linux

Getting ready

Ubuntu 20.04

  • dotnet SDK
    • For 4.5.1 release, you will need dotnet SDK 5.0. Please follow this instruction to install asp .net core on Ubuntu. Once that is done, run the following command to verify dotnet is installed:
      ubuntu:~$ dotnet --list-runtimes
      It should show a message similar to the following
      Microsoft.AspNetCore.App 5.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  • CMake
    • Emgu TF & Emgu TF Lite has adapted to use cmake to compile its source code.
  • Installing GIT so you can check out the project folder, you can install GIT by running
    sudo apt-get install git

Raspberry Pi OS

  • dotnet SDK
    • For 4.5.1 release, you will need dotnet SDK 5.0
  • CMake
    • Emgu TF & Emgu TF Lite has adapted to use cmake to compile its source code.
  • Installing GIT so you can check out the project folder, you can install GIT by running
    sudo apt-get install git

Getting the source code

  • To build from source, you will need a Git client to check out the source code from SourceForge. For more information, see GIT. The following command can be used to check out the source:
git clone https://github.com/emgucv/emgutf emgutf 
  • Go to emgutf directory
cd emgutf
  • Initialize tensorflow and submodules
git submodule update --init --recursive

Configuring & Building the project

Ubuntu 20.04

  • Got to the configuration folder.
    cd platforms/ubuntu/20.04
  • Installing the prerequisites. This only needs to be run once. You can install them by running
    ./apt_install_dependency
Tensorflow
  • If you are build Emgu TF, use the following command to build the tensorflow:
    bazel_build_tf
  • Skip the build steps for Tensorflow Lite below
Tensorflow Lite
  • If you are build Emgu TF Lite, use the following command to build the tensorflow:
    bazel_build_tflite
  • Skip the build steps for Tensorflow above
Emgu TF / Emgu TF Lite
  • Build the managed Emgu TF or Emgu TF Lite code using the following command:
    build_emgutf

Raspberry Pi OS

  • Got to the configuration folder
cd platforms/raspbian
  • Installing the perquisites

This only needs to be run once. You can install the prerequisites by running

./apt_install_dependency
Tensorflow
  • If you are build Emgu TF, use the following command to build the tensorflow:
    bazel_build_tf
  • Skip the build steps for Tensorflow Lite below
Tensorflow Lite
  • If you are build Emgu TF Lite, use the following command to build the tensorflow:
    bazel_build_tflite
  • Skip the build steps for Tensorflow above
Emgu TF / Emgu TF Lite
  • Build the managed Emgu TF or Emgu TF Lite code using the following command:
    build_emgutf


Running the Examples

Emgu TF

  • We have the native binary compiled. Now let's compile and run our first dot net core program.
cd Emgu.TF.Example\Inception.Console.NetCore
  • make sure dotnet can load the dynamic library from the current location by typing
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
  • Try to compile and run the program on ubuntu:
dotnet run
  • Or, if you are on Raspbian OS,
 LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libatomic.so.1 dotnet run

Emgu TF Lite

  • We have the native binary compiled. Now let's compile and run our first dot net core program.
cd Emgu.TF.Example\Inception.Console.Lite.NetCore
  • make sure dotnet can load the dynamic library from the current location by typing
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
  • Try to compile and run the program on ubuntu:
dotnet run
  • Or, if you are on Raspbian OS,
 LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libatomic.so.1 dotnet run

System.DllNotFoundException

If you encounter this exception, there might be missing dependencies. In this case, go to libs\x64 folder (or libs\arm folder, or libs\x86 folder, depends on your system architecture).

Run this command for Emgu TF: ldd libtfextern.so

Run this command for Emgu TF Lite: ldd libtfliteextern.so

and check if there is any dependency missing.

If not, go back to project folder and run this command

gdb dotnet

then, on the (gdb) commandline, type

run run

to debug with GDB.

You can also try

LD_DEBUG=libs dotnet run

to find missing dependencies.