No description, website, or topics provided.
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
diagrams Diagrams for NIPS publication Oct 27, 2018
jpeg2dct remove duplicate Aug 31, 2018
test add new license Jul 2, 2018
.gitignore Ignore all .so files Jul 2, 2018
.travis.yml add travis continuous integration Jul 2, 2018
LICENSE remove from LICENSE Jul 2, 2018
MANIFEST.in Implementation for NumPy and TF operations Jul 2, 2018
NOTICE update the date Jul 2, 2018
README.md Updated README Oct 26, 2018
setup.py add new license Jul 2, 2018

README.md

Faster Neural Networks Straight from JPEG: jpeg2dct subroutines

This repository contains source code useful for reproducing results presented in the paper Faster Neural Networks Straight from JPEG (ICLR workshop 2018):

@inproceedings{gueguen_2018_ICLR
  title={Faster Neural Networks Straight from JPEG},
  author={Lionel Gueguen and Alex Sergeev and Ben Kadlec and Rosanne Liu and Jason Yosinski},
  booktitle={International Conference on Learning Representations},
  year={2018}
}

jpeg2dct subroutines

The jpeg2dct library provides native Python functions and a TensorFlow Operators to read the Discrete Cosine Transform coefficients from image encoded in JPEG format. The I/O operation leverages standard JPEG libraries (libjpeg or libjpeg-turbo) to perform the Huffman decoding and obtain the DCT coefficients.

Usage

Read into numpy array

from jpeg2dct.numpy import load, loads


#read from a file
jpeg_file = '/<jpeg2dct dir>/test/data/DCT_16_16.jpg'
dct_y, dct_cb, dct_cr = load(jpeg_file)
print ("Y component DCT shape {} and type {}".format(dct_y.shape, dct_y.dtype))
print ("Cb component DCT shape {} and type {}".format(dct_cb.shape, dct_cb.dtype))
print ("Cr component DCT shape {} and type {}".format(dct_cr.shape, dct_cr.dtype))


#read from in memory buffer
with open(jpeg_file, 'rb') as src:
    buffer = src.read()
dct_y, dct_cb, dct_cr = loads(buffer)

Read into Tensorflow Op

import tensorflow as tf
from jpeg2dct.tensorflow import decode

jpeg_file = '/<jpeg2dct dir>/test/data/DCT_16_16.jpg'
with tf.Session() as sess:
    jpegbytes = tf.read_file(jpeg_file)
    dct_y_tf, dct_c_tf, dct_r_tf = decode(jpegbytes)
    print ("Y component DCT shape {} and type {}".format(dct_y_tf.eval().shape, dct_y_tf.dtype))

Installation

Requirements

  1. Numpy>=1.14.0
  2. libjpeg or libjpeg-turbo
  3. (Optional) Tensorflow>=1.5.0

Pip

pip install jpeg2dct

On macOS 10.13, with default Python, the compiler has troubles. In Conda, the following is unnecessary.

mv /usr/local/include /usr/local/include_old
brew reinstall llvm libjpeg
pip install jpeg2dct

From source

git clone https://github.com/uber-research/jpeg2dct.git
cd jpeg2dct
python setup.py install

On Mac run the following, before python setup.py ...

export MACOSX_DEPLOYMENT_TARGET=10.10
# or
conda install --channel https://conda.anaconda.org/anaconda clangxx_osx-64

Test the installation

python setup.py test
# or
python setup.py develop
pytest