Code Monkey home page Code Monkey logo

tensorflow_cc's Introduction

tensorflow_cc

Build Status TF version

This repository makes possible the usage of the TensorFlow C++ library from the outside of the TensorFlow source code folders and without the use of the Bazel build system.

This repository contains two CMake projects. The tensorflow_cc project downloads, builds and installs the TensorFlow C++ library into the operating system and the example project demonstrates its simple usage.

Installation

1) Install requirements

Ubuntu 16.04+:
# On Ubuntu 16.04, add ubuntu-toolchain-r PPA (for g++-6)
# sudo apt-get install software-properties-common
# sudo add-apt-repository ppa:ubuntu-toolchain-r/test
# sudo apt-get update

sudo apt-get install build-essential curl git cmake unzip autoconf autogen libtool mlocate zlib1g-dev \
                     g++-6 python python3-numpy python3-dev python3-pip python3-wheel wget
sudo updatedb

If you require GPU support on Ubuntu, please also install Bazel, NVIDIA CUDA Toolkit, NVIDIA drivers, cuDNN, and libcupti-dev package. The tensorflow build script will automatically detect CUDA if it is installed in /opt/cuda or /usr/local/cuda directories.

Arch Linux:
sudo pacman -S base-devel cmake git unzip mlocate python python-numpy wget
sudo updatedb

For GPU support on Arch, also install the following:

sudo pacman -S gcc6 bazel cuda cudnn nvidia

2) Clone this repository

git clone https://github.com/FloopCZ/tensorflow_cc.git
cd tensorflow_cc

3) Build and install the library

There are two possible ways to build the TensorFlow C++ library:

  1. As a static library (default):
    • Faster to build.
    • Provides only basic functionality, just enough for inferring using an existing network (see contrib/makefile).
    • No GPU support.
  2. As a shared library:
    • Requires Bazel.
    • Slower to build.
    • Provides the full TensorFlow C++ API.
    • GPU support.
cd tensorflow_cc
mkdir build && cd build
# for static library only:
cmake ..
# for shared library only (requires Bazel):
# cmake -DTENSORFLOW_STATIC=OFF -DTENSORFLOW_SHARED=ON ..
make && sudo make install

4) (Optional) Free disk space

# cleanup bazel build directory
rm -rf ~/.cache
# remove the build folder
cd .. && rm -rf build

Usage

1) Write your C++ code:

// example.cpp

#include <tensorflow/core/platform/env.h>
#include <tensorflow/core/public/session.h>
#include <iostream>
using namespace std;
using namespace tensorflow;

int main()
{
    Session* session;
    Status status = NewSession(SessionOptions(), &session);
    if (!status.ok()) {
        cout << status.ToString() << "\n";
        return 1;
    }
    cout << "Session successfully created.\n";
}

2) Link TensorflowCC to your program using CMake

# CMakeLists.txt

find_package(TensorflowCC REQUIRED)
add_executable(example example.cpp)
# link the static Tensorflow library
target_link_libraries(example TensorflowCC::Static)
# link the shared Tensorflow library
# target_link_libraries(example TensorflowCC::Shared)

3) Build and run your program

mkdir build && cd build
cmake .. && make
./example 

If you are still unsure, consult the Dockerfiles for Ubuntu and Arch Linux.

tensorflow_cc's People

Contributors

floopcz avatar ahoereth avatar tano297 avatar daavoo avatar

Watchers

James Cloos 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.