convolution

Performing Convolution (NOT cross-correlation) in pytorch

不羁的心 提交于 2020-01-12 18:43:30
问题 I have a network (https://github.com/TheAbhiKumar/tensorflow-value-iteration-networks) that I am trying to implement in pytorch (I'm very new to pytorch, however, not at all new to machine learning). In short, I cannot seem to figure out how to implement "pure" convolution in pytorch. In tensorflow it could be accomplished like this: def conv2d_flipkernel(x, k, name=None): return tf.nn.conv2d(x, flipkernel(k), name=name, strides=(1, 1, 1, 1), padding='SAME') With the flipkernel function being

CUDA small kernel 2d convolution - how to do it

不羁岁月 提交于 2020-01-12 06:57:05
问题 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

Using numpy `as_strided` function to create patches, tiles, rolling or sliding windows of arbitrary dimension

烈酒焚心 提交于 2020-01-08 13:22:30
问题 Spent a while this morning looking for a generalized question to point duplicates to for questions about as_strided and/or how to make generalized window functions. There seem to be a lot of questions on how to (safely) create patches, sliding windows, rolling windows, tiles, or views onto an array for machine learning, convolution, image processing and/or numerical integration. I'm looking for a generalized function that can accept a window , step and axis parameter and return an as_strided

Real-time impulse response convolution with FFTW — result sounds like IR is symmetrical

回眸只為那壹抹淺笑 提交于 2020-01-06 20:01:58
问题 For research purposes I am building a real-time reverb convolution engine in C++ using FFTW (and PortAudio for the sound delivery) with the overlap-add method for convolution. Most of it is working, but a very peculiar effect occurs. Though I can't see why, it sounds very much as if the impulse response becomes symmetrical: what was h[n] becomes h[n] + h[-n] . Does anyone know if performing FFT in the way I describe below would have this effect? Basically, my process is as follows: Known in

Deep learning: big difference between training and validation loss from the very first epoch on

こ雲淡風輕ζ 提交于 2020-01-06 08:08:20
问题 My neural net is slightly modified version of model proposed on this paper: https://arxiv.org/pdf/1606.01781.pdf My goal is to classify text to 9 different categories. I'm using 29 convolutional layers and have set the max length of any text to 256 characters. Training data has 900k and validation data 35k samples. The data is quite imbalanced and therefore I have done some data augmentation to balance the training data (have not touched the validation data obviously) and then used class

Keras Conv1D for Time Series

喜你入骨 提交于 2020-01-06 05:50:11
问题 I am just a novice in area of deep learning. I made my first basic attempt with Keras Conv1D. Not sure what I did and whether I did it right. My input data is simply total sales by every week (total of 313 weeks), for stores across US and with a time step of 1. Here is my code: from pandas import read_csv import matplotlib.pyplot as plt import numpy from keras.datasets import imdb from keras.models import Sequential from keras.layers import Dense from keras.layers import Flatten from keras

Keras wrong image size

给你一囗甜甜゛ 提交于 2020-01-05 07:09:11
问题 I want to test the accuracy of my CNN model for the test-images . Following is the code for converting Ground-truth images in mha format to png format. def save_labels(fns): ''' INPUT list 'fns': filepaths to all labels ''' progress.currval = 0 for label_idx in progress(xrange(len(fns))): slices = io.imread(fns[label_idx], plugin = 'simpleitk') for slice_idx in xrange(len(slices)): ''' commented code in order to reshape the image slices. I tried reshaping but it did not work strip=slices

What's the difference between convolution in Keras vs Caffe?

丶灬走出姿态 提交于 2020-01-05 04:38:06
问题 I'm trying to replicate a large Caffe network into Keras (based on tensorflow backend). But I'm having a large trouble doing it even at a single convolutional layer. Simple Convolution in General : Let's say we had a 4D input with shape (1, 500, 500, 3) , and we had to perform a single convolution on this input with 96 filters with kernel size of 11 and 4x4 strides. Let's set our weight and input variables: w = np.random.rand(11, 11, 3, 96) # weights 1 b = np.random.rand(96) # weights 2 (bias

Linear convolution using fft for system output

怎甘沉沦 提交于 2020-01-05 04:36:12
问题 Here is a mass-spring-damper system with an impulse response, h and an arbitrary forcing function, f ( cos(t) in this case). I am trying to use Matlab's FFT function in order to perform convolution in the frequency domain. I am expecting for the output ( ifft(conv) ) to be the solution to the mass-spring-damper system with the specified forcing, however my plot looks completely wrong! So, i must be implementing something wrong. Please help me find my errors in my code below! Thanks clear

Optimizing 1D Convolution

守給你的承諾、 提交于 2020-01-03 02:28:10
问题 Is there a way to speed up this 1D convolution ? I tried to make the dy cache efficient but compiling with g++ and -O3 gave worse performances. I am convolving with [-1. , 0., 1] in both directions. Is not homework. #include<iostream> #include<cstdlib> #include<sys/time.h> void print_matrix( int height, int width, float *matrix){ for (int j=0; j < height; j++){ for (int i=0; i < width; i++){ std::cout << matrix[j * width + i] << ","; } std::cout << std::endl; } } void fill_matrix( int height,