tf.TensorShape
目录
class tf.TensorShape
Properties
dims
ndims
Methods
__init__
__bool__
__eq__
__getitem__
__iter__
__len__
__ne__
__nonzero__
as_list
as_proto
assert_has_rank
assert_is_compatible_with
assert_is_fully_defined
assert_same_rank
concatenate
is_compatible_with
is_fully_defined
merge_with
num_elements
with_rank
with_rank_at_least
with_rank_at_most
class tf.TensorShape
Defined in tensorflow/python/framework/tensor_shape.py.
See the guide: Building Graphs > Defining new operations
Represents the shape of a Tensor
.
A TensorShape
represents a possibly-partial shape specification for a Tensor
. It may be one of the following:
- Fully-known shape: has a known number of dimensions and a known size for each dimension. e.g.
TensorShape([16, 256])
- Partially-known shape: has a known number of dimensions, and an unknown size for one or more dimension. e.g.
TensorShape([None, 256])
- Unknown shape: has an unknown number of dimensions, and an unknown size in all dimensions. e.g.
TensorShape(None)
If a tensor is produced by an operation of type "Foo"
, its shape may be inferred if there is a registered shape function for "Foo"
. See Shape functions in C++ for details of shape functions and how to register them. Alternatively, the shape may be set explicitly using tf.Tensor.set_shape.
Properties
dims
Returns a list of Dimensions, or None if the shape is unspecified.
ndims
Returns the rank of this shape, or None if it is unspecified.
Methods
__init__
__init__(dims)
Creates a new TensorShape with the given dimensions.
Args:
dims
: A list of Dimensions, or None if the shape is unspecified. DEPRECATED: A single integer is treated as a singleton list.
Raises:
TypeError
: If dims cannot be converted to a list of dimensions.
__bool__
__bool__()
Returns True if this shape contains non-zero information.
__eq__
__eq__(other)
Returns True if self
is equivalent to other
.
__getitem__
__getitem__(key)
Returns the value of a dimension or a shape, depending on the key.
Args:
key
: Ifkey
is an integer, returns the dimension at that index; otherwise ifkey
is a slice, returns a TensorShape whose dimensions are those selected by the slice fromself
.
Returns:
- A dimension if
key
is an integer, or aTensorShape
ifkey
is a slice.
Raises:
ValueError
: Ifkey
is a slice, and any of its elements are negative, or ifself
is completely unknown and the step is set.
__iter__
__iter__()
Returns self.dims
if the rank is known, otherwise raises ValueError.
__len__
__len__()
Returns the rank of this shape, or raises ValueError if unspecified.
__ne__
__ne__(other)
Returns True if self
is known to be different from other
.
__nonzero__
__nonzero__()
Returns True if this shape contains non-zero information.
as_list
as_list()
Returns a list of integers or None
for each dimension.
Returns:
- A list of integers or
None
for each dimension.
Raises:
ValueError
: Ifself
is an unknown shape with an unknown rank.
as_proto
as_proto()
Returns this shape as a TensorShapeProto
.
assert_has_rank
assert_has_rank(rank)
Raises an exception if self
is not compatible with the given rank
.
Args:
rank
: An integer.
Raises:
ValueError
: Ifself
does not represent a shape with the givenrank
.
assert_is_compatible_with
assert_is_compatible_with(other)
Raises exception if self
and other
do not represent the same shape.
This method can be used to assert that there exists a shape that both self
and other
represent.
Args:
other
: Another TensorShape.
Raises:
ValueError
: Ifself
andother
do not represent the same shape.
assert_is_fully_defined
assert_is_fully_defined()
Raises an exception if self
is not fully defined in every dimension.
Raises:
ValueError
: Ifself
does not have a known value for every dimension.
assert_same_rank
assert_same_rank(other)
Raises an exception if self
and other
do not have compatible ranks.concatenate(other)
Args:
other
: AnotherTensorShape
.
Raises:
ValueError
: Ifself
andother
do not represent shapes with the same rank.
concatenate
concatenate(other)
Returns the concatenation of the dimension in self
and other
.
N.B. If either self
or other
is completely unknown, concatenation will discard information about the other shape. In future, we might support concatenation that preserves this information for use with slicing.
Args:
other
: AnotherTensorShape
.
Returns:
- A
TensorShape
whose dimensions are the concatenation of the dimensions inself
andother
.
is_compatible_with
is_compatible_with(other)
Returns True iff self
is compatible with other
.
Two possibly-partially-defined shapes are compatible if there exists a fully-defined shape that both shapes can represent. Thus, compatibility allows the shape inference code to reason about partially-defined shapes. For example:
TensorShape(None) is compatible with all shapes.
TensorShape([None, None]) is compatible with all two-dimensional shapes, such as TensorShape([32, 784]), and also TensorShape(None). It is not compatible with, for example, TensorShape([None]) or TensorShape([None, None, None]).
TensorShape([32, None]) is compatible with all two-dimensional shapes with size 32 in the 0th dimension, and also TensorShape([None, None]) and TensorShape(None). It is not compatible with, for example, TensorShape([32]), TensorShape([32, None, 1]) or TensorShape([64, None]).
TensorShape([32, 784]) is compatible with itself, and also TensorShape([32, None]), TensorShape([None, 784]), TensorShape([None, None]) and TensorShape(None). It is not compatible with, for example, TensorShape([32, 1, 784]) or TensorShape([None]).
The compatibility relation is reflexive and symmetric, but not transitive. For example, TensorShape([32, 784]) is compatible with TensorShape(None), and TensorShape(None) is compatible with TensorShape([4, 4]), but TensorShape([32, 784]) is not compatible with TensorShape([4, 4]).
Args:
other
: Another TensorShape.
Returns:
- True iff
self
is compatible withother
.
is_fully_defined
is_fully_defined()
Returns True iff self
is fully defined in every dimension.
merge_with
merge_with(other)
Returns a TensorShape
combining the information in self
and other
.
The dimensions in self
and other
are merged elementwise, according to the rules defined for Dimension.merge_with()
.
Args:
other
: AnotherTensorShape
.
Returns:
- A
TensorShape
containing the combined information ofself
andother
.
Raises:
ValueError
: Ifself
andother
are not compatible.
num_elements
num_elements()
Returns the total number of elements, or none for incomplete shapes.
with_rank
with_rank(rank)
Returns a shape based on self
with the given rank.
This method promotes a completely unknown shape to one with a known rank.
Args:
rank
: An integer.
Returns:
- A shape that is at least as specific as
self
with the given rank.
Raises:
ValueError
: Ifself
does not represent a shape with the givenrank
.
with_rank_at_least
with_rank_at_least(rank)
Returns a shape based on self
with at least the given rank.
Args:
rank
: An integer.
Returns:
- A shape that is at least as specific as
self
with at least the given rank.
Raises:
ValueError
: Ifself
does not represent a shape with at least the givenrank
.
with_rank_at_most
with_rank_at_most(rank)
Returns a shape based on self
with at most the given rank.
Args:
rank
: An integer.
Returns:
A shape that is at least as specific as self
with at most the given rank.
Raises:
ValueError
: Ifself
does not represent a shape with at most the givenrank
.
tf.TensorShape相关推荐
- TensorFlow tf.data 导入数据(tf.data官方教程) * * * * *
原文链接:https://blog.csdn.net/u014061630/article/details/80728694 TensorFlow版本:1.10.0 > Guide > I ...
- 使用tf.keras搭建mnist手写数字识别网络
使用tf.keras搭建mnist手写数字识别网络 目录 使用tf.keras搭建mnist手写数字识别网络 1.使用tf.keras.Sequential搭建序列模型 1.1 tf.keras.Se ...
- TensorFlow数据读取机制:文件队列 tf.train.slice_input_producer和 tf.data.Dataset机制
TensorFlow数据读取机制:文件队列 tf.train.slice_input_producer和tf.data.Dataset机制 之前写了一篇博客,关于<Tensorflow生成自己的 ...
- TensorFlow高阶 API: keras教程-使用tf.keras搭建mnist手写数字识别网络
TensorFlow高阶 API:keras教程-使用tf.keras搭建mnist手写数字识别网络 目录 TensorFlow高阶 API:keras教程-使用tf.keras搭建mnist手写数字 ...
- tf.Variable
参考 tf.Variable - 云+社区 - 腾讯云 目录 __init__ __abs__ __add__ __getitem__ __gt__ __invert__ __iter__ __le_ ...
- 【TensorFlow实战笔记】对于TED(en-zh)数据集进行Seq2Seq模型实战,以及对应的Attention机制(tf保存模型读取模型)
个人公众号 AI蜗牛车 作者是南京985AI硕士,CSDN博客专家,研究方向主要是时空序列预测和时间序列数据挖掘,获国家奖学金,校十佳大学生,省优秀毕业生,阿里天池时空序列比赛rank3.公众号致力于 ...
- tensorflow2笔记:简单数据预处理(TF专属)
目录(注意本文jupyterlab编写) 预先导入数据 数据API 数据样式 乱序数据 shuffle乱序(小数据集) 大数据集乱序 训练测试和绘制图像 小结 TFRecord格式 TFRecord的 ...
- 深入浅出TensorFlow2函数——tf.keras.layers.Dense
分类目录:<深入浅出TensorFlow2函数>总目录 tf.keras.layers.Dense实现操作:output = activation(dot(input, kernel) + ...
- Tensorflow 自动文摘: 基于Seq2Seq+Attention模型的Textsum模型
Github下载完整代码 https://github.com/rockingdingo/deepnlp/tree/master/deepnlp/textsum 简介 这篇文章中我们将基于Tensor ...
- 空间深度学习——ConvLSTM原理及其TensorFlow实现
今天介绍一种很有名的网络结构--ConvLSTM,其不仅具有LSTM的时序建模能力,而且还能像CNN一样刻画局部特征,可以说是时空特性具备. LSTM已经在语音识别.视频分析.序列建模等领域取得了非常 ...
最新文章
- 几十万的词如何用每页500词分页展示_如何写出一份优秀的应届生简历?
- 优雅的创建一个JavaScript库
- 重写toString()方法(Java篇)
- LeetCode MySQL 1241. 每个帖子的评论数
- Ranklib源码剖析--LambdaMart
- python shell运行当前程序、可以按下_Python下调用Linux的Shell命令的方法
- string 中的offset_【Java基础】String常量的长度有限制吗?
- phpcmsV9单网页调用其他栏目文章 -方法总结
- JavaScript Try Catch:异常处理说明
- 同城o2o商城系统开发和运营四大要素
- yii2 asset.php,Yii2中使用asset压缩js,css文件的方法_php实例
- 穿透防火墙调用EJB--rmi-http在JBOSS中的应用
- Dialog里加入下拉框Java_android 自定义dialog弹出框,带单选多选下拉
- 四个月备考计算机考研,这些考研走心建议帮你度过剩下的四个月
- php爬虫框架下载文件,php爬虫框架怎么安装
- bin文件转化为csv文件
- c语言求阶乘和的流程图_C语言:数据结构-栈与递归
- ps中怎样测量标尺线之间的距离及怎样切换距离单位
- 依照以下条件写出合适的XML Schema.
- android修改虚拟内存(方法)
热门文章
- DAVE笔记--Micrium uc-Probo DashBoard调试
- AR图书,看着很美其实有点坑
- 解除宝塔面板强制绑定手机号教程
- 网件 无线打印机服务器,NETGEAR Genie让普通打印机实现Air print功能
- sklearn常用函数整理
- 图解:卷帘快门(Rolling shutter)与全局快门(global shutter)的区别
- Hyper-V虚拟机设置固定IP
- 华三交换机配置access命令_H3C 交换机常用配置命令
- Iptables实现 DMZ 区域的服务器简单的发布策略
- linux终端下打开pdf文件,如何从终端打开PDF文件?