Performing 1D Depthwise conv using Keras 2D Depthwise conv

I would like to perform a 1D Depthwise convolution (ie the first step of the depthwise-separable convolution) for a machine learning model I am working on. This means that for an input activation space of h x w, there are h kernels, each 1xk, where k is the length of the kernel (see attached figure).

This is not currently offered by Keras, but one can use the available Depthwise 2D convolution (which operates on 3D inputs), and simply add an extra dimension to the 2D inputs, and permute such that the original 2D height will span the channels of the new 3D activation space (see figure). The model report, showing these dimensions and permutations is below (the format for the Depthwise layer is channels first).

However, I do not seem to be able to mimic this behaviour in a matlab golden model which uses the same input activation space and kernels. Does this method of using a Depthwise Conv2D to operate like a Depthwise Conv 1D make fundamental sense, or practical sense with keras, or am I missing something with the channel permutations perhaps?

Topic keras convolution matlab machine-learning

Category Data Science


Indeed I was able to prove that this method works, confirmed by my Matlab golden model. The problem was that in order to read the output activations of an intermediate layer in Keras, you have to create a separate model with the specified output.

This separate model in my case did not have the same weights as the original model, leading to incorrect outputs. But now that I read the output activations correct, I can confirm this method works.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.