├── .gitignore ├── CoordAttention.py ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | *.pyc 34 | core 35 | tags 36 | 37 | # ignore build folder 38 | [bB]uild 39 | saferm 40 | lesson_private 41 | -------------------------------------------------------------------------------- /CoordAttention.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #coding: utf-8 3 | 4 | import tensorflow as tf 5 | import tensorflow.contrib.slim as slim 6 | 7 | 8 | def CoordAtt(x, reduction = 32): 9 | 10 | def coord_act(x): 11 | tmpx = tf.nn.relu6(x+3) / 6 12 | x = x * tmpx 13 | return x 14 | 15 | x_shape = x.get_shape().as_list() 16 | [b, h, w, c] = x_shape 17 | x_h = slim.avg_pool2d(x, kernel_size = [1, w], stride = 1) 18 | x_w = slim.avg_pool2d(x, kernel_size = [h, 1], stride = 1) 19 | x_w = tf.transpose(x_w, [0, 2, 1, 3]) 20 | 21 | y = tf.concat([x_h, x_w], axis=1) 22 | mip = max(8, c // reduction) 23 | y = slim.conv2d(y, mip, (1, 1), stride=1, padding='VALID', normalizer_fn = slim.batch_norm, activation_fn=coord_act,scope='ca_conv1') 24 | 25 | x_h, x_w = tf.split(y, num_or_size_splits=2, axis=1) 26 | x_w = tf.transpose(x_w, [0, 2, 1, 3]) 27 | a_h = slim.conv2d(x_h, c, (1, 1), stride=1, padding='VALID', normalizer_fn = None, activation_fn=tf.nn.sigmoid,scope='ca_conv2') 28 | a_w = slim.conv2d(x_w, c, (1, 1), stride=1, padding='VALID', normalizer_fn = None, activation_fn=tf.nn.sigmoid,scope='ca_conv3') 29 | 30 | out = x * a_h * a_w 31 | 32 | 33 | return out 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Zhengtq 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
10 | 11 | 12 | # Table Of Contents 13 | 14 | * [Features](#features) 15 | 16 | * [Quick Start](#quick-start) 17 | 18 | * [Installation](#installation) 19 | 20 | * [Package Managers](#package-managers) 21 | 22 | * [Usage](#usage) 23 | 24 | * [Authors](#authors) 25 | 26 | * [License](#license) 27 | 28 | 29 | 30 | # Features 31 | 32 | * Easy To Use 33 | 34 | * Tensorflow 35 | * TF-Slim 36 | 37 | 38 | # Quick Start 39 | 40 | 41 | ```markdown 42 | from CoordAttention import CoordAtt 43 | x = CoordAtt(x) 44 | ``` 45 | 46 | 47 | # Installation 48 | 49 | Very simple 50 | 51 | 52 | ## Package Managers 53 | 54 | #### Just Clone 55 | 56 | ```bash 57 | git clone git@github.com:Zhengtq/CoordAttention_tensorflow.git 58 | ``` 59 | 60 | 61 | 62 | 63 | > Know Any Other Solutions Or Have Any More Ideas Kindly. Give A [Issue][issues] Or If Possible Submit A [Pull Request](https://github.com/Zhengtq/CoordAttention_tensorflow/pulls) 64 | 65 | 66 | # Authors 67 | 68 | |  | 69 | | :----------------------------------------------------------: | 70 | | [Github](https://github.com/Zhengtq) | 71 | | [Email](mailto:1553866519@qq.com) | 72 | 73 | 74 | # License 75 | ``` 76 | MIT License 77 | 78 | Copyright (c) 2021 Readme Template Authors 79 | 80 | Permission is hereby granted, free of charge, to any person obtaining a copy 81 | of this software and associated documentation files (the "Software"), to deal 82 | in the Software without restriction, including without limitation the rights 83 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 84 | copies of the Software, and to permit persons to whom the Software is 85 | furnished to do so, subject to the following conditions: 86 | 87 | The above copyright notice and this permission notice shall be included in all 88 | copies or substantial portions of the Software. 89 | 90 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 91 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 92 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 93 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 94 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 95 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 96 | SOFTWARE. 97 | ``` 98 | 99 | # Status 100 | 101 | This project is currently being maintained. And Will Be Maintained. If You Like This Project And Want This Project To Never Exhaust. Please Consider Donating. 102 | 103 | --------------------------------------------------------------------------------