This guide is courtesy of kenr1234 in our Shinobi Community chat. Thank you Ken!

Shinobi's default install location is /home/Shinobi, this will be the path mentioned in step 3 and 9.

This guide also assumes you are running the TensorFlow Object Detection Plugin for Shinobi as a daemon (NOT started from Superuser panel), not as a child process (started from Superuser panel).

  1. Install git. This will already be installed if you installed Shinobi with the Ninja Way.
    • sudo apt install git -y
  2. Install bazel building tool.
    • sudo install bazel
      • The latest appears to be v8.31 at the time of writing this document, which is what Ken had used on his server.
  3. Clone the version of tensorflow you want to use. I tried the latest (v2.20) but the make files do not have the libtensorflow target which I think is a bug (probably be fixed soon). So I settled for 2.19.0.
  4. Change to the directory git created.
    • cd tensorflow and execute ./configure
  5. For the configure options I selected all the defaults except for CUDA = N (I don't have a GPU in my server), Clang = N.
  6. Now build the libtensorflow target.
    • bazel build -c opt --copt=-march=native --copt=-mfpmath=sse --config=monolithic //tensorflow/tools/lib_package:libtensorflow
  7. Now go get a coffee, it takes a long time to build even on my dual CPU Xeon server. There are many options possible but -march=native will build a library matching the hardware you're building on.
  8. If successful, you'll have the following file under the tensorflow build directory...
    • bazel-bin/tensorflow/tools/lib_package/libtensorflow.tar.gz
  9. Copy this file to the tensorflow plugin deps directory.
    • sudo cp /home/Shinobi/tensorflow/bazel-bin/tensorflow/tools/lib_package/libtensorflow.tar.gz /home/Shinobi/plugins/dl_tensorflow-4-1-0/node_modules/@tensorflow/tfjs-node/deps
  10. Extract the files and symbolic links.
    • cd /home/shinobi/plugins/dl_tensorflow-4-1-0/node_modules/@tensorflow/tfjs-node/deps
      sudo tar -xvzf libtensorflow.tar.gz
  11. Now you should see a filestructure like this
    • /home/Shinobi/plugins/dl_tensorflow-4-1-0/node_modules/@tensorflow/tfjs-node/deps/lib
      total 509620
      drwxr-xr-x 2 root root 4096 Dec 31 1999 .
      drwxr-xr-x 4 shinobi shinobi 4096 Sep 1 12:50 ..
      lrwxrwxrwx 1 root root 28 Dec 31 1999 libtensorflow_framework.so -> libtensorflow_framework.so.2
      lrwxrwxrwx 1 root root 33 Dec 31 1999 libtensorflow_framework.so.2 -> libtensorflow_framework.so.2.19.0
      -r-xr-xr-x 1 root root 49169304 Dec 31 1999 libtensorflow_framework.so.2.19.0
      lrwxrwxrwx 1 root root 18 Dec 31 1999 libtensorflow.so -> libtensorflow.so.2
      lrwxrwxrwx 1 root root 23 Dec 31 1999 libtensorflow.so.2 -> libtensorflow.so.2.19.0
      -r-xr-xr-x 1 root root 472468040 Dec 31 1999 libtensorflow.so.2.19.0
      -r-xr-xr-x 1 root root 13575 Dec 31 1999 LICENSE
      -r-xr-xr-x 1 root root 182565 Dec 31 1999 THIRD_PARTY_TF_C_LICENSES
  12. Restart the plugin.
    • pm2 restart shinobi-tensorflow

Additionally, now you can run the tester for the plugin in the Superuser panel and you should see it detecting as expected.