由於實驗室工位上的電腦是Mac 只能從新熟悉一波了html
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
gpustat
os.environ['CUDA_VISIBLE_DEVICES'] = '0' os.environ['CUDA_VISIBLE_DEVICES'] = '0,1'
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
config = tf.ConfigProto() config.gpu_options.allow_growth = True session = tf.Session(config=config)
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本身去分配了python
參考資料:
tensorflow設置gpu及gpu顯存使用
TensorFlow 使用 GPU
tensorflow GPU小測試linux