TensorSpace.js
Getting Start
Basic Concepts
Model Preprocessing
Models
Layers
Merge Function
DepthwiseConv2d
DepthwiseConv2d performs the first step in a depthwise spatial convolution, apply convolution operation on each input channel separately.
Constructor
Two methods to create a new layer. Arguments are required.
〔Method 1〕Use kernelSize and strides (Support two formats)
Rectangle kernel and stride(same height and width)
TSP.layers.DepthwiseConv2d( { kernelSize: Int, strides: Int } );
Kernel and stride with different width(first) and height(second)
TSP.layers.DepthwiseConv2d( { filters : Int, kernelSize: [Int, Int], strides: [Int, Int] } );
〔Method 2〕Use shape
TSP.layers.DepthwiseConv2d( { shape : [ Int, Int, Int ] } );
Fig. 1 - DepthwiseConv2d layer collapse and expand
Arguments

Name

Tag

Type

Instruction

Usage Notes and Examples

kernelSize

📦

Int The dimension of the convolution window The 2d convolutional window is square. kernelSize: 3

strides

📦

Int The strides of the convolution Strides in both dimensions are equal [default] Automatic inference strides = [1, 1]

name

🔧

String Name of this layer. Highly recommend to arrange to make code more readable. name: "layerName"

padding

🔧📦

String Is padding?

valid(default) Without padding. It drops the right-most columns (or bottom-most rows).

same With padding. Output size is the same as input size.

depthMultiplier

🔧📦

Int The number of depthwise convolution output channels for each input channel. Default to 1. For example, if input channel is 32, the default output channel would be 32, if depthMultiplier = 2, the output channel would be 64.

color

⚙️🎨

color format Color of layer DepthwiseConv2d default is #FBBF1F

closeButton

⚙️🎨

Dict Close button appearance control dict, more about close button

display : Boolean. true[default] Show button, false Hide button

ratio : Int. Times to normal size, default is 1

For example, 2 means twice the normal size

initStatus

⚙️️🎦

String Layer status at beginning. Open or Close close[default] : Closed at beginning

animation-
TimeRatio

⚙️🎦

Int The speed of open and close animation Integer for multiple of speed. For example, 2 for 2 times of basic speed.
Properties
.inputShape : Int[]
filter_center_focusThe shape of input tensor. For example, inputShape = [ 28, 28, 3 ] represents 3 feature maps and each one is 28 by 28.
filter_center_focusAfter model.init() data is available, otherwise is undefined.
.outputShape : Int[]
filter_center_focusThe shape of the output tensor is 3-dimensional. 3️⃣
filter_center_focusThe dataFormat is "channel last". For example, outputShape = [ 32, 32, 4 ] represents the output through this layer has 4 feature maps and each one is 32 by 32.
filter_center_focusAfter model.init() data is available, otherwise is undefined.
.neuralValue : Int[]
filter_center_focusThe intermediate raw data after this layer.
filter_center_focusAfter load and model.init(), the data are available. Otherwise is undefined.
.name : String
filter_center_focusThe custom name for this layer.
filter_center_focusOnce created, you can get it.
.layerType : String
filter_center_focusType of this layer, return a constant: string DepthwiseConv2d.
filter_center_focusOnce created, you can get it.
Method
filter_center_focusThis method only used in Functional Model (Non-sequential, Graph structure).
filter_center_focusLink this layer to layer which is the previous layer.
filter_center_focusTo crete a link between this layer and the previous layer. You don't need to use this method specifically to create links in Sequential Model; Instead, you can simply add layers along the lines of Keras or TensorFlow.js build the model syntax.
let conv2d = new TSP.layers.Conv2d( {

    shape: [28, 28],
    filters: 32

} );

let dwConv2d = new TSP.layers.DepthwiseConv2d( {

    kernelSize: 3,
    strides: 1

} );

dwConv2d.apply( conv2d );
filter_center_focusClick on the layer directly to open it by interacting directly with the object in the 3D scene.
filter_center_focusIn code, calling the method to open it.
let dwConv2d = new TSP.layers.DepthwiseConv2d( {

    // configure some parameters for DepthwiseConv2d.

} );

model.add( dwConv2d );

// ... add more layers for model.

model.init();

// Call openLayer API to open layer.

dwConv2d.openLayer();
filter_center_focusTo close by interacting directly with objects in a 3D scene by clicking the close button.
filter_center_focus In code, calling the method to close it.
let dwConv2d = new TSP.layers.DepthwiseConv2d( {

    // configure some parameters for DepthwiseConv2d.

} );

model.add( dwConv2d );

// ... add more layers for model.

model.init();

// If this layer already opened, call closeLayer API to close layer.

dwConv2d.closeLayer();
Example
filter_center_focus Declare an instance of DepthwiseConv2d to facilitate reuse
let dwConv2d = new TSP.layers.DepthwiseConv2d( {

    kernelSize: 3,
    strides: 1,
    depthMultiplier: 2,
    animationTimeRatio: 2,
    name: "depthwiseConv2d1",
    initStatus: "open"

} );

model.add( dwConv2d );
filter_center_focusAdd DepthwiseConv2d directly
model.add(new TSP.layers.DepthwiseConv2d( {

    kernelSize: 3,
    strides: 1,
    name: "depthwiseConv2d2"

} ));
Use Case
When you add convolutional layer with Keras | TensorFlow | tfjs in your model the corresponding API is DepthwiseConv2d in TensorSpace.
Framework Documentation
Keras keras.layers.SeparableConv2D(filters, kernel_size, strides=(1, 1))
TensorFlow tf.nn.depthwise_conv2d( input, filter, strides )
TensorFlow.js tf.layers.depthwiseConv2d (config)
Tag Lookup
Tag Icon Meaning Instruction
⭐️ Required Must be provided, cannot be empty. Meanwhile constructor works properly if this arguments provided. Control arguments use default value.
🔧 Suggest Recommended for giving. The API can work without them.
⚙️️ Optional As an auxiliary adjustment parameter when used, selectively added according to the specific situation The parameters here have no effect on the structure of the layer (3D visualized form).
📦 Model Configure the properties of the Layer. It changes the output shape.
🎨 Style Override the properties in TSP.model (model configuration)
🎦 Animation Override the properties in TSP.model (model configuration)
Source Code
tensorspace/src/layer/intermediate/DepthwiseConv2d.js