Skip to content

Add depthwise separable convolution problem (ID 189)#584

Open
syed-nazmus-sakib wants to merge 2 commits intoOpen-Deep-ML:mainfrom
syed-nazmus-sakib:add-depthwise-separable-conv
Open

Add depthwise separable convolution problem (ID 189)#584
syed-nazmus-sakib wants to merge 2 commits intoOpen-Deep-ML:mainfrom
syed-nazmus-sakib:add-depthwise-separable-conv

Conversation

@syed-nazmus-sakib
Copy link

Description

This PR implements Problem 189: Depthwise Separable Convolution, which is a key component of efficient architectures like Xception and MobileNet.

Changes

  • Added questions/189_implement-depthwise-separable-convolution/ with all required files (meta, learn, description, solution, tests).
  • Fixed utils/build_bundle.py to use utf-8 encoding to prevent UnicodeEncodeError on Windows systems.
  • Validated using utils/validate_questions.py.

Checklist

  • Question follows template structure
  • Solution passes all tests
  • Build script runs successfully

Copy link
Collaborator

@moe18 moe18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small edits, also clarification for example

@@ -0,0 +1,5 @@
{
"input": "input = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]), input.shape = (2, 2, 2)\ndepthwise_filters = np.array([[[1, 0.5]]]), shape = (1, 1, 2)\npointwise_filters = np.array([[[[0.5, 1], [1, 0.5]]]]), shape = (1, 1, 2, 2)",
"output": "array([[[2.5, 3.5], [3.5, 2.5]],\n [[5.5, 6.5], [6.5, 5.5]]])\nshape: (2, 2, 2)",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[[[1.5, 1.5], [3.5, 4.0]],
[[5.5, 6.5], [7.5, 9.0]]]

shouldn't it be this^

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good catch, sorry for the mistake. Updated the example with correct values for all four spatial positions and restructured the reasoning to walk through each one explicitly, so the depthwise→pointwise flow is unambiguous.

"test": "import numpy as np\ninput = np.arange(18).reshape(3, 3, 2).astype(float)\ndepthwise_filters = np.array([[[0.5, 0.5], [0.5, 0.5]], [[0.5, 0.5], [0.5, 0.5]]]).astype(float)\npointwise_filters = np.array([[[[1], [1]]]]).astype(float)\nresult = depthwise_separable_conv2d(input, depthwise_filters, pointwise_filters)\nprint(round(result[0, 0, 0], 2))",
"expected_output": "18.0"
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Negative filter values are never tested

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test with:

  • Depthwise filters: [1, -1] -> negates channel 1
  • Pointwise filters: [[-1, 1], [1, -1]] -> cross-negation
  • Expected: [-2.0, 2.0] which verifies sign propagation works correctly

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching the example output error! Fixed it with correct values and step-by-step reasoning for every spatial position. Also added a negative filter test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants