Skip to content

Instantly share code, notes, and snippets.

@bsantraigi
Forked from Zhomart/tensorflow-cpu.sh
Created November 20, 2017 06:25
Show Gist options
  • Save bsantraigi/212604ee08dc9b896f264a87226d0844 to your computer and use it in GitHub Desktop.
Save bsantraigi/212604ee08dc9b896f264a87226d0844 to your computer and use it in GitHub Desktop.
Compile and install tensorflow on Ubuntu 16.04. You might want to create a virtual machine on GCP, AWS, then compile tensorflow there. And then download compiled `*.wheel` file for further using it. List of compiled tensorflow with different options can be found here https://github.com/yaroslavvb/tensorflow-community-wheels/issues.
#!/bin/bash
##
## FROM https://github.com/floydhub/dl-docker
##
## Before running the script change versions and compilation flags below.
## If you're having trouble running the whole script, try running
## each command separately.
##
## List of compiled tensorflow packages https://github.com/yaroslavvb/tensorflow-community-wheels/issues
set -e
apt-get update && apt-get install -y \
bc \
build-essential \
cmake \
curl \
g++ \
gfortran \
git \
libffi-dev \
libfreetype6-dev \
libhdf5-dev \
libjpeg-dev \
liblcms2-dev \
libopenblas-dev \
liblapack-dev \
libpng12-dev \
libssl-dev \
libtiff5-dev \
libwebp-dev \
libzmq3-dev \
nano \
pkg-config \
python-dev \
software-properties-common \
unzip \
vim \
wget \
zlib1g-dev \
qt5-default \
libvtk6-dev \
zlib1g-dev \
libjpeg-dev \
libwebp-dev \
libpng-dev \
libtiff5-dev \
libjasper-dev \
libopenexr-dev \
libgdal-dev \
libdc1394-22-dev \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
libtheora-dev \
libvorbis-dev \
libxvidcore-dev \
libx264-dev \
yasm \
libopencore-amrnb-dev \
libopencore-amrwb-dev \
libv4l-dev \
libxine2-dev \
libtbb-dev \
libeigen3-dev \
python-dev \
python-tk \
python-numpy \
ant \
default-jdk \
doxygen
# Link BLAS library to use OpenBLAS using the alternatives mechanism (https://www.scipy.org/scipylib/building/linux.html#debian-ubuntu)
update-alternatives --set libblas.so.3 /usr/lib/openblas-base/libblas.so.3
# Install pip
curl -O https://bootstrap.pypa.io/get-pip.py && \
python get-pip.py && \
rm get-pip.py
# Add SNI support to Python
pip --no-cache-dir install \
pyopenssl \
ndg-httpsclient \
pyasn1
# Install useful Python packages using apt-get to avoid version incompatibilities with Tensorflow binary
# especially numpy, scipy, skimage and sklearn (see https://github.com/tensorflow/tensorflow/issues/2034)
apt-get install -y \
python-numpy \
python-scipy \
python-nose \
python-h5py \
python-skimage \
python-matplotlib \
python-pandas \
python-sklearn \
python-sympy
# Install other useful Python packages using pip
pip --no-cache-dir install --upgrade ipython && \
pip --no-cache-dir install \
Cython \
ipykernel \
jupyter \
path.py \
Pillow \
pygments \
six \
sphinx \
wheel \
zmq \
&& \
python -m ipykernel.kernelspec
# # Install Theano and set up Theano config (.theanorc) OpenBLAS
# pip --no-cache-dir install git+git://github.com/Theano/Theano.git@${THEANO_VERSION} && \
# \
# echo "[global]\ndevice=cpu\nfloatX=float32\nmode=FAST_RUN \
# \n[lib]\ncnmem=0.95 \
# \n[nvcc]\nfastmath=True \
# \n[blas]\nldflag = -L/usr/lib/openblas-base -lopenblas \
# \n[DebugMode]\ncheck_finite=1" \
# > /root/.theanorc
# Install bazel
echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list \
&& curl https://bazel.build/bazel-release.pub.gpg | apt-key add - \
&& apt-get update && apt-get install -y bazel
# get tensorflow source code
git clone https://github.com/tensorflow/tensorflow ~/tensorflow \
&& cd ~/tensorflow \
&& git checkout v1.1.0
# configure it
# Say No to: GPU support
./configure
# Build with support of avx, avx2, fma, mse4.1, gmse4.2
bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-msse4.1 --copt=-msse4.2 -k //tensorflow/tools/pip_package:build_pip_package
# build pip package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
# install
pip install /tmp/tensorflow/*.wheel
# # Install Keras
# RUN pip --no-cache-dir install git+git://github.com/fchollet/keras.git@${KERAS_VERSION}
# # Install other useful Python packages using pip
# RUN pip --no-cache-dir install \
# gensim \
# nltk
# RUN python -m nltk.downloader stopwords
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment