tf.depth_to_space详解

[深度学习] SpaceToDepth 类 也就是说,(64,1,120,160)的labels 经过 space2depth 函数,转换成了 (64,64,15,20)的labels。将 labels 输入给 space2depth对象,input:(64,1,120,160)在 output 的第2维度上,按没 block_size=8,切块。对 t_1中的每一块(64,120,8,1),总共20块。交换维度,output:(64,120,160,1)reshape成(64,15,64) 阅读详情
tf.depth_to_space ( 
    input , 
    block_size , 
    name = None
 )

将数据从深度重新排列为空间数据块.这是 SpaceToDepth 的逆向转换.更具体地说,此 op 输出输入张量的一个副本,其中来自深度维度的值在空间块中移动到高度和宽度维度.attr block_size 表示输入块的大小以及数据的移动方式.

从深度大小为 block_size * block_size 的数据块重新排列成不重叠的大小为 block_size x block_size 的数据块.
输出张量的宽度为 input_depth * block_size,而高度是 input_height * block_size.

输入张量的深度必须可以被 block_size * block_size 整除.

即,假设输入的形状是:[batch, height, width, depth],输出的形状为:[batch, heightblock_size, widthblock_size, depth/(block_size*block_size)];

从‘depth_to_space’到图像分块:手把手拆解Einops中rearrange的两种高级用法 本文深入解析Einops库中`rearrange`函数的两种高级用法:像素重排(Depth-to-Space)和图像分块(Image to Patches)。通过对比传统实现与`rearrange`的简洁语法,展示其在计算机视觉任务中的高效应用,帮助开发者提升张量操作的可读性和性能。 阅读详情

相关推荐

从超分到像素洗牌:实战解析tf.nn.depth_to_space在图像生成任务中的三种用法

本文深入解析了TensorFlow中的`tf.nn.depth_to_space`操作在图像生成任务中的三种高效用法,包括超分辨率重建、Vision Transformer上采样模块和风格迁移特征重组。通过对比传统上采样方法,展示了其在减少计算成本、消除棋盘伪影和保持高频细节方面的优势,为开发者提供了实用的代码示例和调参技巧。

weixin_28715081的博客 344

图解TensorFlow op:tf.nn.depth_to_space

田海立@优快云 2020-10-20 TensorFlow算子depth_to_space的官方说明文档写得很简单,从中获取不到真正的执行方式,对于复杂的情况也就无从得知运算结果。本文用图文的方式来解释该算子运算的方式。 零、前提 阅读本文,你需要知道下列基本知识,可以从笔者之前的博文中了解: 《数据的NCHW/NHWC排布方式》 用到数据的NHWC摆放顺序 《Tensor Reshape操作》 用到Reshape操作,以及Reshape操作不改变数据的摆放原则。 ...

田海立@优快云 9267

从原理到实践:深度解析tf.nn.depth_to_space的数据重组逻辑

本文深度解析了TensorFlow中`tf.nn.depth_to_space`的数据重组逻辑,从核心原理到实际应用场景。通过像素洗牌(Pixel Shuffle)的生动比喻和代码示例,详细讲解了该操作在图像超分辨率等计算机视觉任务中的关键作用,包括NHWC/NCHW格式差异、数学表达及常见陷阱解决方案。

weixin_30621711的博客 391

【CNN记录】tensorflow中depth_to_space

tensorflow 、depth_to_space

夏天Alex 1496

从YOLO到超分:实战解析tf.nn.space_to_depth在CV模型中的关键作用与调参技巧

本文深入解析了`tf.nn.space_to_depth`在计算机视觉模型中的关键作用与调参技巧,涵盖从YOLO到超分辨率网络的实际应用。通过对比实验和代码示例,展示了该算子在保持局部结构、提升模型性能方面的独特优势,特别是在目标检测和超分任务中的高效表现。

weixin_42528974的博客 369

AI使用指南:6个超实用的Prompt提示词模板

最近越来越多人开始接触AI,但其实想要让AI更懂你,关键是掌握对的提示词模板!今天就给大家分享6种超实用的Prompt提示词模板,不管你是小白还是老手都能用

程序员世杰 8166

图解TensorFlow op:tf.nn.space_to_depth

田海立@优快云 2020-10-20 TensorFlow算子space_to_depth是depth_to_space的逆操作。本文用图文的方式来解释该算子运算的方式。 一、space_to_depth原型 space_to_depth是把space数据(width和height维)移到depth(Channel)维上,与depth_to_space刚好是反向的操作。对应到ML该操作是把width和height维上各取block_size都分给depth上。所以,对应有一个参数block_s.

田海立@优快云 7203

RS232/RS485/CAN_BUS 通信原理总结与通信波形分析

分析一:232串口信号要点:RS232,全双工,采用三线制传输分别为TXD\RXD\GND,其中TXD为发送信号,RXD为接收信号。在RS232中任何一条信号线的电压均为负逻辑关系。即:-15v ~ -3v 代表1 +3v ~ +15v 代表0测试结果与分析:如图所示,以传输一个8位二进制数值“01101010”为例,异步传输数据的一般格式为:起始位+校验位+数据位+停止位。其中,校验位为可选项。...

乔木鱼 1万+

TensorFlow中 tf.space_to_depth()函数的用法

目录 一、函数定义 二、解释范例 三、代码验证 一、函数定义 通俗易懂些,就是把输入为[batch, height, width, channels]形式的Tensor,其在height和width维的值将移至depth维 space_to_depth( input, block_size, data_format="NHWC", name=No...

黄笳倞的博客 1万+

oh-my-zsh详细安装与主题插件配置

使用Linux的小伙伴都知道默认shell是bash,但是对于喜欢折腾,喜欢酷炫的我们bash怎能够用。zsh的作为一种shell,功能更强大,但是配置复杂。后来,有大佬创建了一个名为oh-my-zsh的开源项目,使用方便,功能强大。 下面就去oh-my-zsh的配置。 ①安装zsh 想要安装oh-my-zsh,首先得安装zsh,输入命令 sudo apt-get install zsh 界面如下 ②查看是否安装成功 输入命令 zsh --version 可以查看安装zsh的版本..

惜洛-Jankin的博客 2万+

MATLAB对pcap文件抓包的读取

应用范围 常用的雷达信号,无线网通信信号的格式大多为pcap、wj文件,这里记录一下MATLAB读取pcap文件的方法,具体处理过程及读取协议针对不同的雷达有不同的处理方式,在这里不做说明。 程序 clc;clear;close all; %% 文件位置 filename= 'E:\File\JOB\JOB_1\data.pcap'; fid = fopen(filename,'r'); % 打开包 tmpPack = fread(fid,1350); % 只读前1350个数 读到

诗酒趁年华的博客 3578

tf.nn.depth_to_space 是如何计算的

depth_to_space 可以将一个张量的数据进行调整(rearrange). 具体如何变化,如下说明: 该函数主要用于4D tensor,因此,数据的格式默认为 ‘NHWC’ , 函数将Channel轴数据变换到Hight 和 Width轴。 举例: x = tf.constant([[[[1, 2, 3, 4, 5, 6, 7, 8], [9, 10,11, 12,13,14,15,...

cjinxi的博客 1384

ZYNQ PS裸机开发RS485

RS485 是一种通用的通信标准,广泛用于数据采集和控制应用中。它的主要优点之一是它允许将多个 RS485 设备放在同一条总线上,这使得多个节点可以相互连接。RS-485是美国电子工业协会(EIA)在1983年批准了一个新的平衡传输标准(balanced transmission standard),EIA一开始将RS(Recommended Standard)做为标准的前缀,不过后来为了便于识别标准的来源,已将RS改为EIA/TIA。

baidu_34971492的博客 829

tf.space_to_depth与tf.reshape比较

demo代码: import tensorflow as tf import numpy as np x_pad = np.reshape(np.arange(0,4*4*8),[1,4,4,8]) x = tf.placeholder(tf.int32,[1,4,4,8]) y = tf.space_to_depth(x,block_size=2) z = tf.reshape(x,[1,2,2...

ShenWeiKKX的博客 1307

【动态导通电阻】p-GaN HEMTs正向和反向导通下的动态导通电阻

2024年,浙江大学的研究团队通过多组双脉冲测试方法,深入研究了两种商用p-GaN栅极HEMTs在正向和反向导通模式下的动态导通电阻(RON)特性。研究发现,肖特基型p-GaN栅极HEMTs在反向导通时动态RON比正向导通高3%-5%,而混合漏极嵌入栅注入晶体管在反向导通时动态RON降级较轻,降低约10%。此外,随着漏极电流(IDS)的增加,两种器件在反向导通时动态RON先减小后增加,形成“谷底”现象。

荷塘阅色 825

六种光耦综合对比——《器件手册--光耦》

可控硅输出光耦(SCR Optocoupler)是一种特殊的光电耦合器,由红外发光二极管(LED)和双向可控硅(SCR)组成,用于实现输入和输出之间的电气隔离和信号传输。逻辑输出光耦是一种高效、可靠的数字信号隔离和电平转换器件,通过电气隔离和逻辑电平输出,确保了系统的安全性和信号的稳定性。固态继电器(可控硅输出,SSR)是一种无触点电子开关设备,利用可控硅(SCR或Triac)作为主要开关元件,通过光耦合器实现输入和输出之间的电气隔离。光耦作为一种成熟的电气隔离器件,在电子电路设计中具有重要的地位。

XU157303764的博客 1722

python numpy实现PixelShuffle及其逆变换(depth_to_space,space_to_depth)

文章目录PixelShuffle简介作用与来源特点PixelShuffle的原理numpy的reshape和transpose简介 PixelShuffle简介 作用与来源 PixelShuffle(PyTorch中的方法)的作用主要是增大特征图的空间分辨率,将Tensor的shape从(N,C∗r2,H,W)(N, C*r^2, H, W)(N,C∗r2,H,W)变为(N,C,H∗r,W∗r)(N, C, H*r, W*r)(N,C,H∗r,W∗r),其中rrr必需是整数,所以它只能实现上采样,而不能做到

吹吹自然风 7829

RT-Thread littefs控制GD32F4xx片内Flash

GD32F4xx RT-Thread下使用littefs 控制片内flash 调试记录

madao1234的博客 995

transpose,pad,space_to_depth(函数总结)

最近在看yolo系列的代码,主要整理一下经常会用到的函数。 ① tran_x = tf.transpose(x, [0, 3, 1, 2]) # channle first mode 当时为了理解这个函数花费了好多时间。看源码也很难明白,其实主要要理解perm参数代表着什么。 perm表示的是数组的阶数,也就是Rank,如果是四位数组,那么每层就分别为(0,1,2,3),以此类推。如果perm为空,其实就是默认为完全转置,就是变成了(3,2,1,0),也就是数组的相应位置的x,y,z,w要进行交换。例如

qq_43521665的博客 1017

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

tf depth_to_space 与torch pixshuffle 踩坑

0 前言 根据文档中对于api介绍, tf.depth_to_space与torch中pixshuffle功能应该是一致的, 都是把深度维的数据给move到宽度和高度上。然而实际测试发现了不一致的情况。 1 现象 当输出通道不为1的时候, 两者的结果不一致, 当输出通道为1的时候, 两者的结果一致。 试验代码如下: import tensorflow.compat.v1 as tf import torch from torch.nn import functional as F import numpy

1930

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

从YOLO到U-Net:盘点tf.nn.space_to_depth在CV模型里的那些‘神操作’

本文深入探讨了`space_to_depth`操作在计算机视觉模型中的核心价值与应用实践。从YOLO系列的目标检测到U-Net的图像分割,再到超分辨率重建中的PixelShuffle技术,这一操作通过巧妙的空间与通道信息转换,显著提升了模型性能。文章详细解析了其原理、典型应用场景及现代架构中的创新变体,为CV开发者提供了实用的技术参考。

weixin_30411239的博客 378

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

tf.depth_to_space和torch.nn.pixel_shuffle

   最近做项目用到了这两个函数,本人经过仔细对比,认为它们的功能应该是完全一样的,都是将一个较多通道的特征变成较少通道的特征,具体定义如下: def depth_to_space(input, block_size, name=None):    block_size用来说明数据移动的方式。该函数的操作是将block_size x block_size数目的特征图转换成一个不重叠的特征,...

CHNguoshiwushuang的博客 1万+

实战指南:用tf.nn.space_to_depth优化你的YOLO模型输入预处理(附代码)

本文详细介绍了如何使用TensorFlow的`tf.nn.space_to_depth`操作优化YOLO模型的输入预处理流程。通过对比传统方法与优化方案,展示了在计算复杂度、内存占用和实现复杂度上的显著优势,并提供了实测数据和代码示例,帮助开发者提升目标检测模型的性能。

weixin_30535843的博客 428

【Python报错】No module named ‘multi_gpu_utils‘、no attribute ‘space_to_depth‘、 ‘tensorflow_backend‘

【Python报错】调用keras.utils里No module named 'multi_gpu_utils'

weixin_42403633的博客 2470

tf.space_to_depth() 最易理解版

tf.depth_to_space ( input , block_size , name = None ) input [batch, height, width, channels]形式的Tensor output t[batch, height/block_size, width/block_size, channelsblock_sizeblock_siz...

qq_42910179的博客 1494

tf.depth_to_space

https://blog.csdn.net/CHNguoshiwushuang/article/details/80878460

u013049912的博客 2092
上一篇: Tensorflow lite debug过程
下一篇: 浅析HTTP的GET 和 POST
SYSU-Leo
博客等级 码龄9年 26粉丝 41原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值