Rebuilding TensorFlow Library for Object Detection
This is how you can build the TensorFlow library for the TensorFlow 4.1.0 Object Detection Shinobi plugin. This is only necessary if you are experiencing "Segmentation Fault" or constant crashing of your TensorFlow object detection plugin.
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).
-
Install git. This will already be installed if you installed Shinobi with the Ninja Way.
-
sudo apt install git -y
-
-
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.
-
-
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.
-
cd /home/Shinobi
git clone --branch v2.19.0 https://github.com/tensorflow/tensorflow- To see all the tags that are available just browse to https://github.com/tensorflow/tensorflow/tags
-
-
Change to the directory git created.
-
cd tensorflow and execute ./configure
-
- For the configure options I selected all the defaults except for CUDA = N (I don't have a GPU in my server), Clang = N.
-
Now build the libtensorflow target.
-
bazel build -c opt --copt=-march=native --copt=-mfpmath=sse --config=monolithic //tensorflow/tools/lib_package:libtensorflow
-
-
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. -
If successful, you'll have the following file under the tensorflow build directory...
-
bazel-bin/tensorflow/tools/lib_package/libtensorflow.tar.gz
-
-
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
-
-
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
-
-
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
-
-
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.