convolution

Different 2D convolution results between keras and scipy

社会主义新天地 提交于 2019-12-02 03:33:49
问题 I found some results difficult to understand when trying to debug my neural network. I tried to do some computations offline using scipy (1.3.0), and I am not having the same results as with keras (2.3.1) with a tensorflow (1.14.0) backend. Here is a minimal reproducible example: from keras.layers import Conv2D, Input from keras.models import Model import numpy as np from scipy.signal import convolve2d image = np.array([[-1.16551484e-04, -1.88735046e-03, -7.90571701e-03, -1.52302440e-02, -1

Python: How can we smooth a noisy signal using moving average?

落花浮王杯 提交于 2019-12-02 02:37:13
For an evaluation of a random forest regression, I am trying to improve a result using a moving average filter after fitting a model using a RandomForestRegressor for a dataset found in this link import pandas as pd import math import matplotlib import matplotlib.pyplot as plt import numpy as np from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor from sklearn.model_selection import GridSearchCV from sklearn.metrics import r2_score, mean_squared_error, make_scorer from sklearn.model_selection import train_test_split from math import sqrt from sklearn.cross_validation

C# Convolution filter for any size matrix (1x1, 3x3, 5x5, …) not fully applied

半腔热情 提交于 2019-12-02 02:15:59
I'm making a convolution filter for my project and I managed to make it for any size of matrix but as it gets bigger I noticed that not all bits are changed. Here are the pictures showing the problem: First one is the original Filter: Blur 9x9 Filter: EdgeDetection 9x9: As you can see, there is a little stripe that is never changed and as the matrix gets bigger, the stripe also gets bigger (in 3x3 it wasn't visible) My convolution matrix class: public class ConvMatrix { public int Factor = 1; public int Height, Width; public int Offset = 0; public int[,] Arr; //later I assign functions to set

autocorrelation of the input in tensorflow/keras

一曲冷凌霜 提交于 2019-12-02 01:37:05
问题 I have a 1D input signal. I want to compute autocorrelation as the part of the neural net for further use inside the network. I need to perform convolution of input with input itself. To perform convolution in keras custom layer/ tensorflow. We need the following parameters data shape is "[batch, in_height, in_width, in_channels]", filter shape is "[filter_height, filter_width, in_channels, out_channels] There is no batch present in filter shape, which needs to be input in my case 回答1:

autocorrelation of the input in tensorflow/keras

若如初见. 提交于 2019-12-02 00:49:27
I have a 1D input signal. I want to compute autocorrelation as the part of the neural net for further use inside the network. I need to perform convolution of input with input itself. To perform convolution in keras custom layer/ tensorflow. We need the following parameters data shape is "[batch, in_height, in_width, in_channels]", filter shape is "[filter_height, filter_width, in_channels, out_channels] There is no batch present in filter shape, which needs to be input in my case TensorFlow now has an auto_correlation function. It should be in release 1.6 . If you build from source you can

Is there a Python equivalent of MATLAB's conv2 function?

╄→гoц情女王★ 提交于 2019-12-01 16:34:03
问题 Does Python or any of its modules have an equivalent of MATLAB's conv2 function? More specifically, I'm interested in something that does the same computation as conv2(A, B, 'same') in MATLAB. 回答1: Looks like scipy.signal.convolve2d is what you're looking for. 回答2: While the other answers already mention scipy.signal.convolve2d as an equivalent, i found that the results do differ when using mode='same' . While Matlab's conv2 results in artifacts on the bottom and right of an image, scipy

perform the exact same convolution as in theano's conv2d

感情迁移 提交于 2019-12-01 11:59:35
I have an existing classification model that was trained using theano's conv2d under theano.tensor.nnet. Now I have to use this model to do some sort of prediction in Java. I implement a simple convolution in Python(In the end, I will code it in Java) as per some documentation( https://developer.apple.com/Library/ios/documentation/Performance/Conceptual/vImage/ConvolutionOperations/ConvolutionOperations.html ). For example, for a 2*2 kernel (k11,k12,k21,k22), one of the areas under the kernel is (a11,a12,a21,a22). The convolution is performed by a11*k11 + a12*k12 + a21*k21 + a22*k22.

Convolution and Deconvolution in Python using scipy.signal

我只是一个虾纸丫 提交于 2019-12-01 11:00:59
I am trying to do some (de)convolution with audio samples. I have one sample s and the same sample with some filters added on top of it s_f . Both samples are represented as numpy arrays. I want to deconvolve them in order to get an array that represents the isolated filter f . Once I do that I should be able to reproduce s_f using convolution of s and f . Here's the code: f = signal.deconvolve(s, s_f) convolved = signal.convolve(s, f) However, I get the following error on the second line: ValueError: in1 and in2 should have the same rank Does anyone know what am I doing wrong here? Thanks

Tensorflow: Trainable Variable Masking

若如初见. 提交于 2019-12-01 10:33:08
I am working on a convolutional neural net that requires some parts of the a kernel weights to be untrainable. tf.nn.conv2d(x, W) takes in a trainable variable W as weights. How can I make some of the elements of W to be untrainable? Maybe you could have your trainable weights W1 , a mask M indicating where the trainable variables are, and a constant / untrainable weight matrix W2 , and use W = tf.multiply(W1, tf.cast(M, dtype=W1.dtype)) + tf.multiply(W2, tf.cast(tf.logical_not(M), dtype=W2.dtype)) 来源: https://stackoverflow.com/questions/44774672/tensorflow-trainable-variable-masking

Fast convolution algorithm

萝らか妹 提交于 2019-12-01 09:03:21
I need to convolve two one dimensional signals, one has on average 500 points (This one is a Hanning window function), the other 125000. Per run, I need to apply three times the convolution operation. I already have an implementation running based on the documentation of scipy. You can see the code here if you want to (Delphi code ahead): function Convolve(const signal_1, signal_2 : ExtArray) : ExtArray; var capital_k : Integer; capital_m : Integer; smallest : Integer; y : ExtArray; n : Integer; k : Integer; lower, upper : Integer; begin capital_k := Length(signal_1) + Length(signal_2) - 1;