tf.nn.separable_conv2d.md 1.5 KB
Newer Older
J
jiangjiajun 已提交
1 2
## tf.nn.separable_conv2d

J
jiangjiajun 已提交
3
### [tf.nn.separable_conv2d](https://www.tensorflow.org/versions/r1.13/api_docs/python/tf/nn/separable_conv2d)
J
jiangjiajun 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
``` python
tf.nn.separable_conv2d(
    input,
    depthwise_filter,
    pointwise_filter,
    strides,
    padding,
    rate=None,
    name=None,
    data_format=None
)
```

### PaddlePaddle实现
PaddlePaddle中目前无对应接口,可使用如下代码实现,在如下代码中只考虑了基本的`strides`参数,其它参数如`padding`在PaddlePaddle中使用机制
J
Jason 已提交
19
以及输入输出和卷积核格式与TensorFlow存在差异,可参考文档[tf.layers.conv2d](https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.layers.conv2d.md)[tf.nn.depthwise_conv2d](https://github.com/PaddlePaddle/X2Paddle/blob/master/tensorflow2fluid/doc/tf.nn.depthwise_conv2d.md)中的说明。
J
jiangjiajun 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32
``` python
# TensorFlow中separable_conv2d的使用
depthwise_filter = tf.random_uniform([4, 4, 3, 1], 0.0, 1.0)
pointwise_filter = tf.random_uniform([1, 1, 3, 5], 0.0, 1.0)
result = tf.nn.separable_conv2d(input, depthwise_filter, pointwise_filter, 
                        strides=[1, 1, 1, 1], padding='VALID')

# PaddlePaddle中对应如上代码实现separable_conv2d
depthwise_result = fluid.layers.conv2d(input, 3, filter_size=[4, 4], 
                                stride=[1, 1], groups=3, bias_attr=False)
pointwise_result = fluid.layers.conv2d(depthwise_result, filter_size=[1, 1], 
                                stride=[1, 1], bias_attr=False)

J
jiangjiajun 已提交
33
```