Giter Site home page Giter Site logo

jpeg2dct's Introduction

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

jpeg2dct's People

Contributors

yosinski avatar

Watchers

 avatar  avatar

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.