@@ -519,3 +519,83 @@ def call(self, x, mask=None):
519
519
return K .max (x , axis = [1 , 2 ])
520
520
else :
521
521
return K .max (x , axis = [2 , 3 ])
522
+
523
+
524
+ class _GlobalPooling3D (Layer ):
525
+
526
+ def __init__ (self , dim_ordering = 'default' , ** kwargs ):
527
+ super (_GlobalPooling3D , self ).__init__ (** kwargs )
528
+ if dim_ordering == 'default' :
529
+ dim_ordering = K .image_dim_ordering ()
530
+ self .dim_ordering = dim_ordering
531
+ self .input_spec = [InputSpec (ndim = 5 )]
532
+
533
+ def get_output_shape_for (self , input_shape ):
534
+ if self .dim_ordering == 'tf' :
535
+ return (input_shape [0 ], input_shape [4 ])
536
+ else :
537
+ return (input_shape [0 ], input_shape [1 ])
538
+
539
+ def call (self , x , mask = None ):
540
+ raise NotImplementedError
541
+
542
+ def get_config (self ):
543
+ config = {'dim_ordering' : self .dim_ordering }
544
+ base_config = super (_GlobalPooling3D , self ).get_config ()
545
+ return dict (list (base_config .items ()) + list (config .items ()))
546
+
547
+
548
+ class GlobalAveragePooling3D (_GlobalPooling3D ):
549
+ '''Global Average pooling operation for 3D data.
550
+
551
+ # Arguments
552
+ dim_ordering: 'th' or 'tf'. In 'th' mode, the channels dimension
553
+ (the depth) is at index 1, in 'tf' mode is it at index 4.
554
+ It defaults to the `image_dim_ordering` value found in your
555
+ Keras config file at `~/.keras/keras.json`.
556
+ If you never set it, then it will be "tf".
557
+
558
+ # Input shape
559
+ 5D tensor with shape:
560
+ `(samples, channels, len_pool_dim1, len_pool_dim2, len_pool_dim3)` if dim_ordering='th'
561
+ or 5D tensor with shape:
562
+ `(samples, len_pool_dim1, len_pool_dim2, len_pool_dim3, channels)` if dim_ordering='tf'.
563
+
564
+ # Output shape
565
+ 2D tensor with shape:
566
+ `(nb_samples, channels)`
567
+ '''
568
+
569
+ def call (self , x , mask = None ):
570
+ if self .dim_ordering == 'tf' :
571
+ return K .mean (x , axis = [1 , 2 , 3 ])
572
+ else :
573
+ return K .mean (x , axis = [2 , 3 , 4 ])
574
+
575
+
576
+ class GlobalMaxPooling3D (_GlobalPooling3D ):
577
+ '''Global Max pooling operation for 3D data.
578
+
579
+ # Arguments
580
+ dim_ordering: 'th' or 'tf'. In 'th' mode, the channels dimension
581
+ (the depth) is at index 1, in 'tf' mode is it at index 4.
582
+ It defaults to the `image_dim_ordering` value found in your
583
+ Keras config file at `~/.keras/keras.json`.
584
+ If you never set it, then it will be "tf".
585
+
586
+ # Input shape
587
+ 5D tensor with shape:
588
+ `(samples, channels, len_pool_dim1, len_pool_dim2, len_pool_dim3)` if dim_ordering='th'
589
+ or 5D tensor with shape:
590
+ `(samples, len_pool_dim1, len_pool_dim2, len_pool_dim3, channels)` if dim_ordering='tf'.
591
+
592
+ # Output shape
593
+ 2D tensor with shape:
594
+ `(nb_samples, channels)`
595
+ '''
596
+
597
+ def call (self , x , mask = None ):
598
+ if self .dim_ordering == 'tf' :
599
+ return K .max (x , axis = [1 , 2 , 3 ])
600
+ else :
601
+ return K .max (x , axis = [2 , 3 , 4 ])
0 commit comments