You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

SimAM.py 829 B

2 years ago
1234567891011121314151617181920212223242526272829
  1. """
  2. MindSpore implementation of 'SimAM'
  3. Refer to "SimAM: A Simple, Parameter-Free Attention Module for Convolutional Neural Networks"
  4. """
  5. import mindspore as ms
  6. from mindspore import nn
  7. class SimAM(nn.Cell):
  8. """ SimAM """
  9. def __init__(self, e_lambda=1e-4):
  10. super().__init__()
  11. self.activation = nn.Sigmoid()
  12. self.e_lambda = e_lambda
  13. def construct(self, x):
  14. _, _, H, W = x.shape
  15. n = W * H - 1
  16. x_minus_mu_square = (x - x.mean(axis=(2, 3), keep_dims=True)).pow(2)
  17. y = x_minus_mu_square / (4 * x_minus_mu_square.sum(axis=(2, 3), keepdims=True) / n + self.e_lambda) + 0.5
  18. return x * self.activation(y)
  19. if __name__ == '__main__':
  20. dummy_input = ms.ops.randn(3, 64, 7, 7)
  21. model = SimAM(64)
  22. outputs = model(dummy_input)
  23. print(outputs.shape)

基于MindSpore的多模态股票价格预测系统研究 Informer,LSTM,RNN