Im2col()函数和col2im()函数

【darknet源码解析-09】col2im.h 和 col2im.c 解析 本系列为darknet源码解析, 本次解析src/col2im.h 与 src/col2im_cpu.c 两个. 这两个其实与之前所解析src/im2col.h 和 src/im2col.c的逆过程, col2im就是将im2col重排的图片data_col恢复到正常的图像矩阵排列。 col2img.h 中包含的代码如下:主要就是一个函数col2im.h定义,在这里我们也不涉及到gpu那块,先讲... 阅读详情

                                                Im2col()函数和col2im()函数

clear all;clc;

im=imread('lena.bmp');%512*512

[height,weight]=size(im);

im1=im2col(im,[16,16],'distinct');%256*1024正好能整除的情况

figure(1),imshow(im);

im2=col2im(im1,[16,16],[height,weight],'distinct');

figure(2),imshow(im2);

imm=imread('barbara103128.gif');

[height1,weight1]=size(imm); %103*128

im3=im2col(imm,[16,16],'distinct'); %256*56(56=7*8;7=ceil(103/16))

figure(3),imshow(imm);

im4=col2im(im3,[16,16],[height1,weight1],'distinct');

figure(4),imshow(im4);

“distinct”按列进行划分,如果不是整数块,则在填充0。图像分块和复原都没有问题,不管是不是能整除,最后都能恢复成功。“”sliding“”不填充0,小块block在原矩阵上按列滑动,使用col2im函数,不能恢复原矩阵,需要自己编写程序实现,因为有重叠,所以相对要复杂一些,查了源代码,现在还是不能成功写出来恢复程序。

  查看MATLAB源代码

  function a = col2im(b,block,mat,kind)

  mpad = rem(mat(1),block(1)); %求余数,为的是计算需要填充几行0向量

            if mpad>0, mpad = block(1)-mpad; end

 npad = rem(mat(2),block(2)); %求余数,为的是计算需要填充几列0向量

             if npad>0, npad = block(2)-npad; end

  mpad = mat(1)+mpad; npad = mat(2)+npad;

        if mpad*npad/prod(block)~=n,

           error('Images:col2im:inconsistentSize','The column size of b not consistent with BLK2COL size.');

        end

 

  mblocks = mpad/block(1);

  nblocks = npad/block(2);

  aa = mkconstarray(class(b), 0, [mpad npad]);

  x = mkconstarray(class(b), 0, block);

  rows = 1:block(1); cols = 1:block(2);

  for i=0:mblocks-1,

      for j=0:nblocks-1,

                x(:) = b(:,i+j*mblocks+1);

                aa(i*block(1)+rows,j*block(2)+cols) = x;

       end

  end

  a = aa(1:mat(1),1:mat(2));

 

elseif kind(1)=='s', % sliding

  a = reshape(b,mat(1)-block(1)+1,mat(2)-block(2)+1);

else

  error('Images:col2im:unknownBlockType',[deblank(kind),' is a unknown block type']);

 

end

-

从零开始手工实现卷积神经网络CNN以及img2col和col2img的实现方法 本文主要实现卷积神经网络(Convolutional Neural Network, CNN)中卷积操作的forward和backward函数。CNN主要包括卷积(Convolution),池化(pooling),全连接(Fully Connected)操作。相信点进来的同学对这些操作的细节已经很熟悉了,不熟悉的同学可以参考这一篇博文(本人看过讲CNN最简单易懂、最好的博文,没有之一):An In... 阅读详情

相关推荐

QT+QTimer+QThread实现线程内的定时任务并且和主线程进行交互

在制作qt软件时,我们经常会用到qtimer定时器以及将其在非主线程中进行使用,甚至有的时候还需要和主线程进行交互。我总结了两种用法,仅供参考。以上即为QTimer和QThread联合使用的学习记录。

u011826081的博客 5685

caffe源码解析:卷积乘法中用到的im2col及col2im

这两个函数其实完成的功能比较简单,im2col就是把矩阵按卷积乘法所需,变换成列向量,col2im是一个逆过程 从下面这张图你一眼就能看明白im2col的操作(caffe中卷积计算都是Matrix_Kernel * Matrix_Col),因为都列出来太长了,我只列出了前4个,注意这是四周围完全没有填充0的情况,   col2im是一个反过来的过程,那么你可能会好奇,这两个操作能完全可逆...

tanmx219的博客 5544

PC微信(3.9.2.23)逆向实战:定位并Hook消息接收函数

本文详细介绍了PC微信(3.9.2.23)逆向分析中定位并Hook消息接收函数的完整实战流程。通过Cheat Engine动态定位未读消息数内存地址,结合OllyDbg分析代码上下文,最终找到稳定的Hook点,并分享了实战中的关键注意事项与踩坑经验。

lll78的博客 473

卷积神经网络——Convolution层的详细介绍(包含前传后传、im2col和col2im方法)

参考:鱼书《深度学习入门》——斋藤康毅介绍高维数组:https://zhuanlan.zhihu.com/p/650178588,博主从索引的角度出发,有利于理解和应用。

m0_60461719的博客 794

Dell Precision 7920 Tower开机点不亮?别慌,看电源灯闪烁密码快速定位故障(附BIOS恢复指南)

本文详细解析了Dell Precision 7920 Tower工作站开机点不亮时的电源灯闪烁密码,帮助用户快速定位故障。从内存问题到BIOS恢复,再到CPU配置错误,提供了全面的诊断和修复指南,并附有实用的维护建议和工具推荐。

weixin_30892037的博客 484

手把手教你用分立元件搭建自举电路:解决高端MOS驱动难题

本文详细介绍了如何用分立元件搭建自举电路,解决高端MOS驱动中的栅源极电压不足问题。通过面包板实验,逐步讲解二极管、电容等关键元件的选型与电路搭建,提供波形调试和常见问题排查方法,帮助工程师提升开关电源和电机驱动等应用的效率与可靠性。

weixin_30555125的博客 153

深度学习入门:Day-12

内容: - 池化层 - 池化层和卷积层的实现 池化层 (1).池化是缩小高、长方向上的空间的运算.池化方法: Max池化是从目标区域中取出最大值; Average池化则是计算目标区域的平均值,只需要将上面的max–>>mean (2)池化后的形状: 设输入图像尺寸为WxH,其中W:图像宽,H:图像高,D:通道数(图像深度),滤波器大小(FxF),S:步长,池化后输出图像...

月上桃花,拨灯书尽百世梦 545

欧姆龙多PLC串行链接模式的应用

欧姆龙多PLC串行链接模式的应用 一、如何将两台CP1H进行串行PLC连接(PLC串行链接) 主机侧设定 从机侧设定 二、 如何实现编程通信 主机侧的【PC连接模式】为【全部】的时候 ① 主机会把自己的地址从3100开始,按照【链接字】设定的字数个数发送到每个从机的3100开始进行存储。 ② 从机会把自己的地址从31n0开始,按照主机侧参数【链接字】设定的字数个数发送到主机的31n0开始进行存储。 注:(n为从机的地址号,若从机号不连续,则该编号的地址将不被定义..

u014202847的博客 3087

matlab中给图像加几个矩形框_MATLAB--数字图像处理 im2col()

im2col()矩阵卷积卷积就是卷积核跟图像矩阵的运算。卷积核是一个小窗口,记录的是权重。卷积核在输入图像上按步长滑动,每次操作卷积核对应区域的输入图像,将卷积核中的权值和对应的输入图像的值相乘再相加,赋给卷积核中心所对应的输出特征图的一个值,如下图所示(这里卷积核要旋转180 °):如果还不懂的话,可以类比均值滤波,用一个矩阵算子对于图像上一块图像,对于像素点相乘,再相加,这就是卷积。(再理解简...

weixin_42302638的博客 522

中文顶刊《会计研究》文本分析技术最新进展总结盘点

会计研究》是由中华人民共和国财政部主管、中国会计学会主办的国家一级学术期刊,为会计领域中文顶级期刊。随着大数据技术的日益成熟, 社交网络类文本 、上市公司披露类文本、媒体报道类文本、 其他类文本 、网络搜索数据、P2P 网络借贷文 本与分析师报告等文本数据逐渐成为财务会计的研究素材。

qq_52891550的博客 2891

【K210+STM32项目】基于K210与STM32协同工作的智能垃圾分类系统设计与实现(更新3.0版本)(完整工程资料源码)

STM32F407STM32F407_2(含有app功能)

嵌入式技术开发 2491

Python实现im2col和col2im函数

今天来说说im2col和col2im函数,这是MATLAB中两个内置函数,经常用于数字图像处理中。 一般来说: 如果将图像分割成块的时候用的im2col参数为’distinct’,那么用col2im函数时参数也是’distinct’,即可将转换后的数组复原。 如果将图像分割成块的时候用的im2col参数为’sliding’,我目前还不知道MATLAB中使用内置函数是如何复原的。 今天,来看看Python中是如何实现这两个函数的(sliding类型)。 对于im2col的实现,我们沿着原始矩阵逐

Python热爱者的博客 902

【NLP】第十章:位置编码Positional Encoding

前面讲RNN时一般都会有一个ht的输出,这个输出就是样本与样本之间的信息,而且RNN是时序循环的,所以RNN本身的结构,在物理上,就自带词的前后顺序信息的。比如词never,不管never本身的词向量是什么,只要你在序列中排第一个位置,你的位置向量就是[0,1,01],你排第三个位置,你的位置向量就是[0.9,-0,4,0.2,1.0]。也所以,你可以理解为:embedding后的词嵌入,PE按照每个样本在sequence中的位置,把embedding后的词嵌入给扭转后,才送入attention的。

因为热爱所以坚持 1918

IDL im2col和col2im方法

IDL im2col和col2im函数示例 本人在卷积神经网络的卷积层、池化层的im2col和反向传播的col2im方法上有所启发,考虑到IDL本身并没有im2col和col2im函数,于是编写了相关的IDL函数。话不多说,直接上代码! 1. im2col ;input_data: 由(高, 长)的2维数组构成的输入数据 ;filter_h: 滤波器的高 ;filter_w: 滤波器的长 ;str...

慧慧的博客 817

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Python中如何实现im2col和col2im函数(sliding类型)

今天来说说im2col和col2im函数,这是MATLAB中两个内置函数,经常用于数字图像处理中。其中im2col函数在《MATLAB中的im2col函数》一文中已经进行了简单的介绍。一般来说: 如是将图像分割成块的时候用的im2col参数为’distinct’,那么用col2im函数时参数也是’distinct’,即可将转换后的数组复原。 如果将图像分割成块的时候用的im2col参数为’slidi

给永远比拿愉快 5221

深度学习工具包 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")

CV预备(二): im2col与col2im

目录 前言 im2col col2im 最后 前言 Matlab矩阵处理的函数真的是太多了, 这里来看两个矩阵重排的函数im2col与col2im. im2col 这里有3种形式, 如下: B = im2col(A, [m n]) B = im2col(A, [m n], 'sliding') B = im2col(A, [m n], 'distinct') B = im...

weixin_33964094的博客 772

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

python col函数_Python实现im2col和col2im函数

今天来说说im2col和col2im函数,这是MATLAB中两个内置函数,经常用于数字图像处理中。其中im2col函数在《MATLAB中的im2col函数》一文中已经进行了简单的介绍。一般来说: 如是将图像分割成块的时候用的im2col参数为'distinct',那么用col2im函数时参数也是'distinct',即可将转换后的数组复原。如果将图像分割成块的时候用的im2col参数为'slidi...

weixin_39850699的博客 575

【Caffe源码学习】im2col和col2im

首先回顾一下卷积的实现理论细节,卷积核是一个小窗口(记录权重),在输入图像上按步长滑动,每次滑动操作输入图像上的对应小窗区域,将卷积核中的各个权值与输入图像上对应小窗口中的各个值相乘,然后相加,并加上偏置得到输出特征图上的一个值,见下图(图片来自网络) 这里原文https://blog.youkuaiyun.com/jiongnima/article/details/69736844,巴拉巴拉有很多解释...

mjiansun的专栏 2472

Python实现im2col和col2im函数完整代码

在这里先贴上了实现im2col和col2im函数的代码,已覆盖了基本功能,供大家调用学习,后续会附上两个函数的相关解析。 实现im2col函数: import numpy as np def im2col(img, kernel_size, strides=1, paddings=0, dilations=1): if not isinstance(kernel_size, list): k = kernel_size kernel_size = [k, k

码立的博客 3741

python中col函数_Python中如何实现im2col和col2im函数(sliding类型)

今天来说说im2col和col2im函数,这是MATLAB中两个内置函数,经常用于数字图像处理中。其中im2col函数在《MATLAB中的im2col函数》一文中已经进行了简单的介绍。一般来说:如是将图像分割成块的时候用的im2col参数为'distinct',那么用col2im函数时参数也是'distinct',即可将转换后的数组复原。如果将图像分割成块的时候用的im2col参数为'slidin...

weixin_39573535的博客 434

CNN col2im和im2col的实现

代码: ​ import numpy as np def im2col(mtx, block_size): mtx_shape = mtx.shape sx = mtx_shape[0] - block_size[0] + 1 sy = mtx_shape[1] - block_size[1] + 1 # 如果设A为m×n的,对于[p q]的块划分,最后矩阵的行数为p×q,列数为(m−p+1)×(n−q+1)。 result = np.empty((bloc

tugouxp的专栏 680

numpy-ml 神经网络工具集源码解析:minibatch、im2col/col2im、卷积与权重初始化实战指南

本篇文章聚焦 numpy-ml 项目 [neural_nets/utils/utils.py](https://link.gitcode.com/i/d6a393f945b8de2d433e8f9f2d0eae8e) 所实现的神经网络工具函数,涵盖训练批处理(minibatch)、padding 计算与填充、im2col/col2im 卷积向量化、1D/2D 卷积与转置卷积,以及 He/Gloro

gitblog_00816的博客 933

【代码阅读】darknet源码阅读(九):col2im.h 和 col2im.c

参考文献依然是放前面:https://blog.youkuaiyun.com/caicaiatnbu/category_9096319.html darknet版本: https://github.com/AlexeyAB/darknet,与原始的版本还是有一点区别的。 因为第一次读源码,我就直接按照参考文献的顺序来了,到时候再查漏补缺,加油! 【只分析原理,弄明白具体的功能,就不去看gpu了,等以后有时间再补.cu文件】 1.col2im.h #ifndef COL2IM_H #define COL2IM

weixin_38715903的博客 666
上一篇: Matlab R2012a安装
下一篇: 华为eNSP防火墙USG5500基本配置
compression
博客等级 码龄14年 22粉丝 17原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值