如何获得Tensor的类型

CGT*_*end 13 python tensorflow

我正在寻找类似于x.get_shape()的效果的东西,它将给出x的类型.如果没有功能我该怎么办呢?

umu*_*tto 24

您可以使用get_shape()来获取tensorflow变量的形状.

>>> x = tf.Variable(tf.random_normal([256, 100]))
>>> x.get_shape()
(256, 100)
Run Code Online (Sandbox Code Playgroud)

您可以使用dtype属性来获取tensorflow变量的类型.

>>> x = tf.Variable(tf.random_normal([256, 100]))
>>> x.dtype
<dtype: 'float32_ref'>
Run Code Online (Sandbox Code Playgroud)

您可以使用dtype的as_numpy_dtype属性将tf.dtype转换为numpy dtype.

>>> x = tf.Variable(tf.random_normal([256, 100]))
>>> x.dtype.as_numpy_dtype
<class 'numpy.float32'>
Run Code Online (Sandbox Code Playgroud)


Mir*_*ber 13

获得你可以做的类型

x.dtype
Run Code Online (Sandbox Code Playgroud)