• tf.dtypes


    目录

    一、概述

    1、类

    2、函数

    3、别的成员

    二、函数和类详解

    1、tf.dtypes.as_dtype

    2、tf.dtypes.cast

    3、tf.dtypes.complex

    4、tf.dtypes.DType

    1、__init__

    2、__eq__

    3、__ne__

    4、is_compatible_with

    5、tf.dtypes.saturate_cast


    一、概述

    tf.dtypes的公共API名称空间。

    1、类

    2、函数

    3、别的成员

    • QUANTIZED_DTYPES
    • bfloat16
    • bool
    • complex128
    • complex64
    • double
    • float16
    • float32
    • float64
    • half
    • int16
    • int32
    • int64
    • int8
    • qint16
    • qint32
    • qint8
    • quint16
    • quint8
    • resource
    • string
    • uint16
    • uint32
    • uint64
    • uint8
    • variant

    二、函数和类详解

    1、tf.dtypes.as_dtype

    将给定的类型值转换为DType。

    tf.dtypes.as_dtype(type_value)
    

    参数:

    • type_value:可以转换为tf的值。DType对象。这可能是当前的tf。对象、数据类型枚举、字符串类型名称或numpy.dtype。

    返回值:

    与type_value对应的DType。

    可能产生的异常:

    • TypeError: If type_value cannot be converted to a DType.

    2、tf.dtypes.cast

    将张量投射到一个新的类型上。

    1. tf.dtypes.cast(
    2.     x,
    3.     dtype,
    4.     name=None
    5. )

    这个操作对x(对于张量)或x进行了强制转换。值(对于稀疏张量或索引切片)到dtype。

    例:

    1. x = tf.constant([1.8, 2.2], dtype=tf.float32)
    2. tf.dtypes.cast(x, tf.int32)  # [1, 2], dtype=tf.int32

    该操作支持uint8、uint16、uint32、uint64、int8、int16、int32、int64、float16、float32、float64、complex64、complex128、bfloat16的数据类型(适用于x和dtype)。在将复杂类型(complex64、complex128)转换为实类型时,只返回x的实部份。在将实类型转换为复杂类型(complex64、complex128)时,返回值的虚部设置为0。这里对复杂类型的处理与numpy的行为相匹配。

    参数:

    • x:数值型张量或稀疏张量或索引切片。可以是uint8, uint16, uint32, uint64, int8, int16, int32, int64, float16, float32, float64, complex64, complex128, bfloat16。
    • dtype:目标类型。支持的dtypes列表与x相同。
    • name:操作的名称(可选)。

    返回值:

    • 张量或稀疏张量或索引切片,其形状与x相同,类型与d类型相同。

    可能产生的异常:

    • TypeError: If x cannot be cast to the dtype.

    3、tf.dtypes.complex

    将两个实数转换为复数。

    1. tf.dtypes.complex(
    2.     real,
    3.     imag,
    4.     name=None
    5. )

    给定一个张量实数表示复数的实数部分,一个张量imag表示复数的虚数部分,这个操作返回形式的复数元素,其中a表示实数部分,b表示imag部分。输入张量实数和imag必须具有相同的形状。

    参数:

    • real:一个张量。必须是下列类型之一:float32、float64。
    • imag:张量。必须具有与实数相同的类型。
    • name:操作的名称(可选)。

    返回值:

    • 复64或复128型张量。

    可能产生的异常:

    • TypeError: Real and imag must be correct types

    4、tf.dtypes.DType

    表示张量中元素的类型。

    函数的作用是:将numpy类型和字符串类型名称转换为DType对象。

    1、__init__

    __init__(type_enum)
    

    创建一个新的数据类型。注意(mrry):在正常情况下,不应该直接构造数据类型对象。相反,使用tf.as_dtype()函数。

    参数:

    • type_enum: types_pb2。数据类型枚举值。

    可能产生的异常:

    • TypeError: If type_enum is not a value types_pb2.DataType.

    2、__eq__

    __eq__(other)
    

    如果此DType与其他类型引用相同的类型,则返回True。

    3、__ne__

    __ne__(other)
    

    返回True iff self != other。

    4、is_compatible_with

    is_compatible_with(other)
    

    如果将另一个DType转换为此DType,则返回True。转换规则如下:

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

    参数:

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

    返回值:

    • 如果另一个d类型的张量将隐式地转换成这个d类型,则为真。

    5、tf.dtypes.saturate_cast

    将值安全饱和转换为dtype。

    1. tf.dtypes.saturate_cast(
    2.     value,
    3.     dtype,
    4.     name=None
    5. )

    这个函数将输入转换为dtype,而不应用任何缩放。如果有一个危险值将超过或低于铸造,该op应用适当的夹紧之前的铸造。

    参数:

    • value:一个张量。
    • dtype:所需的输出dtype。
    • name:操作的名称(可选)。

    返回值:

    • 值安全转换为dtype。
  • 相关阅读:
    深度学习入门(二十六)卷积神经网络——池化层
    opencv形状目标检测
    五、数据库连接池解析与编写 —— TinyWebServer
    批量采集的时间管理与优化
    固态硬盘SSD
    python必会的10个知识点
    科研小白成长记36——work to live
    改进YOLOv7系列:首发最新结合Non-local Networks and Attention结构(附YOLOv5改进),目标检测高效涨点
    《论文阅读》CARE:通过条件图生成的共情回复因果关系推理 EMNLP 2022
    离散低通滤波方法
  • 原文地址:https://blog.csdn.net/weixin_36670529/article/details/100568033