python–tensorlow。DeviceSpec

哎哎哎:# t0]https://www . geeksforgeeks . org/python-tensorlow-devicespec/

TensorFlow 是谷歌设计的开源 Python 库,用于开发机器学习模型和深度学习神经网络。

DeviceSpec 代表 TensorFlow 设备的规格。这个规范可能是局部的。如果部分指定了设备规格,它将根据定义的范围与其他设备规格合并。

语法:张量流。设备规格(作业、副本、任务、设备类型、设备索引)

参数:

  • 作业(可选):是指定作业名称的字符串。
  • 副本(可选):指定副本索引的整数。
  • 任务(可选):指定任务索引的整数。
  • 设备类型(可选):可以是 CPU,也可以是 GPU。
  • 设备索引(可选):是指定设备索引的整数。

返回:返回一个 DeviceSpec 对象。

例 1:

Python 3

# Importing the library
import tensorflow as tf

# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg", device_type ="GPU", device_index = 0)

# Printing the result
print('DeviceSpec: ', device_spec)

输出:

DeviceSpec:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fe5c1818ac8>

例 2:

Python 3

# Importing the library
import tensorflow as tf

# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg", device_type ="CPU", device_index = 0)

# Printing the result
print('DeviceSpec: ', device_spec)

输出:

DeviceSpec:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fe5bb29d888>