lraspp.py 664 B

123456789101112131415161718
  1. import tensorflow as tf
  2. from tensorflow.keras.models import Sequential
  3. from tensorflow.keras.layers import Layer, Conv2D, BatchNormalization, ReLU, Activation
  4. class LRASPP(Layer):
  5. def __init__(self, out_channels: int):
  6. super().__init__()
  7. self.aspp1 = Sequential([
  8. Conv2D(out_channels, 1, use_bias=False),
  9. BatchNormalization(momentum=0.1, epsilon=1e-5),
  10. ReLU()
  11. ])
  12. self.aspp2 = Conv2D(out_channels, 1, use_bias=False, activation='sigmoid')
  13. def call(self, x):
  14. x1 = self.aspp1(x)
  15. x2 = self.aspp2(tf.reduce_mean(x, axis=[1, 2], keepdims=True))
  16. return x1 * x2