GithubHelp home page GithubHelp logo

rodrigovb96 / cpp-torch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tuotuoxp/cpp-torch

0.0 0.0 0.0 231 KB

cpp-torch is a C++ library, implemented as a wrapper around Torch libraries.

License: Apache License 2.0

CMake 2.39% C++ 91.85% Lua 4.25% Shell 0.92% Python 0.58%

cpp-torch's Introduction

DISCLAIMER

This is a modified version of

https://github.com/tuotuoxp/cpp-torch

Introduction

cpp-torch is a C++ library, implemented as a wrapper around torch C libraries (not lua libraries).

Using this library, you can:

  • load torch data tensor from .t7 file
  • load torch network model from .t7 file
  • feed data into model, perform forward pass and get output

All in C++, without touching lua.

Pretty handy when you want to deploy an off-the-shelf torch model.

Install

Check our install script for Linux

Get started

The following code loads a float tensor and a float network from file, and forwards the tensor into the network:

// read input tensor
std::ifstream fs_input("input_tensor.t7", std::ios::binary);
auto obj_input = cpptorch::load(fs_input);
auto input = cpptorch::read_tensor<float>(obj_input.get());     // load float tensor

// read network
std::ifstream fs_net("net.t7", std::ios::binary);
auto obj_net = cpptorch::load(fs_net);
auto net = cpptorch::read_net<float>(obj_net.get());          // load float network

// forward
auto output = net->forward(input);

// display
std::cout << input << std::endl;
std::cout << *net << std::endl;
std::cout << output << std::endl;

If tensor and network type is double, change the template type accordingly:

auto input = cpptorch::read_tensor<double>(obj_input.get());     // load double tensor
auto net = cpptorch::read_tensor<double>(obj_net.get());     // load double network

To use GPU, use read_cuda_tensor() function:

auto input = cpptorch::read_cuda_tensor(obj_input.get());     // load cuda tensor
auto net = cpptorch::read_cuda_net(obj_net.get());          // load cuda network

We also provides an example script to test the famous CMU OpenFace model. This example transfers a 3 * 96 * 96 face image(OpenCV Mat) into cpp-torch tensor, forwards it through the network, receives a 128 * 1 identity feature tensor, and print the result.

Progress

Currently, this library supports forward pass of

Check this list to see supported modules.

You are more than welcome to add new modules to cpp-torch. Please check our developer guide.

FAQ

-- How can I train my own model with this wrapper?

-- We don't support backward functions, so training is impossible. Use the original torch.

cpp-torch's People

Contributors

rodrigovb96 avatar tuotuoxp avatar twobranchdracaena avatar yytdfc 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.