如何构建用于3D卷积的Sobel滤波器?

在我的代码片段中,我想构建一个Sobel滤波器,分别应用于图像(RGB)的每一层,最后将处理后的图像(仍然是RGB,但已被滤波)拼接在一起。

我不知道如何构建Sobel滤波器,其输入形状为[filter_depth, filter_height, filter_width, in_channels, out_channesl],在我这里是这样的:

 sobel_x_filter = tf.reshape(sobel_x, [1, 3, 3, 3, 3]) 

整个代码看起来像这样:


回答:

你可以使用 tf.nn.depthwise_conv2d

sobel_x = tf.constant([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], tf.float32)kernel = tf.tile(sobel_x[...,None],[1,1,3])[...,None]conv = tf.nn.depthwise_conv2d(image[None,...], kernel,strides=[1,1,1,1],padding='SAME')

使用 tf.nn.conv3d

im = tf.expand_dims(tf.transpose(image, [2, 0, 1]),0)sobel_x = tf.constant([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], tf.float32)sobel_x_filter = tf.reshape(sobel_x, [1, 3, 3, 1, 1])conv = tf.transpose(tf.squeeze(tf.nn.conv3d(im[...,None], sobel_x_filter,                    strides=[1,1,1,1,1],padding='SAME')), [1,2,0])

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注