keras-io/Image-Classification-using-EANet
2134
1---2language:3- en4library_name: tf-keras5license: apache-2.06metrics:7- accuracy8tags:9- tensorflow10- image-classification11libraries: TensorBoard12model-index:13- name: Image-Classification-using-EANet14 results:15 - task:16 type: Image-Classification-using-EANet17 dataset:18 name: CIFAR10019 type: Image20 metrics:21 - type: accuracy22 value: []23 - type: validation loss24 value: []25---26 27## Image-Classification-using-EANet with Keras28 29This repo contains the model and the notebook on [Image Classification using EANet with Keras](https://keras.io/examples/vision/eanet/).30 31Credits: [ZhiYong Chang](https://github.com/czy00000) - Original Author32 33HF Contribution: [Drishti Sharma](https://huggingface.co/spaces/DrishtiSharma) 34 35 36### Introduction37 38This example implements the EANet model for image classification, and demonstrates it on the [CIFAR-100](https://huggingface.co/datasets/cifar100) dataset. EANet introduces a novel attention mechanism named external attention, based on two external, small, learnable, and shared memories, which can be implemented easily by simply using two cascaded linear layers and two normalization layers. It conveniently replaces self-attention as used in existing architectures. External attention has linear complexity, as it only implicitly considers the correlations between all samples. 39 40 41### Implemention of the EANet model42 43The EANet model leverages external attention. The computational complexity of traditional self attention is O(d * N ** 2), where d is the embedding size, and N is the number of patch. The authors find that most pixels are closely related to just a few other pixels, and an N-to-N attention matrix may be redundant. So, they propose as an alternative an external attention module where the computational complexity of external attention is O(d * S * N). As d and S are hyper-parameters, the proposed algorithm is linear in the number of pixels. In fact, this is equivalent to a drop patch operation, because a lot of information contained in a patch in an image is redundant and unimportant.