@@ -509,52 +509,13 @@ function withSpaceToBatchBasePaddings(
509
509
* - For more info, see this guide:
510
510
* [https://www.tensorflow.org/api_guides/python/nn#Convolution](
511
511
* https://www.tensorflow.org/api_guides/python/nn#Convolution)
512
- * @param dimRoundingMode The rounding mode used when computing output
513
- * dimensions if pad is a number. If none is provided, it will not round
514
- * and error if the output is of fractional size.
515
- * @param dataFormat An optional string from: "NDHWC", "NCDHW". Defaults to
516
- * "NDHWC". Specify the data format of the input and output data. With the
517
- * default format "NDHWC", the data is stored in the order of: [batch,
518
- * depth, height, width, channels]. Only "NDHWC" is currently supported.
519
- */
520
- /** @doc {heading: 'Operations', subheading: 'Convolution'} */
521
- function avgPool3d_ (
522
- x : Tensor5D | TensorLike , filterSize : [ number , number , number ] | number ,
523
- strides : [ number , number , number ] | number , pad : 'valid' | 'same' | number ,
524
- dimRoundingMode ?: 'floor' | 'round' | 'ceil' ,
525
- dataFormat : 'NDHWC' | 'NCDHW' = 'NDHWC' ) : Tensor5D {
526
- return avgPool3dImpl_ (
527
- x , filterSize , strides , 1 , pad , dimRoundingMode , dataFormat ) ;
528
- }
529
-
530
- /**
531
- * Computes the 3D average pooling.
532
- *
533
- * @param x The input tensor, of rank 5 of shape
534
- * `[batch, depth, height, width, inChannels]`.
535
- * @param filterSize The filter size:
536
- * `[filterDepth, filterHeight, filterWidth]`.
537
- * If `filterSize` is a single number,
538
- * then `filterDepth == filterHeight == filterWidth`.
539
- * @param strides The strides of the pooling:
540
- * `[strideDepth, strideHeight, strideWidth]`.
541
- * If `strides` is a single number,
542
- * then `strideDepth == strideHeight == strideWidth`.
543
512
* @param dilations The dilation rates:
544
513
* `[dilationDepth, dilationHeight, dilationWidth]`
545
514
* in which we sample input values across the depth, height and width
546
515
* dimensions in dilated pooling.
547
516
* Defaults to `[1, 1, 1]`. If `dilations` is a single number,
548
517
* then `dilationDepth == dilationHeight == dilationWidth`.
549
518
* If it is greater than 1, then all values of `strides` must be 1.
550
- * @param pad The type of padding algorithm.
551
- * - `same` and stride 1: output will be of same size as input,
552
- * regardless of filter size.
553
- * - `valid`: output will be smaller than input if filter is larger
554
- * than 1*1x1.
555
- * - For more info, see this guide:
556
- * [https://www.tensorflow.org/api_guides/python/nn#Convolution](
557
- * https://www.tensorflow.org/api_guides/python/nn#Convolution)
558
519
* @param dimRoundingMode The rounding mode used when computing output
559
520
* dimensions if pad is a number. If none is provided, it will not round
560
521
* and error if the output is of fractional size.
@@ -563,14 +524,15 @@ function avgPool3d_(
563
524
* default format "NDHWC", the data is stored in the order of: [batch,
564
525
* depth, height, width, channels]. Only "NDHWC" is currently supported.
565
526
*/
566
- function avgPool3dImpl_ (
527
+ /** @doc {heading: 'Operations', subheading: 'Convolution'} */
528
+ function avgPool3d_ (
567
529
x : Tensor5D | TensorLike , filterSize : [ number , number , number ] | number ,
568
- strides : [ number , number , number ] | number ,
569
- dilations : [ number , number , number ] | number , pad : 'valid' | 'same' | number ,
530
+ strides : [ number , number , number ] | number , pad : 'valid' | 'same' | number ,
531
+ dilations : [ number , number , number ] | number ,
570
532
dimRoundingMode ?: 'floor' | 'round' | 'ceil' ,
571
533
dataFormat : 'NDHWC' | 'NCDHW' = 'NDHWC' ) : Tensor5D {
572
534
const $x = convertToTensor ( x , 'x' , 'avgPool3d' , 'float32' ) ;
573
-
535
+
574
536
if ( dilations == null ) {
575
537
dilations = [ 1 , 1 , 1 ] ;
576
538
}
@@ -591,22 +553,22 @@ function avgPool3dImpl_(
591
553
( ) => `Error in avgPool3d: pad must be an integer when using, ` +
592
554
`dimRoundingMode ${ dimRoundingMode } but got pad ${ pad } .` ) ;
593
555
}
594
-
556
+
595
557
const convInfo = conv_util . computePool3DInfo (
596
558
$x . shape , filterSize , strides , dilations , pad , dimRoundingMode ,
597
559
dataFormat ) ;
598
-
560
+
599
561
const grad = ( dy : Tensor5D ) => {
600
562
return {
601
563
x : ( ) => avgPool3dBackprop (
602
564
dy , $x , filterSize , strides , dilations , pad , dimRoundingMode )
603
565
} ;
604
566
} ;
605
-
567
+
606
568
let res = ENGINE . runKernel (
607
569
backend => backend . avgPool3d ( $x , convInfo ) , { x : $x } , grad ) ;
608
570
res = res . cast ( $x . dtype ) ;
609
-
571
+
610
572
return res ;
611
573
}
612
574
@@ -706,52 +668,13 @@ function avgPool3dBackprop(
706
668
* - For more info, see this guide:
707
669
* [https://www.tensorflow.org/api_guides/python/nn#Convolution](
708
670
* https://www.tensorflow.org/api_guides/python/nn#Convolution)
709
- * @param dimRoundingMode The rounding mode used when computing output
710
- * dimensions if pad is a number. If none is provided, it will not round
711
- * and error if the output is of fractional size.
712
- * @param dataFormat An optional string from: "NDHWC", "NCDHW". Defaults to
713
- * "NDHWC". Specify the data format of the input and output data. With the
714
- * default format "NDHWC", the data is stored in the order of: [batch,
715
- * depth, height, width, channels]. Only "NDHWC" is currently supported.
716
- */
717
- /** @doc {heading: 'Operations', subheading: 'Convolution'} */
718
- function maxPool3d_ (
719
- x : Tensor5D | TensorLike , filterSize : [ number , number , number ] | number ,
720
- strides : [ number , number , number ] | number , pad : 'valid' | 'same' | number ,
721
- dimRoundingMode ?: 'floor' | 'round' | 'ceil' ,
722
- dataFormat : 'NDHWC' | 'NCDHW' = 'NDHWC' ) : Tensor5D {
723
- return maxPool3dImpl_ (
724
- x , filterSize , strides , 1 , pad , dimRoundingMode , dataFormat ) ;
725
- }
726
-
727
- /**
728
- * Computes the 3D max pooling.
729
- *
730
- * @param x The input tensor, of rank 5 of shape
731
- * `[batch, depth, height, width, inChannels]`.
732
- * @param filterSize The filter size:
733
- * `[filterDepth, filterHeight, filterWidth]`.
734
- * If `filterSize` is a single number,
735
- * then `filterDepth == filterHeight == filterWidth`.
736
- * @param strides The strides of the pooling:
737
- * `[strideDepth, strideHeight, strideWidth]`.
738
- * If `strides` is a single number,
739
- * then `strideDepth == strideHeight == strideWidth`.
740
671
* @param dilations The dilation rates:
741
672
* `[dilationDepth, dilationHeight, dilationWidth]`
742
673
* in which we sample input values across the depth, height and width
743
674
* dimensions in dilated pooling.
744
675
* Defaults to `[1, 1, 1]`. If `dilations` is a single number,
745
676
* then `dilationDepth == dilationHeight == dilationWidth`.
746
677
* If it is greater than 1, then all values of `strides` must be 1.
747
- * @param pad The type of padding algorithm.
748
- * - `same` and stride 1: output will be of same size as input,
749
- * regardless of filter size.
750
- * - `valid`: output will be smaller than input if filter is larger
751
- * than 1*1x1.
752
- * - For more info, see this guide:
753
- * [https://www.tensorflow.org/api_guides/python/nn#Convolution](
754
- * https://www.tensorflow.org/api_guides/python/nn#Convolution)
755
678
* @param dimRoundingMode The rounding mode used when computing output
756
679
* dimensions if pad is a number. If none is provided, it will not round
757
680
* and error if the output is of fractional size.
@@ -760,14 +683,15 @@ function maxPool3d_(
760
683
* default format "NDHWC", the data is stored in the order of: [batch,
761
684
* depth, height, width, channels]. Only "NDHWC" is currently supported.
762
685
*/
763
- function maxPool3dImpl_ (
686
+ /** @doc {heading: 'Operations', subheading: 'Convolution'} */
687
+ function maxPool3d_ (
764
688
x : Tensor5D | TensorLike , filterSize : [ number , number , number ] | number ,
765
- strides : [ number , number , number ] | number ,
766
- dilations : [ number , number , number ] | number , pad : 'valid' | 'same' | number ,
689
+ strides : [ number , number , number ] | number , pad : 'valid' | 'same' | number ,
690
+ dilations : [ number , number , number ] | number ,
767
691
dimRoundingMode ?: 'floor' | 'round' | 'ceil' ,
768
692
dataFormat : 'NDHWC' | 'NCDHW' = 'NDHWC' ) : Tensor5D {
769
693
const $x = convertToTensor ( x , 'x' , 'maxPool3d' ) ;
770
-
694
+
771
695
if ( dilations == null ) {
772
696
dilations = [ 1 , 1 , 1 ] ;
773
697
}
@@ -788,11 +712,11 @@ function maxPool3dImpl_(
788
712
( ) => `Error in maxPool3d: pad must be an integer when using, ` +
789
713
`dimRoundingMode ${ dimRoundingMode } but got pad ${ pad } .` ) ;
790
714
}
791
-
715
+
792
716
const convInfo = conv_util . computePool3DInfo (
793
717
$x . shape , filterSize , strides , dilations , pad , dimRoundingMode ,
794
718
dataFormat ) ;
795
-
719
+
796
720
const grad = ( dy : Tensor5D , saved : Tensor [ ] ) => {
797
721
const [ $x , y ] = saved ;
798
722
return {
@@ -801,13 +725,13 @@ function maxPool3dImpl_(
801
725
pad , dimRoundingMode )
802
726
} ;
803
727
} ;
804
-
728
+
805
729
const res = ENGINE . runKernel ( ( backend , save ) => {
806
730
const y = backend . maxPool3d ( $x , convInfo ) ;
807
731
save ( [ $x , y ] ) ;
808
732
return y ;
809
733
} , { x : $x } , grad ) ;
810
-
734
+
811
735
return res ;
812
736
}
813
737
0 commit comments