由于实验室工位上的电脑是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