TensorFlow张量的元素类型

2018-10-10 16:55 更新
tf.DType

DType 类

定义在:tensorflow/python/framework/dtypes.py.

参见指南:构建图>张量类型

表示 TensorFlow 张量中元素的类型.
定义了以下 DType 对象:

  • tf.float16:16位半精度浮点数.
  • tf.float32:32位单精度浮点数.
  • tf.float64:64位双精度浮点数.
  • tf.bfloat16:16位截断浮点数.
  • tf.complex64:64位单精度复合.
  • tf.complex128:128位双精度复合.
  • tf.int8:8位有符号整数.
  • tf.uint8:8位无符号整数.
  • tf.uint16:16位无符号整数.
  • tf.int16:16位有符号整数.
  • tf.int32:32位有符号整数.
  • tf.int64:64位有符号整数.
  • tf.bool:布尔值.
  • tf.string:字符串.
  • tf.qint8:量化8位有符号整数.
  • tf.quint8:量化的8位无符号整数.
  • tf.qint16:量化16位有符号整数.
  • tf.quint16:量化16位无符号整数.
  • tf.qint32:量化32位有符号整数.
  • tf.resource:处理可变资源.

此外, 还为引用类型的张量定义了具有 _ref 后缀的这些类型的变体.

该 tf.as_dtype() 函数将 numpy 类型和字符串类型名称转换为DType对象.

属性

  • as_datatype_enum
    返回基于 Dtype 的 types_pb2.DataType 枚举值.
  • as_numpy_dtype
    返回一个基于 Dtype 的 numpy.dtype.
  • base_dtype
    返回基于此 DType 的非参考 DType.
  • is_bool
    返回是否为布尔数据类型
  • is_complex
    返回这是否是一个复杂的浮点类型.
  • is_floating
    返回是否为(非量化,实际)浮点型.
  • is_integer
    返回是否为(非量化)整数类型.
  • is_numpy_compatible
  • is_quantized
    返回是否是量化的数据类型.
  • is_unsigned
    返回此类型是否无符号.
    非数字,无序和量化类型不被视为无符号,并且此函数返回 False.

返回:

DType 是否是无符号的.

limits

返回强度限制,即 dtype 的 (最小、最大) 元组.

ARGS:

clip_negative:bool 值(可选).如果为 True,则剪且负值范围(即,返回0的最小强度),即使图像 dtype 允许为负值.返回 min,max:tuple 下限和上限强度限制.

max

返回此数据类型中的最大表示值.

注意:

  • TypeError:如果这是一个非数值,无序或量化的类型.
min

返回此数据类型中的最小表示值.

注意:

  • TypeError:如果这是一个非数字,无序或量化的类型.
name

返回此 DType 的字符串名称.

real_dtype

返回 dtype 对应于这个 dtype 的实际部分.

size

方法

__init__

__init__ ( type_enum )

创建一个新的 DataType.

注意:在正常情况下,您不需要直接构建一个 DataType 对象,而是使用 tf.as_dtype() 函数.

ARGS:

  • type_enum:一个 types_pb2.DataType 枚举值.

注意:

  • TypeError:如果 type_enum 不是值 types_pb2.DataType.

__eq__

__eq__ (other)

如果这个 DType 引用的类型与 other 相同,则返回 True.

__int__

__int__ ()

__ne__

__ne__ (other)

如果 self != other,则返回 True.

is_compatible_with

is_compatible_with (other)

如果其他 DType 将转换为此 DType, 则返回 True.

转换规则如下:

DType(T)       .is_compatible_with(DType(T))        == True
DType(T)       .is_compatible_with(DType(T).as_ref) == True
DType(T).as_ref.is_compatible_with(DType(T))        == False
DType(T).as_ref.is_compatible_with(DType(T).as_ref) == True

ARGS:

  • other:一个 DType(或一个可以转换为 DType 的对象).

返回:

如果其他 DType 的张量将隐式转换为此 DType,则为 True.

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号