Closed BruceDai closed 2 years ago
Hi @BruceDai , thanks for the PR. You mentions it depends on a tfjs enhancement. May I know what is the gap? roundingType or outputSizes or both of them? If there is no gap to support roundingType. I would recommend to focus on that first without depending on the tfjs release.
Hi @huningxin.
Currently our pool2d implementation's invoked tf.pool()
function doesn't support dimRoundingMode
attributes which new option roundingType
could be mapped to, and tf.pool()
function either doesn't support outputSizes
attribute, so I submitted the PR to enable/support these two attributes for tfjs pool.
If we invoked tf.avgPool()
or tf.maxPool()
functions to replace tf.pool()
, we could support new option roundingType
firstly. Thanks.
If we invoked
tf.avgPool()
ortf.maxPool()
functions to replacetf.pool()
, we could support new optionroundingType
firstly. Thanks.
It sounds good to me.
If we invoked tf.avgPool() or tf.maxPool() functions to replace tf.pool(), we could support new option roundingType firstly.
@huningxin I'm sorry to deliver the wrong message, I missed considering the case of dilations
. tf.avgPool()
and tf.maxPool()
functions could not support dilations
directly, while tf.pool() function could do pre-processing with dilations
, as below code, then pass that to tf.avgPool()and
tf.maxPool()` functions
function pool_<T extends Tensor3D|Tensor4D>(
input: T|TensorLike, windowShape: [number, number]|number,
poolingType: 'avg'|'max',
pad: 'valid'|'same'|number|conv_util.ExplicitPadding,
dilations?: [number, number]|number, strides?: [number, number]|number,
dimRoundingMode?: 'floor'|'round'|'ceil') {
if (dilations == null) {
dilations = [1, 1];
}
...
util.assert(
conv_util.eitherStridesOrDilationsAreOne(strides, dilations),
() => 'Error in pool: Either strides or dilations must be 1. ' +
`Got strides ${strides} and dilations '${dilations}'`);
const convInfo = conv_util.computePool2DInfo(
x4D.shape, windowShape, strides, dilations, pad);
const dilation: [number, number] =
[convInfo.dilationHeight, convInfo.dilationWidth];
let basePadding: number[][];
if (pad === 'same') {
basePadding = withSpaceToBatchBasePaddings(
[convInfo.filterHeight, convInfo.filterWidth], dilation);
} else {
basePadding = [[0, 0], [0, 0]];
}
const isDilationOne = dilation[0] === 1 && dilation[1] === 1;
const [adjustedPadding, adjustedCrops] = requiredSpaceToBatchPaddings(
[convInfo.inHeight, convInfo.inWidth], dilation, basePadding);
const convertedPad = isDilationOne ? pad : 'valid';
const convertedX =
isDilationOne ? x4D : spaceToBatchND(x4D, dilation, adjustedPadding);
const forwardOp = poolingType === 'avg' ?
() => avgPool(convertedX, windowShape, strides, convertedPad,
dimRoundingMode) :
() => maxPool(convertedX, windowShape, strides, convertedPad,
dimRoundingMode);
...
So to enable these new two options, we still depend on tfjs implementation. Thanks
For outputSizes
options, I referred to output shape calculation method of pool2d on WebNN-native repo by @mingmingtasd.
@huningxin @mingmingtasd PTAL, thanks.
@mingmingtasd I updated code following your comments, please take another review, thanks.
@mingmingtasd I updated code following your comments, please take another review, thanks.
Thanks, LGTM! @BruceDai
Fix #135. Depend on https://github.com/tensorflow/tfjs/pull/5849.
@huningxin PTAL, thanks.