連接服務器
Windows - XShell XFtp SSH
- 通過SSH來連接實驗室的服務器
- 使用SSH連接已經不陌生了 github和OS課設都經常使用
- 目前使用 192.168.7.169
- 使用工具 XShell 和 XFtp
- 使用XShell連接服務器以及操作,服務器每個節點上都安裝了Ubuntu 16.04 LTS操作系統
- 使用XFtp管理文件
Mac OS - Terminal Cyberduck
因為實驗室工位上的電腦是Mac 只能重新熟悉一波了
- 使用Terminal來建立SSH遠程連接
- 使用Cyberduck來建立SFtp連接管理文件(考慮filezilla中)
- 參考資料:
Mac下如何用SSH連接遠程Linux服務器(包括Cyberduck下載)
Mac下使用自帶終端SSH功能
建立環境 - virtualenv
- 建立虛擬環境並安裝包(也可以考慮anaconda)
建立環境:virtualenv xxx_py
virtualenv -p python3 xxx_py
進入環境:source xxx_py/bin/activate
退出:deactivate
- 使用清華鏡像
- 臨時使用
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
- 設為默認
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
讓TensorFlow代碼跑在GPU上
- GPU占用問題
TensorFlow可能會占用視線可見的所有GPU資源
- 查看gpu占用情況:
gpustat
- 在python代碼中加入:
os.environ['CUDA_VISIBLE_DEVICES'] = '0' os.environ['CUDA_VISIBLE_DEVICES'] = '0,1'
- 設置使用固定的gpu:
運行代碼時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
CUDA_VISIBLE_DEVICES=0 python3 main.py
- TensorFlow自己提供的兩種控制GPU資源的方法:
- 在運行過程中動態申請顯存,需要多少就申請多少
config = tf.ConfigProto() config.gpu_options.allow_growth = True session = tf.Session(config=config)
- 限制GPU的使用率
gpu_options=tf.GPUOptions(per_process_gpu_memory_fraction=0.4) config=tf.ConfigProto(gpu_options=gpu_options) session = tf.Session(config=config)
-
TensorFlow代碼
目前沒有考慮在代碼各個部分手動分配時GPU還是CPU
所以用with tf.device(self.device):
把所有網絡結構包了起來
然后用config = tf.ConfigProto(gpu_options=gpu_options,allow_soft_placement=True)
讓TensorFlow自己去分配了 -
參考資料:
tensorflow設置gpu及gpu顯存使用
TensorFlow 使用 GPU
tensorflow GPU小測試