conv2d包含了两个输入参数:x,filter。一个输出参数:output shape。
参考源码:https://github.com/tensorflow/tfjs-core/blob/master/src/ops/conv_util.ts, 版本号7833594
输入参数的处理
conv2d有两个输入参数:x和filter。
* @param x The input tensor, of rank 4 or rank 3, of shape
* `[batch, height, width, inChannels]`. If rank 3, batch of 1 is
* assumed.
* @param filter The filter, rank 4, of shape
* `[filterHeight, filterWidth, inDepth, outDepth]`.
输入参数x可以是4D, 3D。
4D输入NHWC:[batch, height, width, channels]
inShape: [number, number, number, number] = [2, 2, 2, inputDepth];
3D输入HWC:[height, width, channels]
inputShape: [number, number, number] = [4, 4, inputDepth];
如果输入2D,则会报错。譬如将const x: any = tf.tensor2d([1, 2, 3, 4], [2, 2]);这个传递给conv2d会报错。
输入参数filter滤波器。滤波器必须是4D的。否则运行会出错:
w = tf.tensor4d([1, 0.5, 1], [fSize, fSize, in

本文详细解析了TFJS中conv2d操作的输入参数处理,包括4D和3D输入的区别,重点讨论了PAD为'same'的情况。同时,介绍了输出形状的计算方法,涉及batchSize、outHeight、outWidth和outChannels的确定。最后通过一个简单的示例展示了stride=1,padding=same时的输入和输出形状计算。
最低0.47元/天 解锁文章
1048

被折叠的 条评论
为什么被折叠?



