【发布时间】:2019-07-02 04:24:04
【问题描述】:
目标是尝试在第一层模型上使用自定义权重来充分填充高通滤波器的功能---使第一层模型与图像的高通滤波器相同。
1.首先,类似的解决方案是:在图像处理中使用高通滤波器,并生成新图像,并在模型中使用。 ---这是必须使用图像处理,这是时间成本。
2.我想设置Conv2D的a层,也可以高通图像。使用自定义过滤器(作为初始化器)。基本是filter和conv2D都使用卷积规则。
但结果与第一个解决方案不同。
#The image processing code:
kernel55 = np.array([[-1, 2, -2, 2, -1],
[2, -6, 8, -6, 2],
[-2, 8, -12, 8, -2],
[2,-6, 8, -6, 2],
[-1, 2, -2, 2, -1]])/12
# load the image, pre-process it, and store it in the data list
image = cv2.imread('1.pgm',-1)
image = ndimage.convolve(image, kernel55)
print(image)
#the first layer of the Model:
def kernel_init(shape):
kernel = np.zeros(shape)
kernel[:,:,0,0] = np.array([[-1, 2, -2, 2, -1],
[2, -6, 8, -6, 2],
[-2, 8, -12, 8, -2],
[2,-6, 8, -6, 2],
[-1, 2, -2, 2, -1]])/12
return kernel
#Build Keras model
model = Sequential()
model.add(Conv2D(1, [5,5], kernel_initializer=kernel_init,
input_shape=(256,256,1), padding="same",activation='relu'))
model.build()
test_im=cv2.imread('1.pgm',-1) # define a test image
test_im=np.expand_dims(np.expand_dims(np.array(test_im),2),0)
out = model.predict(test_im)
问题是: 使用图像处理能够产生适当的高通图像,但使用 Conv2D 是不一样的结果。
我假设两个结果应该相同或相似,但事实证明不是......
为什么,我的想法有什么问题吗?
【问题讨论】:
-
你在
for循环中做什么?因为我注意到imagePath未被使用
标签: python image-processing keras convolution