TensorFlow2.0:数据的填充与复制
**
一 tf.pad( )填充函数
**
tf.pad(tensor, paddings, mode="CONSTANT", name=None, constant_values=0):
paddings参数的设置方法:
假设输入tensor有两个维度,则paddings参数设置为paddings = [[a,b],[c,d]]
a,b表示为axis=0维度上最前面填充a行,最后面填充b行,
c,d表示为axis=1维度上最前面填充c列,最后面填充d列,
同理,假设输入的tensor有三个维度,则paddings参数设置为paddings = [[a,b],[c,d],[e,f]]
a,b表示为axis=0维度上最前面填充a行,最后面填充b行,
c,d表示为axis=1维度上最前面填充c列,最后面填充d列,
e,f表示为axis=2维度上最前面填充e,最后面填充f,
In [3]: a
Out[3]: <tf.Tensor: id=3, shape=(9,), dtype=int32, numpy=array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=int32)>In [4]: a = tf.reshape(a,[3,3]) In [5]: a
Out[5]:
<tf.Tensor: id=6, shape=(3, 3), dtype=int32, numpy=
array([[0, 1, 2],[3, 4, 5],[6, 7, 8]], dtype=int32)>In [6]: tf.pad(a,[[0,0],[0,0]])#不填充
Out[6]:
<tf.Tensor: id=9, shape=(3, 3), dtype=int32, numpy=
array([[0, 1, 2],[3, 4, 5],[6, 7, 8]], dtype=int32)>In [7]: tf.pad(a,[[1,0],[0,0]])#在axis=0上最前面填充1行,得到的维度应为[4,3]
Out[7]:
<tf.Tensor: id=12, shape=(4, 3), dtype=int32, numpy=
array([[0, 0, 0],[0, 1, 2],[3, 4, 5],[6, 7, 8]], dtype=int32)>In [8]: tf.pad(a,[[0,1],[0,0]])#在axis=0的最后面填充1行
Out[8]:
<tf.Tensor: id=15, shape=(4, 3), dtype=int32, numpy=
array([[0, 1, 2],[3, 4, 5],[6, 7, 8],[0, 0, 0]], dtype=int32)>In [9]: tf.pad(a,[[0,0],[1,0]])#在axis=1的最前面填充1列
Out[9]:
<tf.Tensor: id=18, shape=(3, 4), dtype=int32, numpy=
array([[0, 0, 1, 2],[0, 3, 4, 5],[0, 6, 7, 8]], dtype=int32)>In [10]: tf.pad(a,[[0,0],[0,1]])#在axis=1的最后面填充1列
Out[10]:
<tf.Tensor: id=21, shape=(3, 4), dtype=int32, numpy=
array([[0, 1, 2, 0],[3, 4, 5, 0],[6, 7, 8, 0]], dtype=int32)>In [11]: tf.pad(a,[[1,1],[0,0]])#在axis=0最前面和最后面分别填充
Out[11]:
<tf.Tensor: id=24, shape=(5, 3), dtype=int32, numpy=
array([[0, 0, 0],[0, 1, 2],[3, 4, 5],[6, 7, 8],[0, 0, 0]], dtype=int32)>In [12]: tf.pad(a,[[0,0],[1,1]])#在axis=1最前和最后各填充
Out[12]:
<tf.Tensor: id=27, shape=(3, 5), dtype=int32, numpy=
array([[0, 0, 1, 2, 0],[0, 3, 4, 5, 0],[0, 6, 7, 8, 0]], dtype=int32)>In [13]: tf.pad(a,[[1,1],[1,1]])#在axis=0和axis=1的最前和最后各进行填充
Out[13]:
<tf.Tensor: id=30, shape=(5, 5), dtype=int32, numpy=
array([[0, 0, 0, 0, 0],[0, 0, 1, 2, 0],[0, 3, 4, 5, 0],[0, 6, 7, 8, 0],[0, 0, 0, 0, 0]], dtype=int32)>
iamge padding
tf.pad(tensor, paddings, mode="CONSTANT", name=None, constant_values=0): In [19]: tf.pad(a,[[0,0],[2,2],[2,2],[2,2],[0,0]],constant_values=255).shape
Out[19]: TensorShape([4, 32, 32, 32, 3])
**
二 tf.tile( ) 数据复制函数
**
tf.tile( input, #输入 multiples, #某一维度上复制的次数 name=None )
multiples参数设置方法:
假设输入Input有两个维度,则可以设置multiples = [a,b]
a表示在维度axis=0上复制a次,
b表示在维度axis=1上复制b次.
同理,假设Input有三个维度,则可以设置multiples = [a,b,c]
a表示在维度axis=0上复制a次,
b表示在维度axis=1上复制b次.
c表示在维度axis=2上复制c次,
In [2]: a = tf.range(9) In [3]: a
Out[3]: <tf.Tensor: id=3, shape=(9,), dtype=int32, numpy=array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=int32)>In [4]: a = tf.reshape(a,[3,3]) In [5]: a
Out[5]:
<tf.Tensor: id=6, shape=(3, 3), dtype=int32, numpy=
array([[0, 1, 2],[3, 4, 5],[6, 7, 8]], dtype=int32)>In [6]: tf.tile(a,[1,1])#表示不复制
Out[6]:
<tf.Tensor: id=9, shape=(3, 3), dtype=int32, numpy=
array([[0, 1, 2],[3, 4, 5],[6, 7, 8]], dtype=int32)>In [7]: tf.tile(a,[1,2])#在axis=1维度上复制2次
Out[7]:
<tf.Tensor: id=12, shape=(3, 6), dtype=int32, numpy=
array([[0, 1, 2, 0, 1, 2],[3, 4, 5, 3, 4, 5],[6, 7, 8, 6, 7, 8]], dtype=int32)>In [8]: tf.tile(a,[2,2])#在axis=0和axis=1维度上分别复制2,次,先复制小维度,再复制大维度
Out[8]:
<tf.Tensor: id=15, shape=(6, 6), dtype=int32, numpy=
array([[0, 1, 2, 0, 1, 2],[3, 4, 5, 3, 4, 5],[6, 7, 8, 6, 7, 8],[0, 1, 2, 0, 1, 2],[3, 4, 5, 3, 4, 5],[6, 7, 8, 6, 7, 8]], dtype=int32)>In [9]: tf.tile(a,[2,1])#在axis=0维度上复制2次
Out[9]:
<tf.Tensor: id=18, shape=(6, 3), dtype=int32, numpy=
array([[0, 1, 2],[3, 4, 5],[6, 7, 8],[0, 1, 2],[3, 4, 5],[6, 7, 8]], dtype=int32)>
tile VS broadcast_to
broadcast_to相当于先expand_dims,再tile
In [12]: a = tf.reshape(tf.range(9),[3,3]) In [13]: a
Out[13]:
<tf.Tensor: id=28, shape=(3, 3), dtype=int32, numpy=
array([[0, 1, 2],[3, 4, 5],[6, 7, 8]], dtype=int32)>In [14]: aa = tf.expand_dims(a,axis=0)#先扩充维度 In [15]: aa
Out[15]:
<tf.Tensor: id=31, shape=(1, 3, 3), dtype=int32, numpy=
array([[[0, 1, 2],[3, 4, 5],[6, 7, 8]]], dtype=int32)>In [16]: bb = tf.tile(aa,[2,1,1]) In [17]: bb
Out[17]:
<tf.Tensor: id=34, shape=(2, 3, 3), dtype=int32, numpy=
array([[[0, 1, 2],[3, 4, 5],[6, 7, 8]],[[0, 1, 2],[3, 4, 5],[6, 7, 8]]], dtype=int32)>In [18]: cc = tf.broadcast_to(a,[2,3,3]) In [19]: cc
Out[19]:
<tf.Tensor: id=37, shape=(2, 3, 3), dtype=int32, numpy=
array([[[0, 1, 2],[3, 4, 5],[6, 7, 8]],[[0, 1, 2],[3, 4, 5],[6, 7, 8]]], dtype=int32)>
TensorFlow2.0:数据的填充与复制相关推荐
- Tensorflow2.0数据和部署(二)——基于设备的模型与TensorFlow Lite
文章目录 一.概述 1.模型存储 2.量化方法 3.模型验证 二.基于安卓的TF模型 1.初始化解释器 2.准备输入 3.调用解释器 4.输出结果 三.基于IOS的TF模型 1.初始化 2.准备输入 ...
- Tensorflow2.0数据和部署(一)——基于浏览器的模型与TensorFlow.js
文章目录 一.总体介绍 编程实践 1.创建一个简单的网页 2.编写脚本文件加载TensorFlow.js 3.完整代码 4.从csv文件中读取数据 5.设计更复杂的神经网络 二.图像分类 1.编写一个 ...
- Tensorflow2.0数据和部署(四)——Tensorflow高级模型部署
文章目录 一.TF Serving 1.安装 2.搭建服务 (1)构建模型 (2)保存模型 (3)运行TF Model Server 3.使用服务 (1)将数据传递给服务器 (2)从服务器获取结果 二 ...
- Tensorflow2.0数据和部署(三)——基于Tensorflow数据服务的数据管道
文章目录 一.概述 1.概述 2.TFDS功能介绍 (1)ETL原理 (2)Datasetinfo (3)load参数说明 二.split和slice 1.Split API (1)Legacy AP ...
- TensorFlow2.0:数据统计
** 一 tf.norm( )函数–求范数 ** In [30]: a = tf.ones([2,2]) In [31]: tf.norm(a)#求a的二范数 Out[31]: <tf.Tens ...
- 【TensorFlow2.0】(7) 张量排序、填充、复制、限幅、坐标选择
各位同学好,今天和大家分享一下TensorFlow2.0中的一些操作.内容有: (1)排序 tf.sort().tf.argsort().top_k():(2)填充 tf.pad():(3)复制 tf ...
- 【TensorFlow2.0】数据读取与使用方式
大家好,这是专栏<TensorFlow2.0>的第三篇文章,讲述如何使用TensorFlow2.0读取和使用自己的数据集. 如果您正在学习计算机视觉,无论你通过书籍还是视频学习,大部分的教 ...
- 【CTR模型】TensorFlow2.0 的 xDeepFM 实现与实战(附代码+数据)
CTR 系列文章: 广告点击率(CTR)预测经典模型 GBDT + LR 理解与实践(附数据 + 代码) CTR经典模型串讲:FM / FFM / 双线性 FFM 相关推导与理解 CTR深度学习模型之 ...
- 【CTR模型】TensorFlow2.0 的 DeepFM 实现与实战(附代码+数据)
CTR 系列文章: 广告点击率(CTR)预测经典模型 GBDT + LR 理解与实践(附数据 + 代码) CTR经典模型串讲:FM / FFM / 双线性 FFM 相关推导与理解 CTR深度学习模型之 ...
最新文章
- java threetable,Java XWPFDocument.createTable方法代码示例
- C/S和B/S的区别
- php实现享元模式,php设计模式 flyweight (享元模式)
- 第一个WebService案例
- Form的is_valid校验规则及验证顺序
- SpringCloud工作笔记050---关于同一账号多人同时登录的token重复问题
- NetShopForge网上商店程序(VB)源码—讨论-发布
- (完美)华为畅玩7A AUM-AL00的Usb调试模式在哪里打开的步骤
- 多种文件上传绕过手法
- adams如何保存_实用的Adams使用技巧
- 1. 无穷维空间的测度论-Wiener测度(二)
- 华为的PBC个人绩效评价模板
- OSChina 周五乱弹 —— 美团外卖程序崩溃的真相
- 模拟人生Java修改_模拟人生4 常用修改秘籍作弊码一览 修改秘籍怎么用
- RoomDatabase重启断电数据丢失
- POE供电 网线 电源 网络情况图
- 《深入理解计算机系统》学习记录
- NYOJ有趣的问题(单源最短路径dijkstra)
- 软件质量与测试--第二周作业 WordCount
- 投资品讲解及国债逆回购