Skip to content

Instantly share code, notes, and snippets.

@BIGBALLON
Last active July 3, 2018 07:42
Show Gist options
  • Save BIGBALLON/42bfff5352dad4d1f4e2504547db6e9c to your computer and use it in GitHub Desktop.
Save BIGBALLON/42bfff5352dad4d1f4e2504547db6e9c to your computer and use it in GitHub Desktop.
this is my cheat sheet for deep learning & linux
//终端执行程序时设置使用的GPU
CUDA_VISIBLE_DEVICES=1 python my_script.py

//python代码中设置使用的GPU
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "2"
//设置tensorflow使用的显存大小
//定量设置显存

//默认tensorflow是使用GPU尽可能多的显存。可以通过下面的方式,来设置使用的GPU显存:

gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.7)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))        

//按需设置显存

gpu_options = tf.GPUOptions(allow_growth=True)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))   

from keras import backend as K
# set GPU memory 
if('tensorflow' == K.backend()):
    import tensorflow as tf
    from keras.backend.tensorflow_backend import set_session

    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    sess = tf.Session(config=config)
    
ssh -L 6006:127.0.0.1:6006 [email protected] -p port
pip list | grep tensorflow
//or
python -c 'import tensorflow as tf; print(tf.__version__)'
  • 查看CUDA版本
cat /usr/local/cuda/version.txt
\\or
nvcc --version
  • 查看Cudnn版本
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
\\or
cat /usr/include/x86_64-linux-gnu/cudnn_v*.h | grep CUDNN_MAJOR -A 2
  • tf.app.run & tf.app.flags 用法
import tensorflow as tf
FLAGS = tf.app.flags.FLAGS

tf.app.flags.DEFINE_string('log_save_path', './logs', 'Directory where to save tensorboard log')
tf.app.flags.DEFINE_integer('batch_size', 128, 'batch size')
tf.app.flags.DEFINE_float('epochs', 164, 'epochs')

def main(_):
    ...
    ...
    
if __name__ == "__main__": 
    tf.app.run()
    
  • Terminator 快捷键

水平分割: ctrl + alt + o
垂直分割: ctrl + alt + e
调整大小: ctrl + shift +
隐藏/显示滚动条: ctrl + shift + s
搜索: ctrl + shift + f
切换终端(next): ctrl + shift + n or ctrl + tab
切换终端(pre): ctrl + shift + p or ctrl + shift + tab
切换终端): alt +
终端最大化/还原: ctrl + shift + x
增大/减小/还原字号: ctrl + + -0
关闭当前终端: ctrl + shift + w
关闭当前窗口: ctrl + shift + q

  • VIM 粘贴

set: paste, 贴上后再 set: nopaste.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment