我有一个图像(例如(7x7x3)和一个过滤器(3x3x3))。我将图像与过滤器转换成(3x3)输出。如果我想做逆运算,并希望它成为图像输出和过滤器。如何使用Numpy在Python中实现此操作?
我不知道我应该使用哪一个运算与过滤器(逆或转置)?
这是我的反褶积代码:
import numpy as np
def deConv(Z, cashe):
'''
deConv calculate the transpoe Convoultion between the output of the ConvNet and the filter
Arguments:
Z-- Output of the ConvNet Layer, an array of the shape()
'''
# Retrieve information from "cache"
(X_prev, W, b, s, p) = cashe
# Retrieve dimensions from X_prev's shape
(m, n_H_prev, n_W_prev, n_C_prev) = X_prev.shape
# Retrieve dimensions from W's shape
(f, f, n_C_prev, n_C) = W.shape
# Retrieve dimensions from Z's shape
(m, n_H, n_W, n_C) = Z.shape
#create initial array for the output of the Deconvolution
X_curr = np.zeros((m, n_H_prev, n_W_prev, n_C_prev))
#loop over the Training examples
for i in range (m):
#loop over the vertical of the output
for h in range(n_H):
#loop over the horizontal of the output
for w in range(n_W):
#loop over the
for c in range (n_C):
#loop over the color channels
for x in range(n_C_prev):
#inverse_W = np.linalg.pinv(W[:, :, x, c])
transpose_W = np.transpose(W[:,:,x,c])
#X_curr[i, h*s:h*s+f, w*s:w*s+f, x] += Z[i, h, w, c] * inverse_W
X_curr[i, h*s:h*s+f, w*s:w*s+f, x] += Z[i, h, w, c] * transpose_W
X_curr[i, h*s:h*s+f, w*s:w*s+f, :] += b[:,:,:,c]
X_curr = relu(X_curr)
return X_curr发布于 2019-04-07 03:40:22
This可能是不可逆的操作,除非卷积前的数据不是满的。但是请注意,您减少了信号的维数,因此卷积可能被裁剪为“有效”信息(不需要填充)。
如果您至少有图像或滤波器,则恢复可能是可能的,因为可以使用反褶积反转卷积,但请注意:
f(x) \circledast g(x) = h(x) = \int_{-\infty}^{\infty}f(x-t)g(t)dt T\{f(x) \circledast g(x)\}(s) = T\{h(x)\}(s) = T\{f(x)\}(s) \times T\{g(x)\}(s)
i中找到图像j,由滤波器h分别给出I、J和H作为i、j和h的离散傅里叶变换。设F\{.\}表示离散傅里叶变换,F^{-1}\{.\}表示其逆变换:i = F^{-1}\{I\} = F^{-1}\{\frac{J}{H}\}
注1:Is需要注意的是,您至少需要对过滤器进行估计,有很多算法可以这样做。
注2:Deconvolution对噪声非常敏感,您可以在数字图像处理上检查这个类以了解图像过滤,主要是关于Wiener过滤器的部分。
注3:图像反褶积是用许多算法(也是在图像处理工具箱中的matlab上)实现的。
https://datascience.stackexchange.com/questions/48776
复制相似问题