https://tensorflow.google.cn/ 中文官网
https://www.w3cschool.cn/tensorflow_python/tensorflow_python-gnwm2c68.html
[1] 安装Tensorflow(Linux ubuntu) http://blog.csdn.net/lenbow/article/details/51203526
[2] ubuntu下CUDA编译的GCC降级安装 http://blog.csdn.net/lenbow/article/details/51596706
[3] ubuntu手动安装最新Nvidia显卡驱动 http://blog.csdn.net/lenbow/article/details/51683783
[4] Tensorflow的CUDA升级,以及相关配置 http://blog.csdn.net/lenbow/article/details/52118116
[5] 基于gensim的Doc2Vec简析 http://blog.csdn.net/lenbow/article/details/52120230
[6] TensorFlow的分布式学习框架简介 http://blog.csdn.net/lenbow/article/details/52130565
[7] Tensorflow一些常用基本概念与函数(1) http://blog.csdn.net/lenbow/article/details/52152766
[8] Tensorflow一些常用基本概念与函数(2) http://blog.csdn.net/lenbow/article/details/52181159
[9] Tensorflow一些常用基本概念与函数(3) http://blog.csdn.net/lenbow/article/details/52213105
Tensorflow一些常用基本概念与函数(4)
[TensorFlow笔记] 获取Tensor的维度(tf.shape(x)、x.shape和x.get_shape()的区别)
import tensorflow as tf input = tf.constant([[0,1,2],[3,4,5]]) print(type(input.shape)) print(type(input.get_shape())) print(type(tf.shape(input)))
Out: <class 'tensorflow.python.framework.tensor_shape.TensorShape'> <class 'tensorflow.python.framework.tensor_shape.TensorShape'> <class 'tensorflow.python.framework.ops.Tensor'>
可以看到s.shape和x.get_shape()都是返回TensorShape类型对象,而tf.shape(x)返回的是Tensor类型对象。
因此要想获得维度信息,则需要调用TensorShape的ts.as_list()方法,返回的是Python的list:
input.shape.as_list() # Out: [2,3] input.get_shape().as_list() # Out: [2,3]
此外,还可以获得维度的个数:
input.shape.ndims # Out: 2 input.get_shape().ndims # Out: 2
tf.rank(input) # Out: type=Tensor, value=2
总结
获得Python原生类型的维度信息:
input.shape.as_list() # [2,3] input.shape.ndims # 2
获得TensorFlow中Tensor类型的维度信息:
tf.shape(input)
tf.rank(input)