tensorflow - TensorRT 中的 Depthwise_conv2d
问题描述
从 Tensorflow 转换为 TensorRT 时,Depthwise_con2d 存在问题。
实现如图所示。
TensorFlow 代码如下。
def gauss_kernel(self, kernlen=21, nsig=3, channels=1):
interval = (2*nsig+1.)/(kernlen)
x = np.linspace(-nsig-interval/2., nsig+interval/2., kernlen+1)
kern1d = np.diff(st.norm.cdf(x))
kernel_raw = np.sqrt(np.outer(kern1d, kern1d))
kernel = kernel_raw/kernel_raw.sum()
out_filter = np.array(kernel, dtype = np.float32)
out_filter = out_filter.reshape((kernlen, kernlen, 1, 1))
out_filter = np.repeat(out_filter, channels, axis = 2)
return out_filter
def make_gauss_var(self, name, size, sigma, c_i):
# with tf.device("/cpu:0"):
kernel = self.gauss_kernel(size, sigma, c_i)
var = tf.Variable(tf.convert_to_tensor(kernel), name=name)
return var
@layer
def smoother(self, input, name='gaussian_heatMat'):
# Get the number of channels in the input
c_i = input.get_shape().as_list()[3]
# Convolution for a given input and kernel
convolve = lambda i, k: tf.nn.depthwise_conv2d(i, k, [1, 1, 1, 1], padding='SAME')
with tf.variable_scope(name) as scope:
kernel = self.make_gauss_var('gauss_weight', 25, 3.0, c_i)#filter_size=25,sigma=3.0
output = convolve(input, kernel)
return output
我在从 uff 解析到网络时出错
[TensorRT] ERROR: gaussian_heatMat/depthwise: kernel weights has count 11875 but 7796358 was expected
[TensorRT] ERROR: gaussian_heatMat/depthwise: count of 11875 weights in kernel, but kernel dimensions (25, 25) with 1459200 input channels, 19 output channels and 19 groups were specified.
[TensorRT] ERROR: UffParser: Parser error: MarkOutput_0: Order size is not matching the number dimensions of TensorRT
11875 = 25*25*19 所以这是内核。为什么预期为 7796358?也不要在其他错误下。
解决方案
推荐阅读
- php - TYPO3:从另一个扩展覆盖 TCA 后端类公共变量
- mysql - Node Js在Firebase中发送通知之前查询MySql
- python - Python列表理解太慢了
- angular - Angular 6:Http升级
- c++ - “'CLOCK_PER_SEC' 未在此范围内声明”错误,即使包含
- android - Android Studio 3.2 Preview 中的导航预览不可用
- arrays - 插入嵌套数组
- javascript - 试图在前端显示信息
- aws-lambda - Kinesis:异常:SocketException:不允许操作(选择/轮询失败)
- java - 如何在 Gradle 中获取生命周期库的版本?