Skip to main content

Full Network Embedding implementation in pytorch.

Project description

Full Network Embedding

Simple code for generating the Full-Network Embedding (FNE) of a dataset using a pre-trained convolutional neural network (CNN) model, as defined in [1].

The Full-Network Embedding is composed by two main steps. First, it extracts the neural activations of a given input using all convolutional or dense layers of the network, thus integrating information at different levels of abstraction (depending on layer depth) and combining different types of neural representations (convolutional and dense layers). Secondly, the FNE contextualizes and leverages this information through a three-valued discretisation step. While the contextualization provides a problem-specific characterisation of the data, the discretization reduces noise and regularises the embedding space. Significantly, this may also reduce the computational cost of processing the resultant representations through methods like SVMs. The FNE is shown to outperform single layer embeddings on several image classification tasks, while also being more robust to the choice of the pre-trained model used as the transfer source. See [1] for more details. The FNE can also be integrated into many multimodal embedding schemes, providing a boost in performance [2].

All FNE functionalities are coded within the "full_network_embedding" method, which extracts and postprocesses the activations of a list of images, as these are feed-forwarded through a given pre-trained CNN. The code contains an example of use, loading a pre-trained model provided by the tensorflow.lucid package.

A straight-forward application of this code is image classification, often through the training of a linear SVM [1]. The FNE is particularly competitive in contexts with little data availability, working with as little as 10 examples per class. The FNE is also robust to dissimilarities between the pre-trained task and the target task, making it apropriate for unusual or highly specific problems.

FNE Diagram

Usage

Prerequisits

This code can be used either in Python3 (up to 1.1.0). Required packages are numpy, tensorflow, opencv-python, and lucid (only needed for loading example model).

Example

In order to run the example case:

cd fne/
python fne.py

FNE function

If you want to use FNE implementation:


Positional arguments:

  • model (tf.GraphDef): Serialized TensorFlow protocol buffer (GraphDef) containing the pre-trained model graph from where to extract the FNE. You can get corresponding tf.GraphDef from default Graph using tf.Graph.as_graph_def.
  • image_paths (list(str)): List of images to generate the FNE for.
  • batch_size (int): Number of images to be concurrently computed on the same batch.
  • input_tensor (str): Name of tensor from model where the input is fed to.
  • target_tensors (list(str)): List of tensor names from model to extract features from.
  • input_reshape (tuple): A tuple containing the desired shape (height, width) used to resize the image.

Optional arguments:

  • stats (2D ndarray): Array of feature-wise means and stddevs for standardization.

References

If you find this code useful, please reference it as:

[1] D. Garcia-Gasulla et al., "An Out-of-the-box Full-Network Embedding for Convolutional Neural Networks," 2018 IEEE International Conference on Big Knowledge (ICBK), Singapore, 2018, pp. 168-175. doi: 10.1109/ICBK.2018.00030

@INPROCEEDINGS{8588789,
author={D. Garcia-Gasulla and A. Vilalta and F. Parés and E. Ayguadé and J. Labarta and U. Cortés and T. Suzumura},
booktitle={2018 IEEE International Conference on Big Knowledge (ICBK)},
title={An Out-of-the-box Full-Network Embedding for Convolutional Neural Networks},
year={2018},
pages={168-175},
keywords={Feature extraction;Training;Computational modeling;Task analysis;Space exploration;Tuning;Transfer Learning, Feature Extraction, Embedding Spaces},
doi={10.1109/ICBK.2018.00030},
month={Nov},}

[2] Vilalta, Armand, et al. "Studying the impact of the Full-Network embedding on multimodal pipelines." Semantic Web Preprint: 1-15.

How to release a new version

Change the version in pyproject.toml following the next standard:

version = "MAJOR.MINOR.PATCH"
  • MAJOR version when you make incompatible API changes
  • MINOR version when you add functionality in a backwards-compatible manner, and
  • PATCH version when you make backwards-compatible bug fixes.
git commit -m  "RELEASE ..."
git tag -a "MAJOR.MINOR.PATCH"
git push origin <tag_name>

License

GNU General Public License v3.0

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

fne-1.1.1.tar.gz (108.2 kB view hashes)

Uploaded Source

Built Distribution

fne-1.1.1-py3-none-any.whl (29.8 kB view hashes)

Uploaded Python 3

Supported by

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