在 tensorflow js api 0.15.3 中设置卷积层的配置

我有一个我在 python 中使用 Keras API 在 tensorflow 上制作的 CNN,我想在 JavaScript 中实现它。但是在 tf for js API 0.15.3 中,我找不到为卷积层添加步幅和填充的选项。

我的 Python 代码如下所示。

X = Conv2D(64, (2, 2), strides = (1, 1), name = 'conv0')(X_input)

在 Js API 参考中。

tf.layers.conv2d (args) 函数源

2D 卷积层(例如图像上的空间卷积)。

该层创建一个卷积核,该核与层输入进行卷积以产生输出张量。

如果 useBias 为 True,则会创建一个偏置向量并将其添加到输出中。

如果激活不为空,它也适用于输出。

当将此层用作模型中的第一层时,提供关键字参数 inputShape(整数数组,不包括样本轴),例如 inputShape=[128, 128, 3] 对于 dataFormat='channelsLast' 中的 128x128 RGB 图片. 参数:

参数(对象)

过滤器(数量)输出空间的维度(即卷积中的过滤器数量)。

如果有人可以提供帮助,真的很感激。我应该使用像 0.9.0 这样的旧 API


慕雪6442864
浏览 167回答 1
1回答

30秒到达战场

刚刚发现,即使他们没有提到我们可以提供 strides 和 paddings 作为参数。我们实际上可以,根据源代码。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');
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python