• Stars
    star
    275
  • Rank 149,796 (Top 3 %)
  • Language CMake
  • License
    BSD 3-Clause "New...
  • Created over 11 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Torch-7 for Android

##########################################

Torch-7 for Android

########################################## Torch7 provides a Matlab-like environment for state-of-the-art machine learning algorithms. It is easy to use and provides a very efficient implementation, thanks to an easy and fast scripting language (Lua) and a underlying C implementation.

Modified to be compiled and used with Android

Features

  • Loading of lua packages from the apk directly.
  • This is done by writing a custom package.loader Reference: http://www.lua.org/manual/5.1/manual.html#pdf-package.loaders The loader is in torchandroid.cpp as loader_android
  • torchandroid.h and torchandroid.cpp give lots of helper functions to make life easier
    • Print function overriden to redirect to logcat (only handles strings for now)
    • Function to get apk assets as bytes (very useful)
  • Full support for ffi and shared libraries

torch.load now takes three additional modes: apkbinary32, apkbinary64, apkascii. One can store model files in the assets folder and use these modes to load them. If the model was saved on a 64-bit machine, use apkbinary64, if it was saved on a 32-bit machine, use apkbinary32.

Requirements

For CUDA-enabled version: NVIDIA CodeWorks for Android: https://developer.nvidia.com/codeworks-android.

  • NOTE: CodeWorks 1R5 does not have CUDA! You need to install 1R5 and then CUDA from 1R4.

For CPU-only version : Android NDK (13b) and Android SDK

  • NOTE (Nov 2016): Android NDK v13b is required for NEON, even if building with CodeWorks and CUDA.
  • This is due to some NDK bugs fixed in v13b - CodeWorks has 12b. NDK will only be used to build Lua JIT.
    1. Get it here: https://dl.google.com/android/repository/android-ndk-r13b-linux-x86_64.zip.
    2. Extract it under ~/NVPACK, next to 12b that comes with CodeWorks.
    3. Change NVPACK environvent to point to that NDK (see sample in ./.bashrc-android)

Samples

  • Three sample projects has been provided in demos/
  • demos/android-demo/jni/torchdemo.cpp is a simple use-case
  • demos/android-demo/assets/main.lua is the file that is run
  • demos/android-demo-cifar showcases classifying Camera inputs (or images from gallery) into one of 10 CIFAR-10 categories.
  • Vinayak Ghokale from e-lab Purdue (https://github.com/e-lab) contributed a face detector demo, which showcases a fuller use-case (demos/facedetector_e-lab ).

Building Torch Libraries and Java class.

If on ubuntu, install the following packages: sudo apt-get install libx32gcc-4.8-dev libc6-dev-i386 Default is to build with CUDA - so make sure you installed NVIDIA CodeWorks for Android and its nvcc is in your PATH. Otherwise, set WITH_CUDA=OFF in build.sh

  1. git submodule update --init --recursive
  2. Optionally, open build.sh and modify ARCH (to match your device architecture) and WITH_CUDA variables.
  3. run build script: 3 ./build.sh

You can use torch in your android apps. The relevant directories are

  • install/include - include directories
  • install/libs/$APP_ABI - static libs cross-compiled for your APP_ABI
  • install/share/lua - lua files

Building Android Demo App

  1. Build Torch-Android atleast once using the steps above.
  2. [Optional] Connect your android phone in debugging mode, to automatically install the apk.
  3. Change directory into demos/android-demo folder.
  4. Run build script. $ ./build.sh
  5. Run the app TorchDemo on your phone.

More Repositories

1

ganhacks

starter from "How to Train a GAN?" at NIPS2016
10,908
star
2

convnet-benchmarks

Easy benchmarking of all publicly accessible implementations of convnets
Python
2,675
star
3

dcgan.torch

A torch implementation of http://arxiv.org/abs/1511.06434
Lua
1,427
star
4

cvpr2015

Jupyter Notebook
869
star
5

cudnn.torch

Torch-7 FFI bindings for NVIDIA CuDNN
Lua
408
star
6

imagenet-multiGPU.torch

an imagenet example in torch.
Lua
395
star
7

talks

Jupyter Notebook
261
star
8

net2net.torch

Implementation of http://arxiv.org/abs/1511.05641 that lets one build a larger net starting from a smaller one.
Lua
159
star
9

imagenetloader.torch

some old code that i wrote, might be useful to others
Shell
88
star
10

deepmind-atari

Lua
67
star
11

lua---audio

Module for torch to support audio i/o as well as do common operations like dFFT, generate spectrograms etc.
C
67
star
12

inception.torch

Torch port of https://github.com/google/inception
Jupyter Notebook
66
star
13

torch-signal

Signal processing toolbox for Torch 7
Lua
48
star
14

cuda-convnet2.torch

Torch7 bindings for cuda-convnet2 kernels!
Cuda
40
star
15

matio-ffi.torch

A LuaJIT FFI interface to MATIO and simple bindings for torch
Lua
39
star
16

galaxyzoo

Entry for GalaxyZoo challenge
Lua
35
star
17

eyescream

JavaScript
35
star
18

nextml

35
star
19

examplepackage.torch

A hello-world for torch packages
CMake
23
star
20

sunfish.lua

tiny and basic chess engine for lua. Port of https://github.com/thomasahle/sunfish
Lua
20
star
21

kaggle_retinopathy_starter.torch

A starter kit in Torch for Kaggle Diabetic Retinopathy Detection
Lua
19
star
22

neon.torch

Nervana Neon kernels in Torch
Lua
18
star
23

torch-ship-binaries

A page describing how to ship torch binaries without sharing the source code of your scripts.
17
star
24

nnjs

JavaScript
16
star
25

deep_gitstats

Based on SciPy's normalized git stats, adapted for Deep Learning frameworks
Jupyter Notebook
16
star
26

cifar.torch

Lua
15
star
27

torch.js

nodejs bindings for libTH (tensor library that powers torch). for fun!
JavaScript
14
star
28

fakecuda

A convenient package for the lazy torch programmer to leave all your :cuda() calls as-is when running on CPU
Lua
14
star
29

rgbd_streamer

Python
12
star
30

mscoco.torch

Lua
11
star
31

torch-docker

Dockerfile to create an image for Torch7
Shell
10
star
32

NeuralNetworks.jl

hacking torch-like neural networks in Julia
Julia
10
star
33

torch-cheatsheet

A quick page for everything Torch
9
star
34

fftw3-ffi

A LuaJIT FFI interface to FFTW3
Lua
5
star
35

thnb

iTorch notebooks
4
star
36

lzmqstatic

Self-contained statically linked zeromq bindings for lua
C++
3
star
37

nvblog_rnnlstm

HTML
3
star
38

fairmark1

Lua
2
star
39

cunnsparse

Lua
2
star
40

yasa

Yet another Sentiment analyzer. This one uses convolution networks.
Lua
1
star
41

cunnCUDA

some depreceated, ugly and old modules
Cuda
1
star
42

housenumbers_classifier

An attempt on the Stanford Housenumbers dataset
Lua
1
star
43

Bar__ZEbulLonX22L.torch

wtf
1
star