tf.config

参考   tf.config - 云+社区 - 腾讯云

目录

一、模块和函数

二、experimental模块

1、tf.config.experimental.set_visible_devices

2、tf.config.experimental.list_physical_devices

3、tf.config.experimental.set_memory_growth

4、tf.config.experimental.list_logical_devices


Public API for tf.config namespace.

一、模块和函数

Modules:

  • experimental module: Public API for tf.config.experimental namespace.
  • optimizer module: Public API for tf.config.optimizer namespace.
  • threading module: Public API for tf.config.threading namespace.

Functions:

二、experimental模块

Classes:

Functions:

1、tf.config.experimental.set_visible_devices

Set the list of visible devices.

tf.config.experimental.set_visible_devices(
    devices,
    device_type=None
)

Used in the guide:

Sets the list of PhysicalDevices to be marked as visible to the runtime. Any devices that are not marked as visible means TensorFlow will not allocate memory on it and will not be able to place any operations on it as no LogicalDevice will be created on it. By default all discovered devices are marked as visible.

The following example demonstrates disabling the first GPU on the machine.

physical_devices = config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
# Disable first GPU
tf.config.experimental.set_visible_devices(physical_devices[1:], 'GPU')
logical_devices = config.experimental.list_logical_devices('GPU')
# Logical device was not created for first GPU
assert len(logical_devices) == len(physical_devices) - 1

Args:

  • devices: (optional) List of PhysicalDevice objects to make visible
  • device_type: (optional) Device types to limit visibility configuration to. Other device types will be left unaltered.

Compat aliases

2、tf.config.experimental.list_physical_devices

Return a list of physical devices visible to the runtime.

tf.config.experimental.list_physical_devices(device_type=None)

Used in the guide:

Used in the tutorials:

Physical devices are hardware devices locally present on the current machine. By default all discovered CPU and GPU devices are considered visible. The list_physical_devices allows querying the hardware prior to runtime initialization.

The following example ensures the machine can see at least 1 GPU.

physical_devices = tf.config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "No GPUs found."

Args:

  • device_type: (optional) Device type to filter by such as "CPU" or "GPU"

Returns:

  • List of PhysicalDevice objects

Compat aliases

3、tf.config.experimental.set_memory_growth

Set if memory growth should be enabled for a PhysicalDevice.

tf.config.experimental.set_memory_growth(
    device,
    enable
)

Used in the guide:

A PhysicalDevice with memory growth set will not allocate all memory on the device upfront. Memory growth cannot be configured on a PhysicalDevice with virtual devices configured.

For example:

physical_devices = tf.config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
tf.config.experimental.set_memory_growth(physical_devices[0], True)

Args:

  • device: PhysicalDevice to configure
  • enable: Whether to enable or disable memory growth

Compat aliases

4、tf.config.experimental.list_logical_devices

Return a list of logical devices created by runtime.

tf.config.experimental.list_logical_devices(device_type=None)

Used in the guide:

Logical devices may correspond to physical devices or remote devices in the cluster. Operations and tensors may be placed on these devices by using the name of the LogicalDevice.

For example:

logical_devices = tf.config.experimental.list_logical_devices('GPU')
# Allocate on GPU:0
with tf.device(logical_devices[0].name):
  one = tf.constant(1)
# Allocate on GPU:1
with tf.device(logical_devices[1].name):
  two = tf.constant(2)

Args:

  • device_type: (optional) Device type to filter by such as "CPU" or "GPU"

Returns:

List of LogicalDevice objects

Compat aliases

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wanderer001

ROIAlign原理

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值