繁体   English   中英

tensorflow gpu 使用没有 compat.v1

[英]tensorflow gpu usage without compat.v1

有人可以帮我吗?

在不使用 compat.v1 的情况下,在 tensorflow 2.2.0 中使用 gpu 的代码语法是什么?

gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.3)# i used this with compat.v1

您必须配置一个逻辑 GPU 设备。

import tensorflow as tf

gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
  # Restrict TensorFlow to only allocate 1GB of memory on the first GPU
  try:
    tf.config.experimental.set_virtual_device_configuration(
        gpus[0],
        [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=1024)])
    logical_gpus = tf.config.experimental.list_logical_devices('GPU')
    print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
  except RuntimeError as e:
    # Virtual devices must be set before GPUs have been initialized
    print(e)

我建议您阅读本指南:https://www.tensorflow.org/guide/gpu#limiting_gpu_memory_growth

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM