如何获得张量的类型? [英] How to get the type of a Tensor?

查看:23
本文介绍了如何获得张量的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找类似于以下效果的东西:

x.get_shape()

这将给出 x 的类型.有这个功能吗?

解决方案

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

<预><代码>>>>x = tf.Variable(tf.random_normal([256, 100]))>>>x.get_shape()(256, 100)

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

<预><代码>>>>x = tf.Variable(tf.random_normal([256, 100]))>>>数据类型<dtype: 'float32_ref'>

您可以使用 dtype 的 as_numpy_dtype 属性从 tf.dtype 到 numpy 数据类型.

<预><代码>>>>x = tf.Variable(tf.random_normal([256, 100]))>>>x.dtype.as_numpy_dtype<class 'numpy.float32'>

I'm looking for something similar to the effects of:

x.get_shape()

that will give the type of x. Is there is any function for this?

解决方案

You can use get_shape() to get the shape of a tensorflow variable.

>>> x = tf.Variable(tf.random_normal([256, 100]))
>>> x.get_shape()
(256, 100)

You can use dtype property to get the type of a tensorflow variable.

>>> x = tf.Variable(tf.random_normal([256, 100]))
>>> x.dtype
<dtype: 'float32_ref'>

You can use as_numpy_dtype property of dtype to convert from tf.dtype to numpy dtype.

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

这篇关于如何获得张量的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆