Reputation: 351
I have a CNN that I have made in python using Keras API on tensorflow that I want to implement in JavaScript. But in tf for js API 0.15.3, I Cannot find the options to add strides and padding for convolutional layers.
My Python Code Looks like this.
X = Conv2D(64, (2, 2), strides = (1, 1), name = 'conv0')(X_input)
In Js API ref.
tf.layers.conv2d (args) function Source
2D convolution layer (e.g. spatial convolution over images).
This layer creates a convolution kernel that is convolved with the layer input to produce a tensor of outputs.
If useBias is True, a bias vector is created and added to the outputs.
If activation is not null, it is applied to the outputs as well.
When using this layer as the first layer in a model, provide the keyword argument inputShape (Array of integers, does not include the sample axis), e.g. inputShape=[128, 128, 3] for 128x128 RGB pictures in dataFormat='channelsLast'. Parameters:
args (Object)
filters (number) The dimensionality of the output space (i.e. the number of filters in the convolution).
Really Appreciate if anyone could help. Should I use an old API like 0.9.0
Upvotes: 1
Views: 136
Reputation: 351
Just Found out that even though they haven't mentioned that we can give strides and paddings as an argument. We actually can, According to the source code.
constructor(rank: number, args: BaseConvLayerArgs) {
super(args as LayerArgs);
BaseConv.verifyArgs(args);
this.rank = rank;
if (this.rank !== 1 && this.rank !== 2) {
throw new NotImplementedError(
`Convolution layer for rank other than 1 or 2 (${this.rank}) is ` +
`not implemented yet.`);
}
this.kernelSize = normalizeArray(args.kernelSize, rank, 'kernelSize');
this.strides = normalizeArray(
args.strides == null ? 1 : args.strides, rank, 'strides');
this.padding = args.padding == null ? 'valid' : args.padding;
checkPaddingMode(this.padding);
this.dataFormat =
args.dataFormat == null ? 'channelsLast' : args.dataFormat;
checkDataFormat(this.dataFormat);
this.activation = getActivation(args.activation);
this.useBias = args.useBias == null ? true : args.useBias;
this.biasInitializer =
getInitializer(args.biasInitializer || this.DEFAULT_BIAS_INITIALIZER);
this.biasConstraint = getConstraint(args.biasConstraint);
this.biasRegularizer = getRegularizer(args.biasRegularizer);
this.activityRegularizer = getRegularizer(args.activityRegularizer);
this.dilationRate = normalizeArray(
args.dilationRate == null ? 1 : args.dilationRate, rank,
'dilationRate');
Upvotes: 1