convolution

Keras input_shape for conv2d and manually loaded images

瘦欲@ 提交于 2019-12-03 13:05:43
问题 I am manually creating my dataset from a number of 384x286 b/w images. I load an image like this: x = [] for f in files: img = Image.open(f) img.load() data = np.asarray(img, dtype="int32") x.append(data) x = np.array(x) this results in x being an array (num_samples, 286, 384) print(x.shape) => (100, 286, 384) reading the keras documentation, and checking my backend, i should provide to the convolution step an input_shape composed by ( rows, cols, channels ) since i don't arbitrarily know the

CUDA small kernel 2d convolution - how to do it

元气小坏坏 提交于 2019-12-03 10:48:52
I've been experimenting with CUDA kernels for days to perform a fast 2D convolution between a 500x500 image (but I could also vary the dimensions) and a very small 2D kernel (a laplacian 2d kernel, so it's a 3x3 kernel.. too small to take a huge advantage with all the cuda threads). I created a CPU classic implementation (two for loops, as easy as you would think) and then I started creating CUDA kernels. After a few disappointing attempts to perform a faster convolution I ended up with this code: http://www.evl.uic.edu/sjames/cs525/final.html (see the Shared Memory section), it basically lets

Is there a equivalent of scipy.signal.deconvolve for 2D arrays?

a 夏天 提交于 2019-12-03 10:27:38
问题 I would like to deconvolve a 2D image with a point spread function (PSF). I've seen there is a scipy.signal.deconvolve function that works for one-dimensional arrays, and scipy.signal.fftconvolve to convolve multi-dimensional arrays. Is there a specific function in scipy to deconvolve 2D arrays? I have defined a fftdeconvolve function replacing the product in fftconvolve by a divistion: def fftdeconvolve(in1, in2, mode="full"): """Deconvolve two N-dimensional arrays using FFT. See convolve. "

How to perform 1-dimensional “valid” convolution? [closed]

不打扰是莪最后的温柔 提交于 2019-12-03 10:14:29
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I'm trying to implement a 1-dimensional convolution in "valid" mode (Matlab definition) in C++. It seems pretty simple, but I haven't been able to find a code doing that in C++ (or any other language that I could adapt to as a matter of fact). If my vector size is a power, I can

Calculating the blur kernel between 2 images

浪尽此生 提交于 2019-12-03 09:21:52
Unlike the standard (and more challenging) de-blurring and super resolution scenarios, I have access to both the original (sharp) image G and it's blurred version B . I'm simply looking for the blur kernel h . So because B is taken using a real camera the relation is: B=G*h+N (where * denotes convolution and N is some additive noise) Naturally, this is an over-constrained problem since h is small in size compared to G and B and so every few pixels in the pair of images generate an equation on the entries of h . But what would be the simplest way to actually implement this? My thoughts so far:

2D circular convolution Vs convolution FFT [Matlab/Octave/Python]

痞子三分冷 提交于 2019-12-03 08:58:09
I am trying to understand the FTT and convolution (cross-correlation) theory and for that reason I have created the following code to understand it. The code is Matlab/Octave, however I could also do it in Python. In 1D: x = [5 6 8 2 5]; y = [6 -1 3 5 1]; x1 = [x zeros(1,4)]; y1 = [y zeros(1,4)]; c1 = ifft(fft(x1).*fft(y1)); c2 = conv(x,y); c1 = 30 31 57 47 87 47 33 27 5 c2 = 30 31 57 47 87 47 33 27 5 In 2D: X=[1 2 3;4 5 6; 7 8 9] y=[-1 1]; conv1 = conv2(x,y) conv1 = 24 53 89 29 21 96 140 197 65 42 168 227 305 101 63 Here is where I find the problem, padding a matrix and a vector? How should I

Strided convolution of 2D in numpy

北城以北 提交于 2019-12-03 08:54:11
I tried to implement strided convolution of a 2D array using for loop i.e arr = np.array([[2,3,7,4,6,2,9], [6,6,9,8,7,4,3], [3,4,8,3,8,9,7], [7,8,3,6,6,3,4], [4,2,1,8,3,4,6], [3,2,4,1,9,8,3], [0,1,3,9,2,1,4]]) arr2 = np.array([[3,4,4], [1,0,2], [-1,0,3]]) def stride_conv(arr1,arr2,s,p): beg = 0 end = arr2.shape[0] final = [] for i in range(0,arr1.shape[0]-1,s): k = [] for j in range(0,arr1.shape[0]-1,s): k.append(np.sum(arr1[beg+i : end+i, beg+j:end+j] * (arr2))) final.append(k) return np.array(final) stride_conv(arr,arr2,2,0) This results in 3*3 array: array([[ 91, 100, 88], [ 69, 91, 117], [

Gaussian blur and convolution kernels

筅森魡賤 提交于 2019-12-03 08:52:07
问题 I do not understand what a convolution kernel is and how I would apply a convolution matrix to pixels in an image (I am talking about doing a Gaussian Blur operation on an image). Also could I get an explanation on how to create a kernel for a Gaussian Blur operation? I am reading this article but I cannot seem to understand how things are done... Thanks to anyone who takes time to explain this to me :), ExtremeCoder 回答1: The basic idea is that the new pixels of the image are created by an

Gaussian Blur with FFT Questions

这一生的挚爱 提交于 2019-12-03 08:49:44
I have a current implementation of Gaussian Blur using regular convolution. It is efficient enough for small kernels, but once the kernels size gets a little bigger, the performance takes a hit. So, I am thinking to implement the convolution using FFT. I've never had any experience with FFT related image processing so I have a few questions. Is a 2D FFT based convolution also separable into two 1D convolutions ? If true, does it go like this - 1D FFT on every row, and then 1D FFT on every column, then multiply with the 2D kernel and then inverse transform of every column and the inverse

How is using im2col operation in convolutional nets more efficient?

一曲冷凌霜 提交于 2019-12-03 07:51:38
I am trying to implement a convolutional neural netwrok and I don't understand why using im2col operation is more efficient. It basically stores the input to be multiplied by filter in separate columns. But why shouldn't loops be used directly to calculate convolution instead of first performing im2col ? Well, you are thinking in the right way, In Alex Net almost 95% of the GPU time and 89% on CPU time is spent on the Convolutional Layer and Fully Connected Layer. The Convolutional Layer and Fully Connected Layer are implemented using GEMM that stands for General Matrix to Matrix