先記一下命令
#啓動gpu容器 帶jupyter以及 ssh
(docker run -tdi --gpus all -p 60106:22 -p 60006:8888 --name cujupt102 --privileged=true registry.cn-hangzhou.aliyuncs.com/mkmk/gpujupyter:sshtf20b1 /bin/bash) &&(docker exec -d cujupt102 /bin/bash -c "cd /home &&(/etc/init.d/ssh start) && nohup jupyter notebook --allow-root & " )
#刪除容器
docker stop cujupt102 && docker rm cujupt102
#刪除鏡像
docker rmi $(docker images -q)
docker run -tdi --gpus all --name gpu102 --privileged=true nvidia/cuda:10.2-base /bin/bash
成功,
如果不使用官方的鏡像,cuda會顯示N/A
失敗截圖
#進入容器
docker exec -it gpu102 "bash"
#查看驅動
nvidia-smi
#查看系統版本
cat /etc/issue
Ubuntu 18.04.3 LTS \n \l
安裝python3
安裝ptyhon3.7
sudo apt-get update
sudo apt-get install python3.7
安裝成後的目錄在/usr/bin/python3.7,同時將其設置成默認
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 150
sudo update-alternatives --config python
安裝setuptools
unzip setuptools-42.0.2.zip
docker cp setuptools-42.0.2 gpu102:/home/installpackges/setuptools-42.0.2
cd s
安裝pip
apt-get install python3-pip
在這裏插入代碼片
apt-get install python3-pip
建立 從 a 到 b 的軟連接
ln -s a b
ln -s /usr/bin/pip3 /usr/bin/pip
ln -s /usr/bin/python3.6 /usr/bin/python
配置jupyter
pip install jupyter
root@1589c892929a:/home# jupyter notebook --generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
>>> from notebook.auth import passwd
>>> passwd()
Enter password:
Verify password:
'sha1:e7760ad802a5:0d634bc07644459cacf405f962c504c9df1c87dc'
編輯jupyter配置文件
docker cp gpu102:/root/.jupyter/jupyter_notebook_config.py jupyter_notebook_config.py
#編輯
vi /root/.jupyter/jupyter_notebook_config.py
c.NotebookApp.ip='*' #設置訪問notebook的ip,*表示所有IP
c.NotebookApp.password = u'sha1:xxx' #填寫剛剛複製的密鑰
c.NotebookApp.open_browser = False # 禁止notebook啓動時自動打開瀏覽器
c.NotebookApp.port =8888 #指定訪問的端口,默認是8888。
jupyter notebook --config /root/.jupyter/jupyter_notebook_config.py --allow-root
#啓動gpu容器 帶jupyter以及 ssh
(docker run -tdi --gpus all -p 60106:22 -p 60006:8888 --name cujupt102 --privileged=true registry.cn-hangzhou.aliyuncs.com/mkmk/gpujupyter:ssh0tf20opencv4keras /bin/bash) &&(docker exec -d cujupt102 /bin/bash -c "cd /home &&(/etc/init.d/ssh start) && nohup jupyter notebook --allow-root & " )
#刪除容器
docker stop cujupt102 && docker rm cujupt102
pip 加速
vi ~/.pip/pip.conf
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
chapter3-autoencoders
下有cpu執行和gpu執行文件的對比
然後數據集加載
keras中
loaddata() 函數默認可以添加一個path
loaddata( datapath ) 這樣keras就不會再去 網上下數據資源
#每秒監視一次gpu信息
watch -n 1 nvidia-smi
#在哪裏查看都可以,都可以檢測到GPU是否運行
最後對於每一個 echo cpu運行 60s
gpu運行16s
with tf.device("/cpu:0"):
執行代碼
with tf.device("/gpu:0"):
執行代碼
指定特定顯卡工作
也可以創建多線程 ,cpu GPU 分別工作