Git Product home page Git Product logo

deepcabac's Introduction

DeepCABAC for Python

This code implements the encoding and decoding process of DeepCABAC as described in (insert paper link).

Python binding of the C++ Implementation of deepCABAC using pybind11.

How to install

Tested on

  • Ubuntu 18.04, gcc 7.4
  • Windows 7, Visual Studio 2019
  • Windows 10, Visual Studio 2019
  • OS X Mojave 10.14, Xcode 10.2.1

You need python >= 3.6 with working pip:

From the root of this repository, run

pip install .

to install deepCABAC extension.

Examples

Encoding Pytorch model weights

import deepCABAC
import torchvision.models as models

model = models.resnet50(pretrained=True)
encoder = deepCABAC.Encoder()

interv = 0.1
stepsize = 15
_lambda = 0.

for name, param in model.state_dict().items():
    if '.weight' in name:
        encoder.encodeWeightsRD( weights, interv, stepsize, _lambda )
    else:
        encoder.encodeWeightsRD( weights, interv, stepsize + 4, _lambda )
    
stream = encoder.finish()
with open('weights.bin', 'wb') as f:
    f.write(stream)

Decoding Pytorch model weights

import deepCABAC
import torchvision.models as models

model = models.resnet50(pretrained=False)
decoder = deepCABAC.Decoder()

with open('weights.bin', 'rb') as f:
    stream = f.read()

decoder.getStream(stream)
state_dict = model.state_dict()
for name in state_dict.keys():
    state_dict[name] = torch.tensor(decA.decodeWeights())
decoder.finish()

model.load_state_dict(state_dict)

# evaluate(model)

Debugging

If you want to debug the module, on Ubuntu with gdb you can use:

CFLAGS='-Wall -O0 -g' pip install .

Find simple usage example in ./Tests.

deepcabac's People

Contributors

hellge avatar

Watchers

 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.