Add depthwise separable convolution problem (ID 189)#584
Add depthwise separable convolution problem (ID 189)#584syed-nazmus-sakib wants to merge 2 commits intoOpen-Deep-ML:mainfrom
Conversation
moe18
left a comment
There was a problem hiding this comment.
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)", | |||
There was a problem hiding this comment.
[[[1.5, 1.5], [3.5, 4.0]],
[[5.5, 6.5], [7.5, 9.0]]]
shouldn't it be this^
There was a problem hiding this comment.
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" | ||
| } | ||
|
|
There was a problem hiding this comment.
Negative filter values are never tested
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Description
This PR implements Problem 189: Depthwise Separable Convolution, which is a key component of efficient architectures like Xception and MobileNet.
Changes
questions/189_implement-depthwise-separable-convolution/with all required files (meta, learn, description, solution, tests).utils/build_bundle.pyto useutf-8encoding to preventUnicodeEncodeErroron Windows systems.utils/validate_questions.py.Checklist