How to get the type of a Tensor?

后端 未结 2 2057
心在旅途
心在旅途 2021-02-12 12:04

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 thi

相关标签:
2条回答
  • 2021-02-12 12:34

    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'>
    
    0 讨论(0)
  • 2021-02-12 12:40

    To get the type you can do

    x.dtype
    
    0 讨论(0)
提交回复
热议问题