python-在tensorflow中使用gabor过滤器,或使用其他任何过滤器代替默认过滤器
作者:互联网
我想在CNN中使用gabor过滤器.使用convolution2d函数,如何更改它以将输入图像转换为gabor滤镜而不是默认的高斯滤镜?
解决方法:
这是一些代码,您可以将其用作使用OpenCV库创建的恒定(非学习型)Gabor过滤器的指南:
import tensorflow as tf
import cv2
# Create a 3x3 Gabor filter
params = {'ksize':(3, 3), 'sigma':1.0, 'theta': 0, 'lambd':15.0, 'gamma':0.02}
filter = cv2.getGaborKernel(**params)
# make the filter to have 4 dimensions.
filter = tf.expand_dims(filter, 2)
filter = tf.expand_dims(filter, 3)
# Apply the filter on `image`
answer = tf.conv2d(image, filter, strides=[1, 1, 1, 1], padding='SAME')
标签:convolution,tensorflow,opencv,deep-learning,python 来源: https://codeday.me/bug/20191026/1933846.html