关于使用实验室服务器的GPU以及跑上TensorFlow代码

链接服务器

Windows - XShell XFtp SSH

  1. 经过SSH来链接实验室的服务器
  • 使用SSH链接已经不陌生了 github和OS课设都常常使用
  • 目前使用 192.168.7.169
  1. 使用工具 XShell 和 XFtp
  • 使用XShell链接服务器以及操做,服务器每一个节点上都安装了Ubuntu 16.04 LTS操做系统
  • 使用XFtp管理文件
  1. 参考资料:
    Xshell+Xftp SSH隧道代理
    Xshell经过SSH密钥、SSH代理链接Linux服务器详解

Mac OS - Terminal Cyberduck

由于实验室工位上的电脑是Mac 只能从新熟悉一波了html

  1. 使用Terminal来创建SSH远程链接
  2. 使用Cyberduck来创建SFtp链接管理文件(考虑filezilla中)
  3. 参考资料:
    Mac下如何用SSH链接远程Linux服务器(包括Cyberduck下载)
    Mac下使用自带终端SSH功能

创建环境 - virtualenv

  1. 创建虚拟环境并安装包(也能够考虑anaconda)
    创建环境:virtualenv xxx_py virtualenv -p python3 xxx_py
    进入环境:source xxx_py/bin/activate
    退出:deactivate
  2. 使用清华镜像
  • 临时使用
    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
  1. 参考资料:
    清华pypi 镜像使用帮助
    virtualenv介绍及基本使用
    Python开发必备神器之一:virtualenv
    virtualenv-廖雪峰的官方网站

让TensorFlow代码跑在GPU上

  1. 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)  
  1. TensorFlow代码
    目前没有考虑在代码各个部分手动分配时GPU仍是CPU
    因此用 with tf.device(self.device): 把全部网络结构包了起来
    而后用 config = tf.ConfigProto(gpu_options=gpu_options,allow_soft_placement=True) 让TensorFlow本身去分配了python

  2. 参考资料:
    tensorflow设置gpu及gpu显存使用
    TensorFlow 使用 GPU
    tensorflow GPU小测试linux

相关文章
相关标签/搜索