当前位置:网站首页>【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]]]
边栏推荐
- ¶ Backtop back to the top is not effective
- C#测试项目中属性的用法
- openGauss切换后state状态显示不对
- 【LeetCode每日一题】——103.二叉树的锯齿形层序遍历
- NIO‘s Sword(牛客多校赛)
- 微信小程序异步回调函数恶梦和解决办法
- The first time I wrote a programming interview question for Niu Ke: input a string and return the letter with the most occurrences of the string
- 用位运算为你的程序加速
- Project Background Technology Express
- 【 wheeled odometer 】
猜你喜欢
openGauss切换后state状态显示不对
使用DBeaver进行mysql数据备份与恢复
How to adjust the cross cursor too small, CAD dream drawing calculation skills
Golang分布式应用之定时任务
The failure to create a role in Dahua Westward Journey has been solved
Nanoprobes丨1-巯基-(三甘醇)甲醚功能化金纳米颗粒
Talking about the "horizontal, vertical and vertical" development trend of domestic ERP
nacos启动报错,已配置数据库,单机启动
【web】理解 Cookie 和 Session 机制
极大似然估计
随机推荐
2022-07-30 mysql8 executes slow SQL-Q17 analysis
Analysis of the status quo of digital transformation of manufacturing enterprises
【web】理解 Cookie 和 Session 机制
Install mysql using docker
BI - SQL 丨 WHILE
oracle query scan full table and walk index
Centos7 安装postgresql并开启远程访问
swift project, sqlcipher3 -> 4, cannot open legacy database is there a way to fix it
列表常用方法
Golang分布式应用之定时任务
LeetCode Review Diary: 153. Find the Minimum Value in a Rotated Sort Array
2022 NPDP take an examination of how the results?How to query?
BioVendor人俱乐部细胞蛋白(CC16)Elisa试剂盒研究领域
项目场景 with ERRTYPE = cudaError CUDA failure 999 unknown error
messy website
GTK RGB图像绘制
What to study after the PMP exam?The soft exam ahead is waiting for you~
Scheduled tasks for distributed applications in Golang
Oracle数据类型介绍
FOFAHUB使用测试