Skip to content
This repository was archived by the owner on Sep 17, 2022. It is now read-only.

Add avgPool3d & maxPool3d to nodejs_kernel_backend #256

Merged
merged 3 commits into from
Aug 14, 2019

Conversation

syt123450
Copy link
Contributor

@syt123450 syt123450 commented Jun 6, 2019

This PR makes nodejs_kernel_backend support avgPool3d & maxPool3d.

Features in this PR:

  • Add avgPool3d to nodejs kernel
  • Add avgPool3dBackprop to nodejs kernel
  • Add maxPool3d to nodejs kernel
  • Add maxPool3dBackprop to nodejs kernel

Note:

  • Two new test cases in tfjs-core would throw exception when running in tfjs-node environment, as the test cases use NUMBER padding mode which TF backend doesn’t support. The broken test cases are:
  • This PR depends on tensorflow/tfjs-core#1778

Reference:


This change is Reviewable

dsmilkov pushed a commit to tensorflow/tfjs-core that referenced this pull request Aug 8, 2019
This PR adds `avgPool3d` op & `maxPool3d` op with CPU and WebGL implementation, supports inference and gradient. The APIs align with TensorFlow’s Python API [tf.nn.avg_pool3d](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/nn/avg_pool3d) and [tf.nn.max_pool3d](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/nn/max_pool3d). The `avgPool3d` & `maxPool3d` ops support `tf.layers.averagePooling3d` & `tf.layers.maxPooling3d` (feature requested in [tensorflow/tfjs#1035](tensorflow/tfjs#1035)).

As a checklist, features in this PR:
* Add `tf.avgPool3d` to ops
* Add `tf.maxPool3d` to ops
* Add `avgPool3d` kernel to handle `tf.avgPool3d`’s prediction
* Add `maxPool3d` kernel to handle `tf.maxPool3d`’s prediction
* Add private helper `pool3d` function in CPU kernel as the implementation of `avgPool3d` kernel and `maxPool3d` kernel in CPU end
* Add `Pool3DProgram` in WebGL kernel as the implementation of `avgPool3d` kernel and `maxPool3d` kernel in GPU end
* Add `avgPool3dBackprop` kernel to handle `tf.avgPool3d`’s gradient
* Add `avgPool3dBackprop` CPU kernel implementation
* Add `AvgPool3DBackpropProgram` as the implementation of `avgPool3dBackprop` WebGL kernel
* Add `maxPool3dBackprop` kernel to handle `tf.maxPool3d`’s gradient
* Add `maxPool3dBackprop` CPU kernel implementation
* Add a private helper function `maxPool3dPositions` for maxPool3dBackprop in CPU kernel
* Add `MaxPool3DBackpropProgram` as the implementation of `maxPool3dBackprop` WebGL kernel
* Integrate WebGL end’s `maxPool3dPositions` helper function into Pool3DProgram
* Add a `computePool3DInfo` util function to compute operation information for `avgPool3d` & `maxPool3d`
* Make check function `eitherStridesOrDilationsAreOne` support 3D input
* Add 14 unit tests for `avgPool3d` (one test case failed in nodejs env as TF Backend doesn’t support `NUMBER` pad mode)
* Add 7 unit tests for `avgPool3dBackprop`
* Add 13 unit tests for `maxPool3d` (one test case failed in nodejs env as TF Backend doesn’t support `NUMBER` pad mode)
* Add 10 unit tests for `maxPool3dBackprop`
* Add 8 unit tests for util function `computePool3DInfo`
* Export `Tensor5D `type
* Add jsdocs and executable examples for website api documentation

I built a local website, if everything goes well, the `avgPool3d` and `maxPool3d` APIs would lie in `Operations/Convolution` section and look like the screen shot below:
<img width="1184" alt="Screen Shot 2019-06-06 at 1 32 30 AM" src="https://github.com/%3Ca%20href="https://user-images.githubusercontent.com/7977100/59018883-c13c3400-87fb-11e9-8f36-316edab35231.png" rel="nofollow">https://user-images.githubusercontent.com/7977100/59018883-c13c3400-87fb-11e9-8f36-316edab35231.png">

**Relative PRs:**
* Make nodejs kernel support  avgPool3d & maxPool3d  [tensorflow/tfjs-node#256](tensorflow/tfjs-node#256)
* Add averagePooling3d layer & maxPooling3d layer [tensorflow/tfjs-layers#555](tensorflow/tfjs-layers#555)
* Add avgPool3d & maxPool3d ops for graph model [tensorflow/tfjs-converter#375](tensorflow/tfjs-converter#375)

**Reference:**
* [tf.nn.avg_pool3d TensorFlow Python API](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/nn/avg_pool3d)
* [tf.nn.max_pool3d TensorFlow Python API](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/nn/max_pool3d)
---
To see the logs from the Cloud Build CI, please join either
our [discussion](https://groups.google.com/a/tensorflow.org/forum/#!forum/tfjs)
or [announcement](https://groups.google.com/a/tensorflow.org/forum/#!forum/tfjs-announce) mailing list.

FEATURE
Copy link

@kangyizhang kangyizhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the awesome PR!

@kangyizhang kangyizhang merged commit 4b5aa1b into tensorflow:master Aug 14, 2019
@syt123450
Copy link
Contributor Author

Thanks for the review @kangyizhang !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants