TensorFlow Configuration and Optimization Notes

Notes for installing TensorFlow on linux, with GPU enabled.

Background

TensorFlow is the second-generation ML framework from Google. (See this comparison of deep learning software.) The current state-of-the art image recognition models (inception-v3) use this framework.

Prequisites

Assuming Fedora 24 with Nvidia 1060 installed, running nvidia as opposed to nouveau drivers. See Fedora 24 Notes, and RPM Fusion’s installation page for installing the Nvidia drivers. In sum,

dnf install -y xorg-x11-drv-nvidia akmod-nvidia "kernel-devel-uname-r == $(uname -r)"
dnf install xorg-x11-drv-nvidia-cuda
dnf install vulkan

After, install some devel packages.

dnf install -y vulkan-devel

Download the Nvidia GPU CUDA Toolkit. The version used for this install is 8.0.61, and the network install for Fedora x86_64 was used.

This version of CUDA Toolkit is not C++11/C++14/C++17 aware. So, be aware! One way around this is to mod like below, and use -std=gnu++98.

117c117,118
 5
---
> /* bkoz use -std=c++98 if necessary */
> #if __GNUC__ > 6

Next, compile top-of-tree OpenCV (aka 3.2) with CUDA enabled. To do so, use the following configure list, mod for paths on system:

cmake -DVERBOSE=1 -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -std=gnu++98 -Wno-deprecated-gpu-targets" -D BUILD_EXAMPLES=1 -D BUILD_DOCS=1 -D WITH_OPENNI=1 -D WITH_CUDA=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -D WITH_FFMPEG=1 -D WITH_EIGEN=1 -D ENABLE_FAST_MATH=1 -D ENABLE_SSE3=1 -D ENABLE_AVX=1 -D CMAKE_BUILD_TYPE=RELEASE -D ENABLE_PRECOMPILED_HEADERS=OFF  -D CMAKE_INSTALL_PREFIX=/home/bkoz/bin/H-opencv -D OPENCV_EXTRA_MODULES_PATH=/home/bkoz/src/opencv_contrib.git/modules /home/bkoz/src/opencv.git/

Admittedly, this abuse of CMAKE_CXX_FLAGS is not optimal. Maybe EXTRA_CXX_FLAGS?

Now, for Nvidia cuDNN. The version used for this install is 5.1

When that is done, use pip to install TensorFlow.

sudo pip install --upgrade pip;
sudo pip install tensorflow-gpu

This should output something like:

Collecting tensorflow-gpu
  Downloading tensorflow_gpu-0.12.1-cp27-cp27mu-manylinux1_x86_64.whl (89.7MB)
    100% |████████████████████████████████| 89.7MB 19kB/s 
Requirement already satisfied: mock>=2.0.0 in /usr/lib/python2.7/site-packages (from tensorflow-gpu)
Requirement already satisfied: six>=1.10.0 in /usr/lib/python2.7/site-packages (from tensorflow-gpu)
Requirement already satisfied: numpy>=1.11.0 in /usr/lib64/python2.7/site-packages (from tensorflow-gpu)
Collecting protobuf>=3.1.0 (from tensorflow-gpu)
  Downloading protobuf-3.2.0-cp27-cp27mu-manylinux1_x86_64.whl (5.6MB)
    100% |████████████████████████████████| 5.6MB 284kB/s 
Collecting wheel (from tensorflow-gpu)
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
    100% |████████████████████████████████| 71kB 3.3MB/s 
Requirement already satisfied: pbr>=0.11 in /usr/lib/python2.7/site-packages (from mock>=2.0.0->tensorflow-gpu)
Requirement already satisfied: funcsigs>=1 in /usr/lib/python2.7/site-packages (from mock>=2.0.0->tensorflow-gpu)
Requirement already satisfied: setuptools in /usr/lib/python2.7/site-packages (from protobuf>=3.1.0->tensorflow-gpu)
Installing collected packages: protobuf, wheel, tensorflow-gpu
Successfully installed protobuf-3.2.0 tensorflow-gpu-0.12.1 wheel-0.29.0

After this has completed, add in Keras.

Optimization

For Nvidia GPUs, take a look at this interesting post from Netflix. In sum, add

NVreg_CheckPCIConfigSpace=0

Notes on the Deep Deep Deepest

 

Reading

 

Approaches

  • SVM (Support Vector Machines)
  • RBM (Restricted Boltzmann Machines)
  • NN/Convolution NN/DNN

 

Silicon Valley Fun

TensorFlow Dev Summit

February 15, 2017 @ googleplex, Mountain View, CA

 

Software

theano

  • python-theano-doc
  • python3-theano
  • python2-theano

tensorflow

  • TensorFlow
  • github
  • Current models for facial recognition include VGG-19, VGG-16, and inception-v3. Of the listed models, inception-v3 seems to have the advantage, at least as of early 2017.

keras

scikit-learn

opencv

 

GPU Hardware

Recommended GPUS are: Nvidia GTX 1080, 1070, 980, and 970. Maximize CUDA cores.

Fedora 25 Notes

Install:
San Francisco, California USA

Using x86_64 netinstall images as install media.

Update/Post-Install:

Use RPM Fusion Repositories.

Some basics

dnf install -y tcsh gnome-tweak-tool livecd-tools ncftp lftp

Install KDE, Razor-qt, and MATE Desktops

	 	 
dnf install -y lightdm-gtk-greeter-settings mate-desktop mate-applets nm-connection-editor network-manager-applet caja mate-themes bluecurve-gtk-themes gnome-themes-legacy;
dnf groupinstall mate-desktop;  
dnf groupinstall kde-desktop;
dnf install -y gnome-themes;

Optionally mate-compiz can be installed:

dnf groupinstall mate-compiz;

Install the basics for media and VLC

dnf install -y vlc vlc-core vlc-extras;
dnf install -y gaupol mediainfo

Install media xtra codecs.

dnf install -y ffmpeg ffmpeg-devel ffmpeg-compat-devel gstreamer-plugins-bad gstreamer-plugins-ugly gstreamer-plugins-good gstreamer-plugins-good-extras gstreamer-plugins-bad-free gstreamer-plugins-bad-free-extras gstreamer-plugins-bad-nonfree gstreamer-ffmpeg;
dnf install -y k3b-extras-freeworld;

Install negativo.
Use negativo17 repositories for HandBrake, volia.

dnf config-manager --add-repo=http://negativo17.org/repos/fedora-handbrake.repo;
dnf install -y HandBrake-gui HandBrake-cli;
dnf install -y makemkv mkvtoolnix mkvtoolnix-gui;
dnf install -y libdvdcss;

Use makemkv for Bluray.

Install some editors, utilities, and basics

dnf install -y calligra-words abiword emacs

Install devel 1

dnf install -y openni openni-devel openni-doc  tbb tbb-devel tbb-doc eigen3-devel eigen3-doc openrdate simple-mtpfs emacs python-BeautifulSoup

Install devel 2

dnf groupinstall -y "Development Tools";
dnf install -y gcc-c++ libstdc++-devel libstdc++-docs boost boost-devel boost-doc valgrind gdb elfutils nemiver dwarves dejagnu emacs expect flex bison cmake git-svn mpfr-devel libmpc-devel lsb;
dnf debuginfo-install glibc;

Install database

dnf install -y glom libpqxx-devel libpqxx postgresql-devel

Install computer vision (hand-build clandmarks and opencv if optimized)

dnf install -y CImg-devel rapidxml-devel opencv opencv-devel

Install graphic

dnf install -y freetype-freeworld inkscape* ufraw ufraw-gimp 

Install technical documentation toolchain

dnf install -y pdfedit texlive-pdfjam doxygen doxygen-latex graphviz  docbook5-style-xsl docbook5-schemas docbook2X docbook-style-xsl dblatex texinfo-tex dblatex docbook-utils-pdf  graphviz-python graphviz-R graphviz-graphs graphviz-doc R-core

Install sysadmin

sudo dnf install -y system-config-network system-config-samba system-config-services system-config-users system-config-firewall system-config-httpd

See separate posts on getting Nvidia and TensorFlow optimized CUDA up.

Issues

Something wrong with file indexing, it is consuming gigabytes of memory. Turn off search in the Gnome menu, but this is insufficient. Instead, use

balooctl disable

Set ulimits higher. Modify /etc/security/limits.cof like so:

*** limits.conf.f25	2016-12-11 23:27:46.609458649 -0800
--- limits.conf	2016-12-15 20:16:57.289245497 -0800
***************
*** 52,57 ****
--- 52,58 ----
  
  #*               soft    core            0
  #*               hard    rss             10000
+ 
  #@student        hard    nproc           20
  #@faculty        soft    nproc           20
  #@faculty        hard    nproc           50
***************
*** 59,61 ****
--- 60,67 ----
  #@student        -       maxlogins       4
  
  # End of file
+ 
+ bkoz               hard    nofile	8092
+ bkoz               soft    nofile       8092
+ 
+ 

In addition, it seems as if there is a bug with nmcli when using the Mate window manager. Mostly, it doesn’t work (along with nm-applet when used in a programmatic fashion from C/C++ code. So, use GNOME, as much as it hurts.

Fedora 24 Notes

Install:
San Francisco, California USA

Using x86_64 netinstall images as install media.

Update/Post-Install:

Use RPM Fusion Repositories.

Some basics

dnf install -y unrar tcsh gnome-tweak-tool livecd-tools ncftp lftp

Install KDE, Razor-qt, and MATE Desktops

	 	 
dnf install -y lightdm-gtk-greeter-settings mate-desktop mate-applets network-manager-applet caja mate-themes bluecurve-gtk-themes gnome-themes-legacy;
dnf groupinstall mate-desktop;  
dnf groupinstall kde-desktop;
dnf install -y gnome-themes;

Still a little sketchy, but optionally mate-compiz can be installed:

dnf groupinstall mate-compiz;

Install the basics for VLC

dnf install -y vlc vlc-core vlc-extras;
dnf install -y gaupol mediainfo

Install media xtra codecs.

dnf install -y ffmpeg ffmpeg-devel ffmpeg-compat-devel gstreamer-plugins-bad gstreamer-plugins-ugly gstreamer-plugins-good gstreamer-plugins-good-extras gstreamer-plugins-bad-free gstreamer-plugins-bad-free-extras gstreamer-plugins-bad-nonfree gstreamer-ffmpeg;
dnf install -y k3b-extras-freeworld;

Install negativo.
Use negativo17 repositories for HandBrake, volia.

dnf config-manager --add-repo=http://negativo17.org/repos/fedora-handbrake.repo;
dnf install -y HandBrake-gui HandBrake-cli;
dnf install -y makemkv mkvtoolnix mkvtoolnix-gui;
dnf install -y libdvdcss;

Use makemkv for Bluray.

Install some editors, utilities, and basics

dnf install -y abiword emacs tcsh

Install devel 1

dnf install -y openni openni-devel openni-doc  tbb tbb-devel tbb-doc eigen3-devel eigen3-doc openrdate simple-mtpfs emacs python-BeautifulSoup

Install devel 2

dnf groupinstall -y "Development Tools";
dnf install -y gcc-c++ libstdc++-devel libstdc++-docs boost boost-devel boost-doc valgrind gdb elfutils nemiver dwarves dejagnu emacs expect flex bison cmake git-svn mpfr-devel libmpc-devel lsb;
dnf debuginfo-install glibc;

Install database

dnf install -y glom libpqxx-devel libpqxx postgresql-devel

Install computer vision (hand-build clandmarks)

dnf install -y CImg-devel rapidxml-devel opencv opencv-devel

Install graphic

dnf install -y freetype-freeworld inkscape* ufraw ufraw-gimp 

Install technical documentation toolchain

dnf install -y pdfedit doxygen doxygen-latex graphviz  docbook5-style-xsl docbook5-schemas docbook2X docbook-style-xsl dblatex texinfo-tex dblatex docbook-utils-pdf  graphviz-python graphviz-R graphviz-graphs graphviz-doc R-core

Install sysadmin

sudo dnf install -y system-config-network system-config-samba system-config-services system-config-users system-config-firewall system-config-httpd

Multi Channel Display [2,3,4] vs. NUC Notes

Hardware

Intel NUC 6i5SYK (i5-6260U 1.8GHz, Mini DisplayPort 1.2, HDMI 1.4b, Iris 540)
Samsung 850 EVO 250 GB M.2 SSD
Kingston HyperX 16GB DDR4

 

Display
1 x Sony VPL-FHZ55 projector
1 x 1920 x 1080 display AOC
2 x 1920 x 1080 Samsung TV
2 x 1920 x 1600 Dell 2407 LCD
Club 3d Multi Stream Transport Hub
1 x HDMI M to DVI M cable
1 x HDMI M to HDMI M 3M
1 x DisplayPort M to Mini DisplayPort M
2 x DisplayPort M to HDMI M

 

Software

Fedora 23 as per previous notes.

Then, either update xorg-x11-drv-intel to 2016 drop by cannibalizing F24 development, or install via Intel Graphics Installer for Linux. See Intel Open Source site, ie 01.org.

Some useful background information from the Fedora Project on How to Debug Xorg Problems.

To probe the current graphics situation, run

grep " (--) " /var/log/Xorg.0.log

Other useful queries

grep " (II) " /var/log/Xorg.0.log;
grep " (II) " /var/log/Xorg.0.log | grep connected;
grep " (II) " /var/log/Xorg.0.log | grep drm;
grep " (II) " /var/log/Xorg.0.log | grep EDID;

 

On the NUC, the above gives the following output

[bkoz@otis log]$ grep " (II) " /var/log/Xorg.0.log | grep EDID;
[    17.236] (II) VESA(0): EDID Version: 1.3
[    17.237] (II) VESA(0): EDID (in hex):
[    17.237] (II) VESA(0): EDID vendor "AOC", prod id 9063
[    17.237] (II) VESA(0): Using EDID range info for horizontal sync
[    17.237] (II) VESA(0): Using EDID range info for vertical refresh

[bkoz@otis log]$ grep " (--) " /var/log/Xorg.0.log
[    17.157] Markers: (--) probed, (**) from config file, (==) default setting,
[    17.165] (--) PCI:*(0:0:2:0) 8086:1926:8086:2063 rev 10, Mem @ 0xde000000/16777216, 0xc0000000/268435456, I/O @ 0x0000f000/64, BIOS @ 0x????????/131072
[    17.223] (==) VESA(0): Depth 24, (--) framebuffer bpp 32
[    17.284] (--) VESA(0): Virtual size is 1920x1080 (pitch 1920)

 

Test matrix

SW Connection-Display-Driver Status
F23 1 x HDMI 1080p vesa OK
F23 1 x Mini DisplayPort 1080p vesa visible but clipped

 

Future Attempts

Hand-rolled xorg.conf files. See How to create xorg.conf.

Windows 10 is supported.

Can MacOS + mini drive 4 x displays?

Fedora 23 Notes

Install:
San Francisco, California USA

usb media

Update/Post-Install:

Some basics

dnf install -y unrar tcsh gnome-tweak-tool livecd-tools

Install KDE, Razor-qt, and MATE Desktops

	 	 
dnf install -y razorqt lightdm-gtk-greeter-settings mate-desktop mate-applets network-manager-applet caja mate-themes bluecurve-gtk-themes gnome-themes-legacy;
dnf groupinstall mate-compiz;  
dnf groupinstall kde-desktop;

Install media.
Use RPM Fusion Repositories.

dnf install -y vlc vlc-core vlc-extras;
dnf install -y gaupol mediainfo

Install media xtra codecs.

dnf install -y ffmpeg ffmpeg-devel ffmpeg-compat-devel gstreamer-plugins-bad gstreamer-plugins-ugly gstreamer-plugins-good gstreamer-plugins-good-extras gstreamer-plugins-bad-free gstreamer-plugins-bad-free-extras gstreamer-plugins-bad-nonfree gstreamer-ffmpeg;
dnf install -y k3b-extras-freeworld;

Install negativo.
Use negativo17 repositories for HandBrake, volia.

dnf config-manager --add-repo=http://negativo17.org/repos/fedora-handbrake.repo;
dnf install -y HandBrake-gui HandBrake-cli;
dnf install -y makemkv mkvtoolnix mkvtoolnix-gui;
dnf install -y libdvdcss;

Install utilities and basics

abiword

Install devel 1

dnf install -y openni openni-devel openni-doc  tbb tbb-devel tbb-doc eigen3-devel eigen3-doc guvcview openrdate simple-mtpfs emacs python-BeautifulSoup

Install devel 2

dnf groupinstall -y "Development Tools";
dnf install -y gcc-c++ libstdc++-devel libstdc++-docs boost boost-devel boost-doc valgrind gdb elfutils nemiver dwarves dejagnu emacs expect flex bison cmake git-svn mpfr-devel libmpc-devel lsb;
dnf debuginfo-install glibc;

Install database

dnf install -y glom libpqxx-devel libpqxx postgresql-devel

Install graphic

dnf install -y freetype-freeworld inkscape* ufraw ufraw-gimp 

Install technical documentation toolchain

dnf install -y pdfedit doxygen doxygen-latex graphviz  docbook5-style-xsl docbook5-schemas docbook2X docbook-style-xsl dblatex texinfo-tex dblatex docbook-utils-pdf  graphviz-python graphviz-R graphviz-graphs graphviz-doc R-core

Install sysadmin

sudo dnf install -y system-config-network system-config-samba system-config-services system-config-users system-config-firewall system-config-httpd

Fedora 21 Notes

Install:
San Francisco, California USA

yum install -y fedup; 
fedup --network 21 --profile workstation

Update/Post-Install:

Install KDE and MATE

	 	 
yum install -y @mate-desktop @kde-desktop
yum install -y @mate-desktop @kde-desktop

Use negativo17 repositories for HandBrake, volia.