huggingface / huggingface/candle
SeparableConv2d implementation
- Dominant language
- Rust
- Stars
- 21k
- Forks
- 1.8k
- Avg merge
- 16h 42m
- Merged PRs (30d)
- 25
Description
I'm trying to implement the Xception model based on tensorflow Keras implementation (and also comparing to the pytorch version). Here is my implementation of the SeparableConv2d in candle:
```rust
use candle_core::{Error as CandleError, Tensor};
use candle_nn::{conv2d_no_bias, Conv2d, Conv2dConfig, Module, VarBuilder};
pub struct SeparableConv2d {
depthwise: Conv2d,
pointwise: Conv2d,
}
impl SeparableConv2d {
pub fn new(
in_channels: usize,
out_channels: usize,
kernel_size: usize,
stride: usize,
padding: usize,
dilation: usize,
vb: VarBuilder,
) -> Result {
let depthwise = conv2d_no_bias(
in_channels,
in_channels,
kernel_size,
Conv2dConfig {
stride,
padding,
dilation,
groups: in_channels,
},
vb.pp("depthwise"),
)?;
let pointwise = conv2d_no_bias(
in_channels,
out_channels,
1,
Conv2dConfig {
stride: 1,
padding: 0,
dilation: 1,
groups: 1,
},
vb.pp("pointwise"),
)?;
Ok(Self {
depthwise,
pointwise,
})
}
}
impl Module for SeparableConv2d {
fn forward(&self, xs: &Tensor) -> candle_core::Result {
xs.apply(&self.depthwise)?.apply(&self.pointwise)
}
}
```
But when I compare the output tensors of the original model and the candle version (with the same pre-trained weights, transposed in channel_first format for candle) using patdiff, I notice a high deviation from the candle sepconv output. Could someone confirm the SeparableConv2d implementation is correct ?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the posted SeparableConv2d implementation and compare its depthwise and pointwise convolution configuration with the TensorFlow Keras and PyTorch implementations, using the same transposed channel-first weights. Confirm whether the outputs match; done means identifying whether the deviation comes from the convolution implementation or weight and layout handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- pytorch, rust, tensorflow
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100