Tensorflow学习资源
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)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架