I need to implement a minmax pooling layer. I have 4-dimensional tensor,(batch_size,height,width,activation_maps).
I want to implement a method where the number with the largest absolute value gets propagated to the next layer instead of max element being chosen.
I have attached an example to make thins clear.
I had an idea to execute maxpooling operation on input tensor x twice. One time on the original tensor and the second time after negating it. After that i can compare the values of both obtained results and choose largest absolute value. However, i am stucked. I have pasted the code below. Any further help will be great.
Thanks
class CustomMaxPooling(tf.keras.layers.Layer):
def __init__(self, pool_size,strides,padding,shape):
super(CustomMaxPooling, self).__init__()
self.pool_size =pool_size
self.strides=strides
self.padding = padding
self.shape = shape
def call(self, x):
positive = MaxPool2D(pool_size=self.pool_size,strides=self.strides, padding=self.padding,name =self.name)(x)
negative = MaxPool2D(pool_size=self.pool_size,strides=self.strides, padding=self.padding,name =self.name)(-x)
return
Just for the sake of testing:
X = tf.random.normal([4,4,4,3], dtype=tf.dtypes.float32, seed=None, name=None)
result = CustomMaxPooling(pool_size=(2, 2),strides=(1, 1),padding='valid',shape=X.shape)(X)
