当前位置:网站首页>【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]]]
边栏推荐
- [ORB_SLAM2] void Frame::ComputeImageBounds(const cv::Mat & imLeft)
- AI目标分割能力,无需绿幕即可实现快速视频抠图
- Redis Persistence - RDB and AOF
- [ORB_SLAM2] SetPose, UpdatePoseMatrices
- 【LeetCode每日一题】——103.二叉树的锯齿形层序遍历
- ofstream,ifstream,fstream read and write files
- Remember a gorm transaction and debug to solve mysql deadlock
- 菜刀webshell特征分析
- FOFAHUB usage test
- 字典常用方法
猜你喜欢

Ringtone 1161. Maximum In-Layer Elements and

使用DBeaver进行mysql数据备份与恢复

Remember a gorm transaction and debug to solve mysql deadlock

【web】理解 Cookie 和 Session 机制

使用docker安装mysql

Garbage Collector CMS and G1

Golang分布式应用之定时任务

项目后台技术Express

Win Go development kit installation configuration, GoLand configuration

2022 Henan Youth Training League Game (3)
随机推荐
网络层解析——IP协议、地址管理、路由选择
BioVendor Human Club Cellular Protein (CC16) Elisa Kit Research Fields
The state status is displayed incorrectly after the openGauss switch
Golang分布式应用之定时任务
2022年NPDP考完多久出成绩?怎么查询?
oracle query scan full table and walk index
The principle and code implementation of intelligent follower robot in the actual combat of innovative projects
四元数、罗德里格斯公式、欧拉角、旋转矩阵推导和资料
接口测试神器Apifox究竟有多香?
Outsourcing worked for three years, it was abolished...
swift project, sqlcipher3 -> 4, cannot open legacy database is there a way to fix it
qt点云配准软件
Golang分布式应用之Redis
29. 删除链表中重复的节点
Check if IP or port is blocked
Reflex WMS Intermediate Series 7: What should I do if I want to cancel the picking of an HD that has finished picking but has not yet been loaded?
2022河南青训联赛第(三)场
CodeTon Round 2 D. Magical Array 规律
字典常用方法
项目后台技术Express