Skip to main content

Memory Wrap: an extension for image classification models

Project description

Description

Memory Wrap is an extension to image classification models that improves both data-efficiency and model interpretability, adopting a sparse content-attention mechanism between the input and some memories of past training samples.

Installation

This is a PyTorch implementation of Memory Wrap. To install Memory Wrap run the following command:

pip install memorywrap

The library contains two main classes:

  • MemoryWrapLayer: it is the Memory Wrap variant described in the paper that uses both the input encoding and the memory encoding to compute the output;
  • BaselineMemory: it is the baseline that uses only the memory encoding to compute the output.

Usage

Instantiate the layer

memorywrap = MemoryWrapLayer(encoder_dim,output_dim,return_weights=False)

or

memorywrap = BaselineMemory(encoder_dim,output_dim)

where:

  • encoder_dim is the output dimension of the last layer of the encoder
  • output_dim is the desired output dimensione. In the case of the paper output_dim is equal to the number of classes;
  • return_weights is a flag telling to the layer if it has to return the sparse content weights.

Forward call

Add the forward call to your forward function.

output_memorywrap = memorywrap(input_encoding,memory_encoding)

where input_encoding and memory_encoding are the outputs of the the encoder of rispectively the current input and the memory set.
If you have set the flag return_weights to True, then output_memorywrap is a Tuple where the first element is the output and the second one are the content weights associated to each element in the memory_encoding.

Additional information

Here you can find link to additional source of information about Memory Wrap:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memorywrap-1.0.3.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

memorywrap-1.0.3-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file memorywrap-1.0.3.tar.gz.

File metadata

  • Download URL: memorywrap-1.0.3.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.8

File hashes

Hashes for memorywrap-1.0.3.tar.gz
Algorithm Hash digest
SHA256 3779f3e7165ce0a41c1edfba26ef4cdd322480dce23aeffbc2627c1df1aa46f3
MD5 64720ba3dfc5ee4b17aaafe2cf886c3c
BLAKE2b-256 82ca4eb15ecca6da0c4dcce159d994b2d9506f05546eea5446f2525ea0ea4ef8

See more details on using hashes here.

File details

Details for the file memorywrap-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: memorywrap-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.8

File hashes

Hashes for memorywrap-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0d4ee881f4e481057309b7745da9cb297dd4a22ea17bcac58088c1965a8c6dee
MD5 3ec66a23c62051d1b6756232fa20542e
BLAKE2b-256 ccada9eb665b01c89395eb421aeb189d75b31f5bdf3ea4c4c8403ce9bb49d544

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page