Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/titu1994/keras-non-local-nets
Keras implementation of Non-local Neural Networks
https://github.com/titu1994/keras-non-local-nets
convolutional-neural-networks keras neural-network non-local
Last synced: 6 days ago
JSON representation
Keras implementation of Non-local Neural Networks
- Host: GitHub
- URL: https://github.com/titu1994/keras-non-local-nets
- Owner: titu1994
- License: mit
- Created: 2017-11-23T05:04:13.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-13T05:00:38.000Z (9 months ago)
- Last Synced: 2025-01-19T21:11:43.892Z (14 days ago)
- Topics: convolutional-neural-networks, keras, neural-network, non-local
- Language: Python
- Size: 267 KB
- Stars: 290
- Watchers: 17
- Forks: 100
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Keras Non-Local Neural Networks
Keras implementation of Non-local blocks from [[1]](https://arxiv.org/abs/1711.07971).- Support for `"Gaussian"`, `"Embedded Gaussian"` and `"Dot"` instantiations of the Non-Local block.
- Support for variable shielded computation mode (reduces computation by N**2 x, where N is default to 2)
- Support for `"Concatenation"` instantiation will be supported when authors release their code.# Usage Templates
The script `non_local.py` contains the `NonLocalBlock` instance which takes in an input tensor and wraps a non-local block around it.
```python
from non_local import NonLocalBlock
from tensorflow.keras.layers import Input, Conv1D, Conv2D, Conv3Dip = Input(shape=(...)) # input tensor with an "N" rank order of 3, 4 or 5
x = ConvND(...) # convolution operation with aforementioned rank
...
non_local_block = NonLocalBlock(intermediate_dim=None, compression=2, mode='embedded', add_residual=True)
x = non_local_block(x)
...
```The script `non_local_layerstyle.py` contains the `NonLocalBlock` **layer** which takes in an input tensor and wraps a non-local block around it. Made to facilitate the neural network builder using the Sequential method.
```python
from non_local_layerstyle import NonLocalBlock
from tensorflow.keras.layers import Input, Conv1D, Conv2D, Conv3D# Define the input shape
input_shape = (...) # shape of input tensormodel = Sequential()
model.add(ConvND(...)) # convolution operation with an "N" rank order of 3, 4 or 5
...
model.add(NonLocalBlock(intermediate_dim=None, compression=2, mode='embedded', add_residual=True))
...
```# Basic block
From [[1]](https://arxiv.org/abs/1711.07971), a basic Non-Local block with the Embedded Gaussian instantiation has the below logic:1. Xiaolong Wang, Ross Girshick, Abhinav Gupta, Kaiming He. "Non-local Neural Networks." arXiv:1711.07971 [cs.CV], 21 Nov 2017. [Link](https://arxiv.org/abs/1711.07971)