tensorflow 笔记14:tf.expand_dims和tf.squeeze函数
tf.expand_dims和tf.squeeze函数
一、tf.expand_dims()
Function
tf.expand_dims(input, axis=None, name=None, dim=None)
Inserts a dimension of 1 into a tensor’s shape.
在第axis位置增加一个维度
Given a tensor input, this operation inserts a dimension of 1 at the dimension index axis of input’s shape. The dimension index axis starts at zero; if you specify a negative number for axis it is counted backward from the end.
给定张量输入,此操作在输入形状的维度索引轴处插入1的尺寸。 尺寸索引轴从零开始; 如果您指定轴的负数,则从最后向后计数。
This operation is useful if you want to add a batch dimension to a single element. For example, if you have a single image of shape [height, width, channels], you can make it a batch of 1 image with expand_dims(image, 0), which will make the shape [1, height, width, channels].
如果要将批量维度添加到单个元素,则此操作非常有用。 例如,如果您有一个单一的形状[height,width,channels],您可以使用expand_dims(image,0)使其成为1个图像,这将使形状[1,高度,宽度,通道]。
Args:
input: A Tensor.
axis: 0-D (scalar). Specifies the dimension index at which to expand the shape of input.
name: The name of the output Tensor.
dim: 0-D (scalar). Equivalent to axis, to be deprecated.
输入:张量。
轴:0-D(标量)。 指定扩大输入形状的维度索引。
名称:输出名称Tensor。
dim:0-D(标量)。 等同于轴,不推荐使用。
Returns:
A Tensor with the same data as input, but its shape has an additional dimension of size 1 added.
For example:
# 't' is a tensor of shape [2] shape(expand_dims(t, 0)) ==> [1, 2] shape(expand_dims(t, 1)) ==> [2, 1] shape(expand_dims(t, -1)) ==> [2, 1] # 't2' is a tensor of shape [2, 3, 5] shape(expand_dims(t2, 0)) ==> [1, 2, 3, 5] shape(expand_dims(t2, 2)) ==> [2, 3, 1, 5] shape(expand_dims(t2, 3)) ==> [2, 3, 5, 1]
二、tf.squeeze()
Function
tf.squeeze(input, squeeze_dims=None, name=None)
Removes dimensions of size 1 from the shape of a tensor.
从tensor中删除所有大小是1的维度
Given a tensor input, this operation returns a tensor of the same type with all dimensions of size 1 removed. If you don’t want to remove all size 1 dimensions, you can remove specific size 1 dimensions by specifying squeeze_dims.
给定张量输入,此操作返回相同类型的张量,并删除所有尺寸为1的尺寸。 如果不想删除所有尺寸1尺寸,可以通过指定squeeze_dims来删除特定尺寸1尺寸。
如果不想删除所有大小是1的维度,可以通过squeeze_dims指定。
Args:
input: A Tensor. The input to squeeze.
squeeze_dims: An optional list of ints. Defaults to []. If specified, only squeezes the dimensions listed. The dimension index starts at 0. It is an error to squeeze a dimension that is not 1.
name: A name for the operation (optional).
输入:张量。 输入要挤压。
squeeze_dims:可选的ints列表。 默认为[]。 如果指定,只能挤压列出的尺寸。 维度索引从0开始。挤压不是1的维度是一个错误。
名称:操作的名称(可选)。
Returns:
A Tensor. Has the same type as input. Contains the same data as input, but has one or more dimensions of size 1 removed.
张量。 与输入的类型相同。 包含与输入相同的数据,但具有一个或多个删除尺寸1的维度。
For example:
# 't' is a tensor of shape [1, 2, 1, 3, 1, 1] shape(squeeze(t)) ==> [2, 3] Or, to remove specific size 1 dimensions: # 't' is a tensor of shape [1, 2, 1, 3, 1, 1] shape(squeeze(t, [2, 4])) ==> [1, 2, 3, 1]
tensorflow 笔记14:tf.expand_dims和tf.squeeze函数的更多相关文章
- tf.expand_dims和tf.squeeze函数
from http://blog.csdn.net/qq_31780525/article/details/72280284 tf.expand_dims() Function tf.expand_d ...
- tensorflow 基本函数(1.tf.split, 2.tf.concat,3.tf.squeeze, 4.tf.less_equal, 5.tf.where, 6.tf.gather, 7.tf.cast, 8.tf.expand_dims, 9.tf.argmax, 10.tf.reshape, 11.tf.stack, 12tf.less, 13.tf.boolean_mask
1. tf.split(3, group, input) # 拆分函数 3 表示的是在第三个维度上, group表示拆分的次数, input 表示输入的值 import tensorflow ...
- tensorflow笔记:使用tf来实现word2vec
(一) tensorflow笔记:流程,概念和简单代码注释 (二) tensorflow笔记:多层CNN代码分析 (三) tensorflow笔记:多层LSTM代码分析 (四) tensorflow笔 ...
- tensorflow笔记4:函数:tf.assign()、tf.assign_add()、tf.identity()、tf.control_dependencies()
函数原型: tf.assign(ref, value, validate_shape=None, use_locking=None, name=None) Defined in tensorflo ...
- tensorflow 笔记11:tf.nn.dropout() 的使用
tf.nn.dropout:函数官网说明: tf.nn.dropout( x, keep_prob, noise_shape=None, seed=None, name=None ) Defined ...
- tensorflow笔记6:tf.nn.dynamic_rnn 和 bidirectional_dynamic_rnn:的输出,output和state,以及如何作为decoder 的输入
一.tf.nn.dynamic_rnn :函数使用和输出 官网:https://www.tensorflow.org/api_docs/python/tf/nn/dynamic_rnn 使用说明: A ...
- tensorflow 笔记 16:tf.pad
函数: tf.compat.v1.pad tf.pad 函数表达式如下: tf.pad( tensor, paddings, mode='CONSTANT', name=Non ...
- tensorflow踩坑合集2. TF Serving & gRPC 踩坑
这一章我们借着之前的NER的模型聊聊tensorflow serving,以及gRPC调用要注意的点.以下代码为了方便理解做了简化,完整代码详见Github-ChineseNER ,里面提供了训练好的 ...
- 机器学习笔记5-Tensorflow高级API之tf.estimator
前言 本文接着上一篇继续来聊Tensorflow的接口,上一篇中用较低层的接口实现了线性模型,本篇中将用更高级的API--tf.estimator来改写线性模型. 还记得之前的文章<机器学习笔记 ...
随机推荐
- Linux学习笔记10
创建文件 touch touch filenames 创建文件夹 mkdir mkdir dir3 dir4 dir5 建立多个文件夹 mkdir ~/games 在登录用户的本目录之下建立game ...
- ubantu 执行sudo apt-get update 出现校验不符问题
一直被这个问题困扰,今天安装mongodb时,看了别人博客暂时解决了,不知道会不会出什么问题. 直接打开软件更新器: 然后点击其他软件,去掉两个独立的多选项: 再执行一遍 sudo apt-get u ...
- 利用nginx,腾讯云免费证书制作https
之前一直在研究,https怎么弄.最近看到了腾讯云提供的免费得ssl证书,寻思把网站弄成https. 首先先去腾讯云购买一个免费得证书. 点击后填写内容, 然后下载证书 解压证书就可以看到,提供四种方 ...
- webpack 入门踩坑
参考来源:知乎张轩 安装 先装好node和npm,因为webpack是一个基于node的项目.然后 npm install -g webpack 全局安装 还可以在当前项目里面也安装一个webpack ...
- bzoj1051: [HAOI2006]受欢迎的牛(tarjan板子)
1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 6064 Solved: 3179[Submit][Sta ...
- oracle函数返回结果集
一.用自定义类型实现 1.创建表对象类型. 在Oracle中想要返回表对象,必须自定义一个表类型,如下所示: create or replace type type_table is table of ...
- django的templatetags
创建tag方式,首先在需要使用tag的app下创建一个templatetags的python包, 然后在包里创建一个tag模块,例如hellotag.py from django import tem ...
- C#隐藏手机号中间四位为*
使用正则:Regex.Replace(手机号, "(\\d{3})\\d{4}(\\d{4})", "$1****$2"); 效果:
- 《Unity3D 实战核心技术详解》书中关于矩阵的错误
最近一直在学习实时渲染,不免要接触线性代数.而渲染中,一定会用到矩阵,当我再次去复习我之前看的书时,发现<Unity3D 实战核心技术详解>关于矩阵就有几处错误 ,特标注出来. 书的第一章 ...
- Unity插件扩展中组件常用的几个方法
最近为美术编写一个Unity编辑器的扩展,主要为了减轻美术在修改预制对象时的机械化操作的繁琐和出错.具体实现的几个功能: 1.删除指定组件: 2.复制.粘贴指定的组件: 3.重新关联新的属性: 4.重 ...