当前位置:网站首页>【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]]]
边栏推荐
- 项目场景 with ERRTYPE = cudaError CUDA failure 999 unknown error
- 790. 数的三次方根
- LeetCode brush diary: LCP 03. Machine's adventure
- 【LeetCode每日一题】——704.二分查找
- 微信小程序异步回调函数恶梦和解决办法
- 【 wheeled odometer 】
- Pinduoduo leverages the consumer expo to promote the upgrading of domestic agricultural products brands and keep pace with international high-quality agricultural products
- 极大似然估计
- ALCCIKERS Shane 20191114
- AI target segmentation capability for fast video cutout without green screen
猜你喜欢

yaml
![[LeetCode Daily Question] - 103. Zigzag Level Order Traversal of Binary Tree](/img/b9/35813ae2972375fa728e3c11fab5d3.png)
[LeetCode Daily Question] - 103. Zigzag Level Order Traversal of Binary Tree

BioVendor Human Club Cellular Protein (CC16) Elisa Kit Research Fields

网络层解析——IP协议、地址管理、路由选择

Analysis of the status quo of digital transformation of manufacturing enterprises

Garbage Collector CMS and G1

极大似然估计

The underlying data structure of Redis

Chopper webshell feature analysis

nacos启动报错,已配置数据库,单机启动
随机推荐
AWR分析报告问题求助:SQL如何可以从哪几个方面优化?
网络层解析——IP协议、地址管理、路由选择
From 2023 onwards, these regions will be able to obtain a certificate with a score lower than 45 in the soft examination.
A good book for newcomers to the workplace
周鸿祎称微软抄袭,窃取360安全模式
Nanoprobes丨1-巯基-(三甘醇)甲醚功能化金纳米颗粒
一次SQL优化,数据库查询速度提升 60 倍
EFCore 反向工程
2022-08-01 Install mysql monitoring tool phhMyAdmin
永磁同步电机36问(二)——机械量与电物理量如何转化?
yaml
20. 用两个栈实现队列
【LeetCode每日一题】——654.最大二叉树
BI - SQL 丨 WHILE
[LeetCode Daily Question]——654. The largest binary tree
TKU remembers a single-point QPS optimization (I wish ITEYE is finally back)
Check if IP or port is blocked
AntPathMatcher uses
2022 NPDP take an examination of how the results?How to query?
Ringtone 1161. Maximum In-Layer Elements and