7/19/2015

Setup Jetson TK1

About Jetson K1
  Jetson TK1 is NVIDIA's embedded Linux development platform featuring a Tegra K1 SOC (CPU+GPU+ISP in a single chip).


Flashing Jetson TK1 with the latest OS(Linux For Tegra) images

Step1 : Download Jetson TK1 Development Pack (JetPack TK1) from the bellow link:

Step2 : Execute and install JetPack on your PC that is running Linux. It will try to flash image and install some components.
$ chmod +x JetPackTK1-1.2-cuda6.5-linux-x64.run
$ ./JetPackTK1-1.2-cuda6.5-linux-x64.run


















Step 3 : When flashing the device, need to let Jetson to enter to recover mode. How to enter Recover mode:

(1) Turn off Jetson TK1 and connect the Micro-USB plug on the USB cable.

(2) Press "Force Recovery" Button, press "POWER" Button, release POWER Button and release Force Recovery button.

(3) In recovery mode, you cannot login to Jetson TK1. If Jetson TK1 in recovery Mode and it is connected to host PC, "lsusb" command lists it with ID 0955:7140 in host PC.
$lsusb 
Bus 003 Device 006: ID 0955:7140 NVidia Corp

Step4 : After flashing device successfully, enter IP of Jetson, username, and password.
















IP Address : Get the IP from Jetson board via $ifconfig
username: ubuntu
password: ubuntu

Run CUDA samples installed from Jetpack on Jetson

 After installing successfully, reboot Jetson. If you know the IP of Jetson board, you could also connect it via remote access.
$ /home/ubuntu/GameWorksOpencGLSamples/samples/bin/linux-arm32
















6/30/2015

BLAS - ATLAS openBLAS and MKL installation on Ubuntu

BLAS (Basic Linear Algebra Subprograms) 

It is a specification that prescribes a set of low-level routines for performing common linear algebra operations.

There are a lot of implements of BLAS:

  • Accelerate : Apple's framework for Mac OS X and iOS, which includes tuned versions of BLAS
  • ACML : The AMD Core Math Library, supporting the AMD Athlon and Opteron CPUs under Linux and Windows.
  • ATLAS : Automatically Tuned Linear Algebra Software, an open source implementation of BLAS APIs for C and Fortran.
  • BLIS : BLAS-like Library Instantiation Software framework for rapid instantiation.
  • cuBLAS : Optimized BLAS for NVIDIA based GPU cards.
  • clBLAS : An OpenCL implemenation of BLAS.
  • Intel MKL : The Intel Math Kernel Library, supporting x86 32-bits and 64-bits. Includes optimizations for Intel Pentium, Core and Intel   Xeon CPUs and Intel Xeon Phi; support for Linux, Windows and Mac OS X.
  • etc..

MKL installation 

Step1: Go to the bellow links and register for Parallel Studio XE Cluster Edition. You will receive an email containing install and download instructions.
https://software.intel.com/en-us/intel-education-offerings

Step2: 

  $ tar zxvf parallel_studio_xe_2015_update3.tgz
  $ chmod a+x parallel_studio_xe_2015_update3 -R
  $ cd parallel_studio_xe_2015_update3
  $ sudo ./install_GUI.sh
And then enter the serial keys as follow figure

Step3:
Extend default lib search path for MKL in ubuntu. Do not need to export LD_LIBRARY_PATH
Create intel_mkl.conf, and edit it.
  $ cd /etc/ld.so.conf.d
  $ sudo vi intel_mkl.conf
Paste the bellows:
  /opt/intel/lib/intel64
  /opt/intel/mkl/lib/intel64
  $ sudo ldconfig -v

The faster way to setup MKL:
Download MKL libraray from 
https://drive.google.com/file/d/0Bz2RXKLpvFgITU16YUs1TmNGcDA/view?usp=sharing
$ tar -xf intel_mkl.tar
$ sudo mv intel_mkl /opt/intel 
$ export LD_LIBRARY_PATH=/opt/intel/mkl/lib/intel64:/opt/intel/lib/intel64:$LD_LIBRARY_PATH

ATLAS installation

  $ sudo apt-get install libatlas-base-dev


OpenBLAS installation

  $ sudo apt-get install libopenblas-dev





6/15/2015

C/C++ gflags and glog

Install gflags and glog


$ sudo apt-get install libgflags-dev libgoogle-glog-dev

gflag Source code on GitHub: https://github.com/gflags/gflags
glog Source code on GitHub: https://github.com/google/glog

gflag sample code

===============================================
// Test.cpp
#include <iostream>
#include <gflags/gflags.h> // #include <google/gflags.h>
using namespace std;

DEFINE_bool(big_menu, true, "Include 'advanced' options in the menu listing");
DEFINE_string(languages, "english,french,german", "comma-separated list of languages to offer in the 'lang' menu");


int main(int argc, char** agrv)
{
    ::google::ParseCommandLineFlags(&argc, &agrv, true);
    std::cout<< "FLAGS_big_menu : " << FLAGS_big_menu << "\n";
    return 0;
}

$ g++ -o test Test.cpp -I /usr/include/gflags -L /usr/lib/x86_64-linux-gnu -lgflags
$ ./Test  --big_menu=false
Output:
FLAGS_big_menu : 0

gflag Defining Flags In Program

Defining a flag is easy: just use the appropriate macro for the type you want the flag to be
DEFINE_bool(big_menu, true, "Include 'advanced' options in the menu listing");
DEFINE_string(languages, "english,french,german",
                 "comma-separated list of languages to offer in the 'lang' menu");
DEFINE_bool defines a boolean flag. Here are the types supported:
DEFINE_bool: boolean
DEFINE_int32: 32-bit integer
DEFINE_int64: 64-bit integer
DEFINE_uint64: unsigned 64-bit integer
DEFINE_double: double
DEFINE_string: C++ string

gflag Setting Flags on the Command Line

app_containing_foo --languages="chinese,japanese,korean"
app_containing_foo -languages="chinese,japanese,korean"
app_containing_foo --languages "chinese,japanese,korean"
app_containing_foo -languages "chinese,japanese,korean"
For boolean flags, the possibilities are slightly different:
app_containing_foo --big_menu
app_containing_foo --nobig_menu
app_containing_foo --big_menu=true
app_containing_foo --big_menu=false

glog sample code

=============================================
#include <glog/logging.h>
int main(int argc, char** argv) {
    FLAGS_alsologtostderr = 1; // It will dump to console
    google::InitGoogleLogging("test");


    LOG(INFO) << "Dump log test";
    return 0;
}
Output:
I0825 14:45:06.432374 22528 objectdection.cpp:15] Dump log test

Miniglog

If you would like to use glog for cross-platform like Android, you can use miniglog as bellows because glog didn't support Android NDK.

https://github.com/tzutalin/miniglog

Ref:

https://google-gflags.googlecode.com/svn/trunk/doc/gflags.html#intro

6/10/2015

Integrate Caffe into ROS

Purpose:

Integrate Caffe into ROS to do image classification.

Please go to my Github, there are more details:



6/03/2015

Setup Caffe from scratch

Introduction

Caffe is a deep learning framework made with expression, speed, and modularity in mind. It is developed by the Berkeley Vision and Learning Center (BVLC) and by community contributors.

Installation on Ubuntu 12.04 / 14.04

Use the script to install Caffe's requirements 
$ git clone https://gist.github.com/tzutalin/b24937905a2480da1723 
$ sh b24937905a2480da1723/installCaffeDep.sh

If you would like to install Caffe's requirement manually or install CUDA depedencies, please refer to http://caffe.berkeleyvision.org/install_apt.html

Get Caffe source and compile it

Clone the source
$ git clone https://github.com/BVLC/caffe.git

After cloning, confing Makefile.config for Makefile
$ cp Makefile.config.example Makefile.config
$ vi Makefile.config
For CPU-only Caffe, uncomment CPU_ONLY := 1 in Makefile.config.

Start compiling
$ make -j 8 all ; make -j 8 test ; make -j 8 runtest ; make pycaffe ; make distribute 
My Makefile.config's screenshot is as bellow. I uncomment CPU_ONLY := 1



Run and test Caffe

Test whether caffe can run or not, use benchmarking cmd as bellos 
$ cd caffe 
$ build/tools/caffe time --model=models/bvlc_alexnet/deploy.prototxt

Run Caffe python
The search path can be manipulated from within a Python program as the variable sys.path.
$ echo PYTHONPATH=[/to/your/path]/caffe/python/:$PYTHONPATH > ~/.bashrc

Try to run classifiy_test.py
$ cd [/to/your/path]/caffe/example 
$ git clone https://gist.github.com/912d1774d96266c4e76b.git 
$ python classify_test.py

If using default python(Python 2.7.6), might need the following dependencies 
$ sudo apt-get install python-scipy python-skimage libqt4-core libqt4-gui libqt4-dev libzmq-dev ; sudo pip install -U scikit-image; sudo pip install pyzmq; sudo pip install protobuf; sudo pip install pygments 


References

Install Intel MKL and other BLAS for Caffe
http://tzutalin.blogspot.tw/2015/06/blas-atlas-openblas-and-mkl.html
Using Caffe with Eclipse
http://tzutalin.blogspot.tw/2015/05/caffe-on-ubuntu-eclipse-cc.html
Manual Install Caffe
http://caffe.berkeleyvision.org/install_apt.html
Instant way to use Caffe
http://nbviewer.ipython.org/github/BVLC/caffe/blob/master/examples/00-classification.ipynb

5/31/2015

Setup Opengrok and tomcat on Ubuntu

To install the tomcat 7 you need to run:

  $ sudo apt-get install default-jdk tomcat7
  $ cd /usr/share/tomcat7/bin/
  $ ./catalina.sh

Then edit your ~/.bashrc and include using the directory pointed by CATALINA_BASE include the following var:

  export CATALINA_HOME=/usr/share/tomcat7/
  export OPENGROK_TOMCAT_BASE=$CATALINA_HOME
Run the tomcat and check if it is working:

$ . /etc/init.d/tomcat7
Open web address: http://localhost:8080/
Result on your browser:

Install OpenGrok
First, you need to install the exuberant C tags

$ sudo apt-get install exuberant-ctags openjdk-7-jdk
Download Opengrok binary from the bellow link:
http://opengrok.github.io/OpenGrok/
After download and extract it (E.g. I put it under /home/darrenl/tools/opengrok-0.12.5):

$ tar -zxvf opengrok-0.12.1.5.tar.gz
Second, create a folder and soft link to your code in order to generate index
  • $ cd ~ ; mkdir local_src ; cd local_src/ ; mkdir data src ; cd src/ $ ln -s ~/code/base/mir/ mir
My case (Create soft links from ~/development/android_core, ~/development/caffe, etc..):
  • $ ln -s ~/development/android_core ~/local_src/src/ $ ln -s ~/development/caffe ~/local_src/src/


Third, edit your ~/.bashrc again and paste the bellow text to add the path of OpenGrok binary to path environment var.
  • export OPENGROK_INSTANCE_BASE=~/local_src
  • export PATH=$PATH:~/tools/opengrok-0.12.1.5/bin

In the end, using OpenGrok to deploying, index the source in ~/local/src/
  • $ source ~/.bashrc $ cd ~/tools/opengrok-0.12.1.5/bin; sudo ./OpenGrok deploy $ OpenGrok index You can ingore some files by setting IGNORE_PATTERNS $ IGNORE_PATTERNS="-i *.git -i *.so -i *.apk -i d:.git" OpenGrok index
Run it on browser:
http://localhost:8080/source/

Besides, co-workers can see the code accessing the following addresses: <IP>:<PORT>/source or <hostname>:<PORT>/source

Update index

Whenever you create a link or source files in ~/local_src, you need to call $ OpenGrok index to update. And then refresh your browser screen again (F5).

Run $OpenGrok index on start up:

    $ cd ~/.config/autostart; vi opengrok.desktop
Paste the bellow content to opengrok.desktop and save it. Then, the computer will execute $ OpenGrok index when booting up.

[Desktop Entry]
Name=OpenGrok
GenericName=A fast and usable source code search and cross reference engine
Comment=A fast and usable source code search and cross reference engine
Exec=OpenGrok index
Terminal=false
Type=Application
StartupNotify=false


Note: If your OS is based on Linux, I strongly recommend that you should use Opengrok + Docker.
Please refer to https://hub.docker.com/r/tzutalin/opengrok/









5/13/2015

Using OpenCV with Eclipse

Step1:
Download and install Opencv and Eclipse C++


Step2:
Launch Eclipse and create a C++ project and select Linux GCC

Go to "Properties/C/C++ Build/Settings/"
Select GCC C++ Linker/ Libraries
Paste each of them to "Libraries (-l)"
  opencv_core 
  opencv_highgui 
  opencv_features2d 
  opencv_superres opencv_video 
  opencv_calib3d opencv_flann 
  opencv_videostab 
  opencv_calib3d  
  opencv_objdetect 
  opencv_imgproc

You should check whether your opencv libraray exists in ldconfig by $ sudo ldconfig -v | egrep -i opencv.  If it does not exist in ldconfig, you should paste the specified library path to "Library search path(-L)" as follow:
  /usr/local/lib

If your opencv verison >= 3.0, you can paste them and you have opencv contrib module
  opencv_imgcodecs
  opencv_imgproc
  opencv_highgui
  opencv_ml
  opencv_rgbd
  opencv_core
  opencv_stereo
  opencv_viz
  opencv_video
  opencv_features2d
  opencv_calib3d
  opencv_objdetect
  opencv_flann


Step3:
Select GCC C++ Compiler/includes. You should check whether the header of your opencv. It might be placed in  /usr/include or /usr/local/include. So you can use $ find -iname 'opencv' first. After you find it, paste it to " include path(-l) "
 /usr/include  or /usr/local/include




Step4:
Paste the snippet of the code:

#include <opencv2/opencv.hpp> 
using namespace cv;
int main(int argc, char** argv)
{
    Mat inputImage = imread(argv[1]);
    imshow("Input Image", inputImage);
    waitKey(0);
    return 0;
}

Step5:
Ctrl+B to build it
Run the program using terminal: e.g.: $ ./main ~/lena.jpg

If cannot find opencv_core.xx.so at runtime, please add the bellow cmds to .bashrc
export LD_LIBRARY_PATH="/lib:/usr/lib:/usr/local/lib"

Related Reference:


Caffe on Ubuntu / Eclipse C/C++

Purpose

After building Caffe framework, you can use Eclipse to develop and build your own application by including Caffe. Here is an article to teach you how to set up Eclipse for Caffe on Ubuntu14.04 and Eclipse C/C++.

Step 1: 
Open Eclipse, create a C++ project and select Linux GCC toolchains.

Step2:
Go to "properties->C/C++ Build->Settings-> GCC C++ Compiler ->includes" to set Caffe's include path. Add two paths to be included:
   to/your/path/caffe/include
   to/your/path/caffe/distribute/include

Notes: Whenever Caffe releases, need to run all build coomands


Step3:
  Go to "properties->C/C++ Build->Settings-> GCC C++ Linker ->Libraries" to set Caffe's libray path.

Add the bellows to "Library search path(-L)"
     to/your/path/caffe/build/lib

Paste it to " include path(-l) "
     caffe


Step4: (Optional)
Because I didn't use GPU to compute, so I set CPU_ONLY=1 for preprocessor.
 




Step5: 
To let Linker find libcaffe.so , you need to specify libcaffe.so in Properties->C/C++ Build->Setting->GCC C++ Linker->Miscellaneous->Other objects

If you does not want specify libcaffe.so in Eclipse.
You can Set LD_LIBRARY_PATH to ~.bashrc to find libcaffe for linker
$ echo 'export LD_LIBRARY_PATH="to/your/path/caffe/build/lib/"' > ~/.bashrc

In my case:
export LD_LIBRARY_PATH="/lib:/usr/lib:/usr/local/lib:/home/darrenl/developments/caffe/build/lib/"

Step6:
Add a *.cpp file and include caffe.hpp to build.

#include <caffe/caffe.hpp>
using caffe::Blob;
using caffe::Caffe;
using caffe::Datum;
using caffe::Net;
using caffe::shared_ptr;
using caffe::vector;
using caffe::MemoryDataLayer;
int main() {
    Net<float> *caffe_net;
    return 0;
}
You can refer to my source code:
$ git clone https://github.com/tzutalin/caffe_test.git

Build and Run
Build: Project-> Build Project  (ctrl + b)
Run: Run as Local C++ application (ctrl + F11)