当前位置:网站首页>【CNN记录】tensorflow slice和strided_slice
【CNN记录】tensorflow slice和strided_slice
2022-08-02 02:23:00 【侵蚀昨天】
两个函数都是从张量中提取切片
slice
tf.slice(input,begin,size,name=None)
参数说明:
input:输入数据
begin:是一个list,切片索引,对应各个维度,例如[0,1,2],三个维度分别冲0、1、2开始
size:是一个list,对应begin中指定位置开始,取多少元素
举个栗子
import tensorflow as tf
import numpy as np
#一个4x2x3的tensor
input = tf.constant([[[1, 1, 1], [2, 2, 2]],
[[3, 3, 3], [4, 4, 4]],
[[5, 5, 5], [6, 6, 6]],
[[7, 7, 7], [8, 8, 8]],
])
out=tf.slice(input, [2, 0, 0], [2, 1, 2])
print(out)
输出:
tf.Tensor(
[[[5 5]]
[[7 7]]], shape=(2, 1, 2), dtype=int32)
第一个维度从2开始取2个,即变为
[[[5, 5, 5], [6, 6, 6]],
[[7, 7, 7], [8, 8, 8]]]
第二个维度从 0开始取1个,即变为
[[[5, 5, 5]],
[[7, 7, 7]]]
第三个维度从0开始取2个,即变为
[[[5, 5]],
[[7, 7]]]
strided_slice
tf.strided_slice(
input_, begin, end, strides=None, begin_mask=0, end_mask=0, ellipsis_mask=0,
new_axis_mask=0, shrink_axis_mask=0, var=None, name=None)
参数解释:
input_:输入数据
begin:是一个list,切片索引,对应各个维度
end:是一个list,终止切片索引(开区间),对应各个维度终止索引
strides:各个维度进行切片的步长,不设置即为1
举个栗子,和前面一样
import tensorflow as tf
import numpy as np
#一个4x2x3的tensor
input = tf.constant([[[1, 1, 1], [2, 2, 2]],
[[3, 3, 3], [4, 4, 4]],
[[5, 5, 5], [6, 6, 6]],
[[7, 7, 7], [8, 8, 8]],
])
out = tf.strided_slice(input, [1, 0, 0], [4, 1, 2],[2,1,1])
print(out)
输出:
tf.Tensor(
[[[3 3]]
[[7 7]]], shape=(2, 1, 2), dtype=int32)
第一个维度从1开始 区间[1,4),步长为2,切片为
[[[3, 3, 3], [4, 4, 4]],
[[7, 7, 7], [8, 8, 8]]]
第二个维度从0开始 区间[0,1),步长为1,切片为
[[[3, 3, 3]],
[[7, 7, 7]]]
第二个维度从0开始 区间[0,2),步长为1,切片为
[[[3, 3],],
[[7, 7]]]
边栏推荐
- 2022-08-01 Install mysql monitoring tool phhMyAdmin
- AOF rewrite
- nacos启动报错,已配置数据库,单机启动
- 2022年NPDP考完多久出成绩?怎么查询?
- Talking about the "horizontal, vertical and vertical" development trend of domestic ERP
- Handwriting a blogging platform ~ Day 3
- 51. 数字排列
- Chopper webshell feature analysis
- [Server data recovery] Data recovery case of server Raid5 array mdisk disk offline
- ALCCIKERS Shane 20191114
猜你喜欢
FOFAHUB使用测试
Personal blog system project test
Power button 1374. Generate each character string is an odd number
AWR分析报告问题求助:SQL如何可以从哪几个方面优化?
Safety (2)
菜刀webshell特征分析
BioVendor Human Club Cellular Protein (CC16) Elisa Kit Research Fields
Software testing Interface automation testing Pytest framework encapsulates requests library Encapsulates unified request and multiple base path processing Interface association encapsulation Test cas
极大似然估计
NAS和私有云盘的区别?1篇文章说清楚
随机推荐
2022 NPDP take an examination of how the results?How to query?
53. 最小的k个数
记一个gorm初始化的坑
Chopper webshell feature analysis
Oracle19c安装图文教程
Moonbeam and Project integration of the Galaxy, bring brand-new user experience for the community
永磁同步电机36问(三)——SVPWM代码实现
Nanoprobes丨1-巯基-(三甘醇)甲醚功能化金纳米颗粒
【ORB_SLAM2】void Frame::AssignFeaturesToGrid()
【LeetCode每日一题】——704.二分查找
[ORB_SLAM2] SetPose, UpdatePoseMatrices
libcurl访问url保存为文件的简单示例
Nanoprobes纳米探针丨Nanogold偶联物的特点和应用
Rasa 3.x 学习系列- Rasa - Issues 4873 dispatcher.utter_message 学习笔记
1688以图搜货
to-be-read list
BI - SQL 丨 WHILE
极大似然估计
Rasa 3 x learning series - Rasa - 4873 dispatcher Issues. Utter_message study notes
字符串常用方法