sh Paperspace上ubuntu 16上的python-2/3的Tensorflow + opencv设置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh Paperspace上ubuntu 16上的python-2/3的Tensorflow + opencv设置相关的知识,希望对你有一定的参考价值。
#!/bin/bash
# Don't require you to constantly enter password for sudo:
sudo visudo
# In the bottom of the file, paste the following (without the `#`):
# paperspace ALL=(ALL) NOPASSWD: ALL
# Then press `ctl+o` then `enter` to save your changes, and `ctr+x` to exit nano
# Allow connection from your IP to any port- default seems to be just 22 (ssh)
sudo ufw allow from <YOUR_EXTERNAL_IP_AT_HOME> to any
# START OF RUN ON YOUR MAC!
# START OF RUN ON YOUR MAC!
# It's only commented out so it doesn't accidently get run on your server
# Passwords are a crappy and annoying way to login to a server when you can just use ssh keys
# ssh-copy-id paperspace@<SERVER IP>
# END OF RUN ON TOUR MAC!
# END OF RUN ON YOUR MAC!
# Now disable password login
sudo nano /etc/ssh/sshd_config
# replace `PasswordAuthentication yes` with `PasswordAuthentication no`- may need to uncomment the line in the config.
# Then press `ctl+o` then `enter` to save your changes, and `ctr+x` to exit nano
sudo service ssh restart
# Allow connection from any IP to port 22, now that we're using keys
sudo ufw allow from any to any port 22
# Stuff for making stuff
sudo apt-get update
sudo apt-get install -y build-essential gcc checkinstall cmake pkg-config git unzip wget gdb
# Download some nvidia stuff
# http://www.nvidia.com/content/DriverDownload-March2009/confirmation.php?url=/XFree86/Linux-x86_64/375.39/NVIDIA-Linux-x86_64-375.39.run&lang=us&type=GeForce
# https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v5.1/prod_20161129/8.0/cudnn-8.0-linux-x64-v5.1-tgz
# https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run
# Install the drivers
# make sure you say yes to gl and to linking to /usr/local
chmod a+x NVIDIA-Linux-x86_64-375.39.run
sudo ./NVIDIA-Linux-x86_64-375.39.run
# Install CUDA
# say NO to installing the drivers!
chmod a+x cuda_8.0.61_375.26_linux.run
sudo ./cuda_8.0.61_375.26_linux.run
# Install CUDNN
tar -xvf cudnn-8.0-linux-x64-v5.1.tgz
cd cuda
sudo cp -P include/cudnn.h /usr/include
sudo cp -P lib64/libcudnn* /usr/lib/x86_64-linux-gnu/
sudo chmod a+r /usr/lib/x86_64-linux-gnu/libcudnn*
sudo cp include/cudnn.h /usr/local/cuda-8.0/include
sudo cp lib64/libcudnn* /usr/local/cuda-8.0/lib64
sudo chmod a+r /usr/local/cuda-8.0/lib64/libcudnn*
sudo ldconfig
# Add bazel repo
echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
sudo apt-get update
# Remove existing old crap
sudo apt-get autoremove -y libopencv-dev python-opencv
# Some Libs
sudo apt-get install openjdk-8-jdk git python-dev python3-dev python-numpy python3-numpy python-six python3-six build-essential python-pip python3-pip python-virtualenv swig python-wheel python3-wheel libcurl3-dev libcupti-dev
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
# Some libs
# libgoogle-glog-dev
sudo apt-get install -y qt5-default qt5-qmake libvtk6-dev tcl-vtk libxmu-dev liblapack-dev liblapacke liblmdb-dev libgflags-dev
sudo apt-get install -y libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libatlas-base-dev openjdk-8-jdk libcurl3-dev libcupti-dev swig
# Python shtuff
sudo apt-get install -y python-pip
pip install --upgrade pip
pip install numpy
sudo apt-get install -y python3-pip
pip3 install --upgrade pip
pip3 install numpy
# Media I/O:
sudo apt-get install -y zlib1g-dev libjpeg-dev libjpeg8-dev libwebp-dev libpng-dev libpng12-dev libtiff5-dev libjasper-dev libopenexr-dev libgdal-dev
# Video I/O:
sudo apt-get install -y 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
# Math libraries:
sudo apt-get install -y gfortran libtbb-dev libeigen3-dev libleveldb-dev libsnappy-dev libboost-dev libhdf5-dev
# libprotobuf-dev
# Java:
sudo apt-get install -y ant default-jdk
# Documentation:
sudo apt-get install -y doxygen
# Install bazel
sudo apt-get install bazel
sudo apt-get upgrade bazel
# INSTALL OPENCV
wget https://github.com/opencv/opencv/archive/3.2.0.zip
unzip 3.2.0.zip
rm 3.2.0.zip
#mv opencv-3.2.0 OpenCV
cd opencv-3.2.0
mkdir build
cd build
cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_NEW_PYTHON_SUPPORT=ON ..
make -j4
sudo make install
sudo ldconfig
# TEST CV2 (these should both print out 3.2.0)
cd ~/
python -c 'import cv2;print(cv2.__version__)'
python3 -c 'import cv2;print(cv2.__version__)'
# Install python packages
sudo pip install scipy numpy matplotlib ipython jupyter pandas sympy nose pillow scikit-learn statsmodels
sudo pip3 install scipy numpy matplotlib ipython jupyter pandas sympy nose pillow scikit-learn statsmodels
# Jupyter notebook bind to 0.0.0.0 by default
mkdir ~/.jupyter
touch ~/.jupyter/jupyter_notebook_config.py
echo "c.NotebookApp.ip = '0.0.0.0'" | sudo tee -a ~/.jupyter/jupyter_notebook_config.py
echo "c.ConnectionFileMixin.ip = '0.0.0.0'" | sudo tee -a ~/.jupyter/jupyter_notebook_config.py
# Installing tensorflow!
# COMPUTE CAPABILITY IS 6.1
cd ~/
wget https://github.com/tensorflow/tensorflow/archive/v1.1.0.zip
unzip v1.1.0.zip
rm v1.1.0.zip
mv tensorflow-1.1.0 tensorflow-1.1.0_py2
cp -rd tensorflow-1.1.0_py2 tensorflow-1.1.0_py3
# Tensorflow Python 2:
# COMPUTE CAPABILITY IS 6.1
cd ~/tensorflow-1.1.0_py2
./configure
# May need to add ``, don't remember
bazel build --config=opt --copt=-march=native --config=cuda --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" -k //tensorflow/tools/pip_package:build_pip_package
mkdir pip_build
bazel-bin/tensorflow/tools/pip_package/build_pip_package `pwd`/pip_build
cd pip_build
sudo pip install tensorflow*
cd ~/
python -c 'import tensorflow as tf;hello=tf.constant("Hello, TensorFlow!");sess=tf.Session();print(sess.run(hello))'
# Tensorflow Python 3:
# COMPUTE CAPABILITY IS 6.1
# When configuring, make sure you set the python to python3 when asked: /usr/bin/python3
cd ~/tensorflow-1.1.0_py3
./configure
bazel build --config=opt --copt=-march=native --config=cuda --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" -k //tensorflow/tools/pip_package:build_pip_package
mkdir pip_build
bazel-bin/tensorflow/tools/pip_package/build_pip_package `pwd`/pip_build
cd pip_build
sudo pip3 install tensorflow*
cd ~/
python3 -c 'import tensorflow as tf;hello=tf.constant("Hello, TensorFlow!");sess=tf.Session();print(sess.run(hello))'
# Assuming the above worked, let's clean up after ourselves:
cd ~/
mkdir setup_stuff
sudo rm -rdf cuda
mv tensorflow* setup_stuff
mv tensorflow* setup_stuff
mv cud* setup_stuff
mv NVIDIA-Linux* setup_stuff
mv opencv* setup_stuff
以上是关于sh Paperspace上ubuntu 16上的python-2/3的Tensorflow + opencv设置的主要内容,如果未能解决你的问题,请参考以下文章