tensorflow 中对 tf.estimator 分配 多GPU 方法

1 通用分配GPU:

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '1,2'

2 有些使用上述方法不可取,需要从代码中指定分配GPU:

  session_config = tf.ConfigProto(device_count={'GPU': 0,'GPU':1,'GPU':2})

  #session_config.gpu_options.per_process_gpu_memory_fraction = 0.9
  #session_config.gpu_options.allow_growth = True
  #session_config.gpu_options.allocator_type = 'BFC'

  run_config = tf.estimator.RunConfig().replace(session_config=session_config)

  estimator = tf.estimator.Estimator(
      model_fn=model_fn, model_dir=FLAGS.model_dir, config=run_config, params=params)
上述代码的注释细节表示每块GPU利用的具体配置。如果需要在tf.estimator 使用多GPU ,需要注释掉这些配置,也就是上述代码注释部分需要注释掉。

猜你喜欢

转载自blog.csdn.net/weixin_32820767/article/details/80872656