CUDASemantic Segmentation机器学习与数据挖掘

AWS EC2 服务建立云端Deep Learning开发环境

2017-11-17  本文已影响21人  李亚鑫

1. AWS EC2 的建立

Ubuntu Server 14.04 LTS (HVM), SSD Volume Type - ami-48db9d28

目前只有g2.2xlarge是最廉价的方案,里面的硬盘空间最大为60g


Root - /dev/sda1 60GB ebs - /dev/sdb 200GB

2. Access EC2 through ssh


ssh -i "weiwei_0903.pem" ubuntu@ec2-52-53-235-35.us-west-1.compute.amazonaws.com

3. 加载 EBS 到刚才建立的 GPU Instance

ubuntu@ip-*-*-*-*:~$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 8G 0 disk `-xvda1 202:1 0 8G 0 part / xvdb 202:16 0 100G 0 disk /home/ubuntu/workspace
[ec2-user ~]$ sudo file -s /dev/xvdb /dev/xvdb: data
[ec2-user ~]$ sudo mkfs -t ext4 /dev/xvdb
ec2-user ~]$ sudo file -s /dev/xvdb /dev/xvdb: Linux rev 1.0 ext4 filesystem data, UUID=1701d228-e1bd-4094-a14c-8c64d6819362 (needs journal recovery) (extents) (large files) (huge files)
ubuntu@ip-*-*-*-*:~$ sudo mount /dev/xvdb workspace ubuntu@ip-*-*-*-*:~$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 8G 0 disk `-xvda1 202:1 0 8G 0 part / xvdb 202:16 0 100G 0 disk /home/ubuntu/workspace
$ sudo chmod go+rw workspace
/dev/sda = /dev/xvda in the instance 8Gb "EBS persistent storage" /dev/sdb = /dev/xvdb in the instance 400Gb "Non persistent storage"
df -h

4. 安装相关软件

sudo apt-get update 
sudo apt-get upgrade 
sudo apt-get install -y build-essential git python-pip libfreetype6-dev libxft-dev libncurses-dev libopenblas-dev gfortran python-matplotlib libblas-dev liblapack-dev libatlas-base-dev python-dev python-pydot linux-headers-generic linux-image-extra-virtual unzip python-numpy swig python-pandas python-sklearn unzip wget pkg-config zip g++ zlib1g-dev 
sudo pip install -U pip
git clone https://gist.github.com/weiweikong/374e93d9ccb88ea45341268a06897259 aws-tensorflow-python2.7-setup
# stop on error 
set -e 
############################################
 # install into /mnt/bin 
sudo mkdir -p /mnt/bin 
sudo chown ubuntu:ubuntu /mnt/bin
wget https://repo.continuum.io/archive/Anaconda2-4.1.1-Linux-x86_64.sh 
bash Anaconda2-4.1.1-Linux-x86_64.sh -b -p /mnt/bin/anaconda2 
rm Anaconda2-4.1.1-Linux-x86_64.sh 
echo 'export PATH="/mnt/bin/anaconda2/bin:$PATH"' >> ~/.bashrc
# install the required packages 
sudo apt-get update && sudo apt-get -y upgrade 
sudo apt-get -y install linux-headers-$(uname -r) linux-image-extra-`uname -r`
# install cuda wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/cuda-repo-ubuntu1404_7.5-18_amd64.deb 
sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb
rm cuda-repo-ubuntu1404_7.5-18_amd64.deb 
sudo apt-get update 
sudo apt-get install -y cuda
scp -i your_pem_file.pem cudnn-7.5-linux-x64-v5.0-ga.tgz ubuntu@ec2-54-67-18-98.us-west-1.compute.amazonaws.com:~/.
# get cudnn 
tar xvzf cudnn-7.5-linux-x64-v5.1.tgz 
cd cuda 
sudo cp lib64/* /usr/local/cuda/lib64/ 
sudo cp include/* /usr/local/cuda/include/ 
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn* 

echo 'export CUDA_HOME=/usr/local/cuda 
export CUDA_ROOT=/usr/local/cuda 
export PATH=$PATH:$CUDA_ROOT/bin:$HOME/bin 
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_ROOT/lib64 
' >> ~/.bashrc
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl /mnt/bin/anaconda2/bin/pip install $TF_BINARY_URL
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler 
sudo apt-get install --no-install-recommends libboost-all-dev 
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
cp Makefile.config.example Makefile.config
# Adjust Makefile.config (for example, if using Anaconda Python, or if cuDNN is desired)

mkdir build 
cd build 
cmake ..
make all 
make test 
make runtest
sh data/mnist/get_mnist.sh 
sh examples/mnist/create_mnist.sh 
sh examples/mnist/train_lenet.sh
# install monitoring programs 
sudo wget https://git.io/gpustat.py -O /usr/local/bin/gpustat 
sudo chmod +x /usr/local/bin/gpustat 
sudo nvidia-smi daemon 
sudo apt-get -y install htop

4.1 Trouble Shooting

sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
sudo ln /dev/null /dev/raw1394
$ nvidia-smi 
CUDA_VISIBLE_DEVICES=1 Only device 1 will be seen 
CUDA_VISIBLE_DEVICES=0,1 Devices 0 and 1 will be visible 
CUDA_VISIBLE_DEVICES=”0,1” Same as above, quotation marks are optional
CUDA_VISIBLE_DEVICES=0,2,3 Devices 0, 2, 3 will be visible; device 1 is masked

4.2 Access to EC2 using FileZilla

上一篇下一篇

猜你喜欢

热点阅读