Git Product home page Git Product logo

sparse-embed's Introduction

sparse-embed

Code for paper 'Minimizing FLOPs to Learn Efficient Sparse Representations' published at ICLR 2020 https://openreview.net/forum?id=SygpC6Ntvr

The main training and testing code is based on TensorFlow, and multi-GPU training is achieved using Horovod.

Requirements

The code has been tested to work with the following versions:

  • python 3.6
  • tensorflow-gpu 1.12
  • horovod 0.16

Datasets

Training data: The MS1M dataset for training was downloaded from the InsightFace repository. The dataset is aligned by authors of InsightFace using MTCNN.

The downloaded dataset is in MXnet format, and must be converted to JPEG images using python preprocessing/msceleb_to_jpeg.py <dataset_directory>. The extracted images will be stored in dataset_directory/images.

Testing data: The MegaFace and FaceScrub datasets can been downloaded from the official MegaFace challenge website. We used MTCNN to align the images.

The CIFAR-100 training and testing data can be downloaded from https://www.cs.toronto.edu/~kriz/cifar.html.

Preprocessing

All the datasets must be converted to TFRecords format for fast and multi-threaded pre-fetching of data. The scripts in preprocessing/*.sh can be used to convert to TFRecords format. The output directories can be modified within the code. The preprocessing code has been taken from the official TF models github.

Training

The pipeline to read images (input_pipeline.py, imagenet_preprocessing.py) during training has also been taken from the TF models github, and the main models have been implemented using the tf.Estimator framework. Sample training scripts can be found in run_scripts/face and run_scripts/cifar. The directories for the trained models and the dataset directories can be specified withing the shell scripts.

Evaluation

For evaluation, we have to first compute the trained embeddings for FaceScrub and MegaFace. Example scripts using get_embeddings_reranking.py are given in run_scripts/get_embeddings. The computed embeddings will be saved as HDF5 files in a directory named embeddings_reranking. The MegaFace and FaceScrub embeddings start with the prefixes megaface and facescrub respectively. For instance, the MegaFace embeddings corresponding to the model sparse_mobilenet_fl_run_1 will be saved as megaface_sparse_mobilenet_fl_run_1.hdf5.

The accuracy and retrieval times are evaluated independently as described below.

Accuracy: Accuracy can be evaluated as

python evaluate_mfacenet_reranking.py --dense_suffix=dense_mobilenet_512_run_1.hdf5 --sparse_suffix=sparse_mobilenet_fl_run_1.hdf5 --threshold=0.25 --rerank_topk=1000

dense_suffix and sparse_suffix parameters denote the corresponding and dense and sparse embeddings to use. The dense embeddings are used for re-ranking as described in the paper. The threshold and rerank_topk parameters denote the filtering threshold and the number of top candidates to rerank, respectively. Refer to the paper for a more detailed description of these parameters.

Retrieval Time: For measuring the time, a more efficient C++ script is used. The HDF5 files must be converted to binary files before they can be read by the script. mobilefacenet_to_bin.sh and resnet_to_bin.sh provide examples to convert the HDF5 files to binary format and saved in the directory embedding_bin. The retrieval time can be measured using search/search.cpp. The makefile search/Makefile provides a sample flow to compile the script and measure the time retrieval time in ms. The runmegaface command measures the time using MegaFace distractors and held-out MegaFace queries. The runfacescrub command on the other hand uses MegaFace distractors and FaceScrub queries.

sparse-embed's People

Contributors

biswajitsc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

kiminh gyume2021

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.