Ubuntu系統安裝與深度學習環境配置


Ubuntu系統安裝與深度學習環境配置

Ubuntu系統安裝

  • 官網下載ubuntu的iso文件,按照官網介紹制作啟動盤,官網下載參考1參考2

  • 插入U盤,開機按F11選擇啟動項為U盤(需要將boot改為UEFI引導)

  • Try ubuntu,進去之后選擇install ubuntu

  • 不要選擇刪除或者和window共存,選擇其他安裝

  • 分區:需要將/boot所在分區修改為安裝啟動引導器的設備,其中/boot為啟動引導盤,200-500M;swap為虛擬交換內存,為電腦內存的2倍;/為系統盤,所有軟件的安裝位置;/home為其他盤,用於存儲文件

分區 大小 類型 文件
/boot 500M 邏輯分區 Ex4
swap 30G 邏輯分區 swap
/ 150G 主分區 Ex4
/home 300G 主分區 Ex4
  • 等待安裝完成,重啟,拔出U盤

Ubuntu系統基本設置

  • 設置用戶用戶密碼 sudo passwd root

  • 進入root用戶 su 然后退出 exit

  • 更改系統的源

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
vim /etc/apt/sources.list
# 從 mirrors.aliyun.com復制ubuntu 18.04的設置
  • 更新系統軟件
sudo apt update
sudo apt upgrade
  • 禁止內核更新:一定要禁止內核更新,不然新內核與驅動不匹配,導致驅動不可用 參考1 參考2
dpkg --get-selections |grep linux-image     # 顯示所有的內核
dpkg --get-selections |grep linux
uname -r    # 當前所有內核

sudo apt-mark hold linux-image-5.3.0-62--generic      # 禁止內核更新
sudo apt-mark hold linux-headers-5.3.0-62-generic
  • 設置-區域與語言管理:管理已安裝語言,然后更新

  • 安裝chrome瀏覽器,官網下載,默認下載到 /下載 文件夾 sudo dpkg -i 安裝包

  • 安裝Typora:官網

  • 屏幕的調整:參考

Xrandr --output DP-1 --primary --auto
Xrandr --output HDMI-1 --right-of  DP-1 --auto

深度學習環境配置

  • nvidia顯卡驅動安裝:安裝的是440,參考
sudo apt-get purge nvidia*
sudo vim /etc/modprobe.d/blacklist-nouveau.conf
	blacklist nouveau
	options nouveau modeset=0
sudo update-initramfs -u

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
ubuntu-drivers devices
sudo apt-get install nvidia-driver-440
sudo reboot
  • 安裝依賴庫 sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
  • 降低gcc版本
g++ --version
sudo apt-get install gcc-4.8
sudo apt-get install g++-4.8

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
sudo sh cuda_10.0.130_410.48_linux.run
tar -zxvf cudnn-10.0-linux-x64-v7.4.1.5.tgz

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
 sudo chmod a+r /usr/local/cuda/lib64/libcudnn*

sudo bash Anaconda3-2020.02-Linux-x86_64.sh

cd ~
mkdir .pip
sudo vim .pip/pip.conf

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = mirrors.aliyun.com
  • 安裝tensorflow和keras pip install tensorflow-gpu==1.14.0
pip install tensorflow-gpu==1.14.0
pip install keras
  • 測試gpu是否可用:可用 參考
import tensorflow as tf
tf.test.gpu_device_name()

from tensorflow.python.client import device_lib 
device_lib.list_local_devices()

import tensorflow as tf   # 需要設置gpu的顯存使用率,不然會報錯
from keras.backend.tensorflow_backend import set_session
config = tf.ConfigProto()
config.gpu_options.allocator_type = 'BFC' #A "Best-fit with coalescing" algorithm, simplified from a version of dlmalloc.
config.gpu_options.per_process_gpu_memory_fraction = 0.3
config.gpu_options.allow_growth = True
set_session(tf.Session(config=config)) 

pip install torch===1.2.0 torchvision===0.4.0 -f https://download.pytorch.org/whl/torch_stable.html

import torch
torch.__version__
torch.cuda.is_available()
torch.cuda.device_count()
torch.cuda.get_device_name(0)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM