Sunday, October 30, 2016

Caffe On Joules - Part two: Cmake soup

I assume that now you have Cmake and OpenCV installed as detailed on the previous post on Caffe. So this post will be mostly about "cmake"ing stuff and sticking them together to compile caffe. First we need to go back into the docker container that the Intel® System Studio IoT uses. To do this fire up the ISSI workspace which also results in getting the docker container running, then probe the docker containers and get a bash shell running in the ISSI container:
docker ps
docker exec -i -t  /bin/bash
And now that we are are inside the ISSI docker container, with no further ado, let's dig in to download and cmake and install a fresh copy of Atlas[1]. Note that code was used from [2]:
cd /home/root/
wget http://freefr.dl.sourceforge.net/project/math-atlas/Stable/3.10.3/atlas3.10.3.tar.bz2
wget http://www.netlib.org/lapack/lapack-3.5.0.tgz
tar xjvf atlas3.10.3.tar.bz2
cd ATLAS
mkdir build
cd build
../configure --prefix=/usr/local --with-netlib-lapack-tarfile=/home/root/lapack-3.5.0.tgz --nof77 -v 2 --cripple-atlas-performance
make build
make install
Then we go onto installing the HDF5 library according to [3]:
cd /home/root/
wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.0-patch1/src/CMake-hdf5-1.10.0-patch1.tar.gz
tar xzvf CMake-hdf5-1.10.0-patch1.tar.gz
cd CMake-hdf5-1.10.0-patch1
./build-unix.sh
cd build
cmake .
make
make install
Then lets do protobuf:
cd /home/root/
wget https://github.com/google/protobuf/archive/master.zip -O protobuf.zip
unzip protobuf.zip
cd protobuf-master/
./autogen.sh
./configure
make
make check
make install
Then we have LMDB:
cd /home/root/
wget https://github.com/LMDB/lmdb/archive/mdb.master.zip
unzip mdb.master.zip
cd lmdb-mdb.master/libraries/liblmdb/
make && make install
Then gflags:
cd /home/root/
wget https://github.com/gflags/gflags/archive/master.zip -O gflags.zip
unzip gflags.zip
cd gflags-master/ && mkdir build && cd build
cmake .. && make && make install
Then glog, yes life is hard:
cd /home/root/
wget https://github.com/google/glog/archive/master.zip -O glog.zip
unzip glog.zip
cd glog-master/ && mkdir build && cd build
cmake .. && make && make install
Finally we get to caffe:
cd /home/root/
wget https://github.com/BVLC/caffe/archive/master.zip -O caffe.zip
unzip caffe.zip
cd caffe-master && mkdir build && cd build
ccmake ..
Notice that this time we are using ccmake instead of cmake. Indeed we need to do some surgery to get things working. In the ccmake dialog press "c" and you will be presented with an error. Something about HDF5 not being configured properly. To get past this quickly we are going to set the HDF5 variables manually. To do this first press "e" to exit the help dialog. And then press "t" to enter advanced mode, yes you are now officially CMAKE NINJA. We'll have to manually copy the following lines to their corresponding variables in ccmake:
HDF5_CXX_INCLUDE_DIR:/usr/local/myhdf5/include/
HDF5_C_INCLUDE_DIR:/usr/local/myhdf5/include/
HDF5_hdf5_LIBRARY_RELEASE:/usr/local/myhdf5/lib/libhdf5.a
HDF5_hdf5_cpp_LIBRARY_RELEASE:/usr/local/myhdf5/lib/libhdf5_cpp.a
HDF5_hdf5_hl_LIBRARY_RELEASE:/usr/local/myhdf5/lib/libhdf5_hl.a
HDF5_hdf5_hl_cpp_LIBRARY_RELEA:/usr/local/myhdf5/lib/libhdf5_hl_cpp.a
CMAKE_EXE_LINKER_FLAGS:-ldl -lszip -lz -L/home/root/CMake-hdf5-1.8.17/build/_CPack_Packages/Linux/TGZ/HDF5-1.8.17-Linux/HDF_Group/HDF5/1.8.17/lib/
While you are in ccmake you better turn off these flags: USE_LEVELDB, USE_CUDNN, BUILD_SHARED_LIBS, and turn on CPU_ONLY. Now press "c" and "g" then "make" caffe! :) With this Caffe is built, and you can run it on the docker container. Furthermore you can try to run it on Joule, but you will have missing libraries. For fixing this you can copy all the lib files from the docker container into a folder on the caffe /root/home/ directory. Of course you'd have to set the LD_LIBRARY_PATH to the said directory. With all this work, caffe still wont work on Joule. If you remember, we built atlas on the docker container, hence it uses instructions that work on your CPU and as soon as it start computing something, caffe will crash. To remedy this we should build the atlas libraries on the Joule device, but this is the story of another day. gl hf. [1] http://math-atlas.sourceforge.net/
[2] http://theworldofinteledison.blogspot.com.es/2015/04/getting-scipy-working-on-edison.html
[3] https://support.hdfgroup.org/HDF5/release/cmakebuild.html

Caffe on Intel Joule

Caffe On Joule. - Part one: return of OpenCV

TL;DR:
I have a Caffe. I have a Joule. UH: Caffe-Joule [1]:

Long story is Caffe is a deep learning framework that is primarily in C++[2]. Essentially it is a package that allows training and deploying deep neural networks. It uses protobufs to define a language for constructing different networks and uses GPUs and/or BLAS libraries to speed up the training and testing process.

Joule is a new hardware platform by Intel that was just released by Intel[3]. It features a quad-core Atom CPU, 4 GB of ram, and 16 GB of eMMC all in a package half the size of a credit card. That is it packs the computational power of a laptop in a package that fits in a pocket.

Now I am sure there is a ton of new things that we can do with the new Joule platform, but my prediction is that performing deep neural network computations is the main breakthrough that it achieves. With deep learning the device can use microphones and camera images to form an understanding of the surroundings that has previously been impossible to achieve.

In this article I will show how to setup and run a sample OpenCV program on the Intel Joule. The next article will continue with the installation of Caffe.

To get started first go a head to [4] and complete it up to and including the section: "Setting up the Intel® System Studio IoT Edition (Linux*)". So now you have a project setup that blinks the LED on the board. Now we'll transform this project to one that uses opencv to access a USB camera and save images to the root's home directory.

First, we shall copy the following piece of code in the place of the main file:
/*
Hey! this is a Hack. don't use for production.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <unistd.h>

#include <csignal>  //Library from the C/++ standard libraries to allow for clean exits.
#include <cstdlib>  //
#include <unistd.h> //
#include <iostream> //The most commonly-included file. This allows you to use cin and cout to print to the console and collect user input.

#include <mraa.hpp> //Intel's MRAA Library. This library allows the programmer to address the GPIO pins on the development board.

#include <cv.h>
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <stdio.h>


using namespace std; //Commonly considered bad practice, this command prevents some simple mistakes that can be difficult to track down for a beginner. Generally, though, you wouldn't do this.
using namespace cv;
//This is a global variable which will hold our GPIO object. (General Purpose In/Out)
mraa::Gpio *gpio;

//This function is called a "signal handler." It allows a signal like "SIGINT" to exit the program cleanly.
//In this case, the SIGINT will be generated by the OS when you press Ctrl+C on your keyboard.
void signal_handler(int sig) {
 delete gpio;
 cout << "Exiting." << endl;
 exit(0);
}

//The main entry point for your program. This is the function that the OS (OSTRO) calls when it "runs" your code.
int main(int argc, char **argv) {

 signal(SIGINT, signal_handler); //This sets the event handler to the SIGINT signal. This is the signal generated by Ctrl+c.

 cout << "Hello from Intel on Joule! again" << endl //Remember, c++ isn't whitespace-sensitive, so you can use "carriage returns" (split lines) in the middle of function calls.
 << "Press Ctrl+c to exit..." << endl;    //This is very useful when the function call will be long and otherwise unwieldy.

 gpio = new mraa::Gpio(100); //Instantiate the GPIO object so that we can access the pin. (Pin 100)


 Mat image;

 cout << "going to test new stuff" << endl;

 VideoCapture capture;

 int c = 0;
 if(!capture.open(c))
  cout << "Capture from camera #" <<  c << " didn't work" << endl;
 else
  cout << "Capture from camera #" <<  c << " actually worked holy shit!" << endl;

 Mat frame;

 if( capture.isOpened() )
 {
  cout << "Video capturing has been started ..." << endl;

  for(;;)
  {
   capture >> frame;
   if( frame.empty() ){
    cout << "empty frame recieved?" << endl;
   }

   Mat frame1 = frame.clone();
   imwrite("coolFile.jpg",frame1);
   cout << "new frame saved" << endl;
   usleep(100);
  }
 }


 delete gpio; //Dispose of the object, now that we no longer need it. This is only needed because the object was allocated on the heap instead of the stack. (I.e. created with a pointer.)
 return 1; //As always, don't forget to return something. In this case, if the code reached this point, there was a problem, so we'll return 1 here.
}

Now you should try to build this, and you will be presented with the error
fatal error: cv.h: No such file or directory
And this makes perfect sense because we have not yet installed OpenCV. To do so, first we find the docker container that has been created with the eclipse workspace:
docker ps
this will show you information about the running container:
CONTAINER ID        IMAGE                                   COMMAND    
257c608539a3        inteliotdevkit/intel-iot-ostro:latest   "/bin/bash" 
note the container ID and proceed to launch a shell inside the container:
docker exec -i -t  /bin/bash
Now you should be inside a bash shell. The next step is to download a copy of Cmake and install it. We can get a copy at [5]. untar. bootstrap and make install:
cd /home/root/
wget https://cmake.org/files/v3.7/cmake-3.7.0-rc3.tar.gz
tar xzvf cmake-3.7.0-rc3.tar.gz
cd cmake-3.7.0-rc3
./bootstrap
make
make install
That's it now you have a fresh copy of cmake installed.
Now for OpenCV, you can get a download link for version 3.1 at [6]. This has to be "cmake"ed, "make"ed and "make install"ed:
cd /home/root
wget https://github.com/Itseez/opencv/archive/3.1.0.zip
unzip 3.1.0.zip
cd opencv-3.1.0/
mkdir build
cd build
cmake ..
make
make install
Although OpenCV is now installed on the docker container, the project will not yet build. We need to show eclipseCDT where it can find the include files and the lib files. In the "project explorer" window right click the project and choose properties. A dialog pops up, in the left pane of the dialog, open the "C/C++ Build" branch by click on the black arrow beside it then choose "settings". In the right pane on the top there will be a dropdown box, select "[all configurations]" from the dropdown. Now on the bottom right part of the top pane select "Includes" from under the "IoT Ostro 64-bit G++ compiler". Finally add the following line to the "include paths (-l)" sub pane:
"//${DOCKER_IMAGE}${DOCKER_SYSROOT}/usr/local/include/opencv/"
The following image should make things clearer:

If we try to build the project now it will compile but it will it will give you linker errors such as:
/usr/local/include/opencv2/core/cvstd.hpp:625: undefined reference to `cv::String::allocate(unsigned long)'
To also fix this we had to link with the OpenCV libraries. This is done in the same dialog as the before. In the left pane of the dialog choose "libraries" from ""IoT Ostro 64-bit G++ Linker". Now add the following libraries one by one to right top pane:
opencv_core
opencv_imgcodecs
opencv_highgui
opencv_imgproc
opencv_videoio
And that's it folks, your OpenCV project should build and get deployed to the device in question. As soon as it starts running, it will probe the USB and open the camera, if any. Then it will start saving images to the file named "/home/root/coolFile.jpg" on the device.
In the next post I will elaborate how we can compile and run caffe on the device.

[1] https://youtu.be/Qu5G443dQ4A
[2] https://github.com/BVLC/caffe
[3] https://software.intel.com/en-us/iot/hardware/joule
[4] https://software.intel.com/en-us/getting-started-on-joule
[5] https://cmake.org/download/ [6] http://opencv.org/downloads.html

Caffe on Intel Joule - Part one: return of OpenCV

TL;DR:
I have a Caffe. I have a Joule. UH: Caffe-Joule [1]:

Long story is that Caffe is a deep learning framework that is primarily in C++[2]. Essentially it is a package that allows training and deploying deep neural networks. It uses protobufs to define a language for constructing different networks and uses GPUs and/or BLAS libraries to speed up the training and testing process.

Joule is a new hardware platform by Intel that was just released by Intel[3]. It features a quad-core Atom CPU, 4 GB of ram, and 16 GB of eMMC all in a package half the size of a credit card. That is it packs the computational power of a laptop in a package that fits in a pocket.

Now I am sure there is a ton of new things that we can do with the new Joule platform, but my prediction is that performing deep neural network computations is the main breakthrough that it achieves. With deep learning the device can use microphones and camera images to form an understanding of the surroundings that has previously been impossible to achieve.

In this article I will show how to setup and run a sample OpenCV program on the Intel Joule. The next article will continue with the installation of Caffe.

To get started first go a head to [4] and complete it up to and including the section: "Setting up the Intel® System Studio IoT Edition (Linux*)". So now you have a project setup that blinks the LED on the board. Now we'll transform this project to one that uses opencv to access a USB camera and save images to the root's home directory.

First, we shall copy the following piece of code in the place of the main file:
/*
Hey! this is a Hack. don't use for production.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <unistd.h>

#include <csignal>  //Library from the C/++ standard libraries to allow for clean exits.
#include <cstdlib>  //
#include <unistd.h> //
#include <iostream> //The most commonly-included file. This allows you to use cin and cout to print to the console and collect user input.

#include <mraa.hpp> //Intel's MRAA Library. This library allows the programmer to address the GPIO pins on the development board.

#include <cv.h>
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <stdio.h>


using namespace std; //Commonly considered bad practice, this command prevents some simple mistakes that can be difficult to track down for a beginner. Generally, though, you wouldn't do this.
using namespace cv;
//This is a global variable which will hold our GPIO object. (General Purpose In/Out)
mraa::Gpio *gpio;

//This function is called a "signal handler." It allows a signal like "SIGINT" to exit the program cleanly.
//In this case, the SIGINT will be generated by the OS when you press Ctrl+C on your keyboard.
void signal_handler(int sig) {
 delete gpio;
 cout << "Exiting." << endl;
 exit(0);
}

//The main entry point for your program. This is the function that the OS (OSTRO) calls when it "runs" your code.
int main(int argc, char **argv) {

 signal(SIGINT, signal_handler); //This sets the event handler to the SIGINT signal. This is the signal generated by Ctrl+c.

 cout << "Hello from Intel on Joule! again" << endl //Remember, c++ isn't whitespace-sensitive, so you can use "carriage returns" (split lines) in the middle of function calls.
 << "Press Ctrl+c to exit..." << endl;    //This is very useful when the function call will be long and otherwise unwieldy.

 gpio = new mraa::Gpio(100); //Instantiate the GPIO object so that we can access the pin. (Pin 100)


 Mat image;

 cout << "going to test new stuff" << endl;

 VideoCapture capture;

 int c = 0;
 if(!capture.open(c))
  cout << "Capture from camera #" <<  c << " didn't work" << endl;
 else
  cout << "Capture from camera #" <<  c << " actually worked holy shit!" << endl;

 Mat frame;

 if( capture.isOpened() )
 {
  cout << "Video capturing has been started ..." << endl;

  for(;;)
  {
   capture >> frame;
   if( frame.empty() ){
    cout << "empty frame recieved?" << endl;
   }

   Mat frame1 = frame.clone();
   imwrite("coolFile.jpg",frame1);
   cout << "new frame saved" << endl;
   usleep(100);
  }
 }


 delete gpio; //Dispose of the object, now that we no longer need it. This is only needed because the object was allocated on the heap instead of the stack. (I.e. created with a pointer.)
 return 1; //As always, don't forget to return something. In this case, if the code reached this point, there was a problem, so we'll return 1 here.
}

Now you should try to build this, and you will be presented with the error
fatal error: cv.h: No such file or directory
And this makes perfect sense because we have not yet installed OpenCV. To do so, first we find the docker container that has been created with the eclipse workspace:
docker ps
this will show you information about the running container:
CONTAINER ID        IMAGE                                   COMMAND    
257c608539a3        inteliotdevkit/intel-iot-ostro:latest   "/bin/bash" 
note the container ID and proceed to launch a shell inside the container:
docker exec -i -t  /bin/bash
Now you should be inside a bash shell. The next step is to download a copy of Cmake and install it. We can get a copy at [5]. untar. bootstrap and make install:
cd /home/root/
wget https://cmake.org/files/v3.7/cmake-3.7.0-rc3.tar.gz
tar xzvf cmake-3.7.0-rc3.tar.gz
cd cmake-3.7.0-rc3
./bootstrap
make
make install
That's it now you have a fresh copy of cmake installed.
Now for OpenCV, you can get a download link for version 3.1 at [6]. This has to be "cmake"ed, "make"ed and "make install"ed:
cd /home/root
wget https://github.com/Itseez/opencv/archive/3.1.0.zip
unzip 3.1.0.zip
cd opencv-3.1.0/
mkdir build
cd build
cmake ..
make
make install
Although OpenCV is now installed on the docker container, the project will not yet build. We need to show eclipseCDT where it can find the include files and the lib files. In the "project explorer" window right click the project and choose properties. A dialog pops up, in the left pane of the dialog, open the "C/C++ Build" branch by click on the black arrow beside it then choose "settings". In the right pane on the top there will be a dropdown box, select "[all configurations]" from the dropdown. Now on the bottom right part of the top pane select "Includes" from under the "IoT Ostro 64-bit G++ compiler". Finally add the following line to the "include paths (-l)" sub pane:
"//${DOCKER_IMAGE}${DOCKER_SYSROOT}/usr/local/include/opencv/"
The following image should make things clearer:

If we try to build the project now it will compile but it will it will give you linker errors such as:
/usr/local/include/opencv2/core/cvstd.hpp:625: undefined reference to `cv::String::allocate(unsigned long)'
To also fix this we had to link with the OpenCV libraries. This is done in the same dialog as the before. In the left pane of the dialog choose "libraries" from ""IoT Ostro 64-bit G++ Linker". Now add the following libraries one by one to right top pane:
opencv_core
opencv_imgcodecs
opencv_highgui
opencv_imgproc
opencv_videoi
And that's it folks, your OpenCV project should build and get deployed to the device in question. As soon as it starts running, it will probe the USB and open the camera, if any. Then it will start saving images to the file named "/home/root/coolFile.jpg" on the device.
In the next post I will elaborate how we can compile and run caffe on the device.

[1] https://youtu.be/Qu5G443dQ4A
[2] https://github.com/BVLC/caffe
[3] https://software.intel.com/en-us/iot/hardware/joule
[4] https://software.intel.com/en-us/getting-started-on-joule
[5] https://cmake.org/download/ [6] http://opencv.org/downloads.html

Friday, January 16, 2015

cuda matrix transpose code and test

This is essentially the code from here:

http://devblogs.nvidia.com/parallelforall/efficient-matrix-transpose-cuda-cc/

I have expanded it to handle non-Square matrices whose sizes are not a multiple of the block size:

/**
 * writtern By Amir Hossein Bakhtiary, use as you wish. Shouldn't have any copyright problems.
 */
#include
#include
#include

#include
#include
#include
#include
#include
#include
#include


const int TILE_DIM = 32;
const int BLOCK_ROWS = 8;

template
__global__ void transposeCoalesced(Dtype *odata, const Dtype *idata, int rows,int cols)
{
  __shared__ Dtype tile[TILE_DIM][TILE_DIM+1];

  int x = blockIdx.x * TILE_DIM + threadIdx.x;
  int y = blockIdx.y * TILE_DIM + threadIdx.y;

//  if (x >= cols||y >= rows){
//      return;
//  }

  int maxJ = TILE_DIM;
  int maxJ2 = TILE_DIM;
  int otherMaxJ = rows - y;
  if (maxJ > otherMaxJ)
    maxJ = otherMaxJ;


  if ( x < cols ){
    for (int j = 0; j < maxJ; j += BLOCK_ROWS)
     tile[threadIdx.y+j][threadIdx.x] = idata[(y+j)*cols + x];
  }
  __syncthreads();

  x = blockIdx.y * TILE_DIM + threadIdx.x;  // transpose block offset
  y = blockIdx.x * TILE_DIM + threadIdx.y;

  int otherMaxJ2 = cols - y;
  if (maxJ2 > otherMaxJ2){
      maxJ2 = otherMaxJ2;
  }
  if ( x < rows){
    for (int j = 0; j < maxJ2; j += BLOCK_ROWS)
       odata[(y+j)*rows + x] = tile[threadIdx.x][threadIdx.y + j];
  }

}

template
thrust::device_vector invertMatrix(thrust::device_vector mat,unsigned rows,unsigned cols){
    thrust::device_vector retval(rows*cols);
    dim3 dimGrid((rows+TILE_DIM-1)/TILE_DIM,(cols+TILE_DIM-1)/TILE_DIM, 1);
    //dim3 dimGrid((nHashes)/TILE_DIM,(nSamples)/TILE_DIM, 1);
    dim3 dimBlock(TILE_DIM, BLOCK_ROWS, 1);

    transposeCoalesced<<< dimGrid, dimBlock>>>(retval.data().get(),mat.data().get(),rows,cols);
    return retval;
}


template
void testInvert(){
    thrust::host_vector h_vec(1000);
    thrust::generate(h_vec.begin(), h_vec.end(), rand);
    int rows = 3 , cols = 4;
    thrust::device_vector a = h_vec;

    thrust::device_vector aInv = invertMatrix(a,rows,cols);
    for (int i = 0 ; i < rows; i++){
        for (int j = 0; j < cols; j++){
            std::cout << (a[i*cols+j]) << " " << aInv[j*rows+i] << std::endl;
        }
    }
}


int main()
{
    testInvert();
}

Thursday, September 9, 2010

PIMPEL

... is a very nice method for use in C++ for abstraction, encapsulation and overall niceness. Why did I not know this before?

Wednesday, August 18, 2010

Posientation!

Finally I have found a word to describe a variable that holds both the position and orientation. Actually, I had to come up with it myself and it's a word I am proud of: Posientation = Position + Orientation.

I must say it is just very difficult to program when you don't have correct variable names. I had looked for this many times and now that I have it my design looks a lot nicer.

Sunday, August 1, 2010

gui complete

That new program I started... Now for approx 300 lines of code I have something that exits when I press 'q'! Lets get this rolling.

Sunday, July 25, 2010

project on sourceforge

I have my blimps repo up at sf.net:
https://aeriallocalizer.svn.sourceforge.net/svnroot/aeriallocalizer

Saturday, July 24, 2010

Back to thesis!

I better be getting this project done now. Working on a new aggregator as I literally hate Multi-hypothesis Bayesian estimators now...

Wednesday, May 5, 2010

paper

got another paper accepted, it's on using PSO for path planning. I have to admit using PSO is never a very good Idea, but in the name of science ... :)

Sunday, November 22, 2009

Bimps and politics, Or how life could have been better in Iran and Afghanistan had we had better blimp technology

After what happened in the Iran Election 2009, I really do wish the west would be able to get its act together in Afghanistan, and trust me these two are related! Here we will present how airships could have actually helped the political life and hence the daily well being of people both in Afghanistan and Iran and how they can do so in the future.

The ruling clergy in Iran has been promising a prosperous Iran ever since its conception. Not only have we not reached that prosperity, but also the living and working quality of life in Iran has fallen behind countries that were once less developed like south Korea turkey and Malaysia. Prosperity in neighbouring countries whose administrations have become democratic can heavily undermine the promise of prosperity in Iran and grossly educate people on the pros of a democratic government. I have to add a note here that many people in Iran really haven't realized that and some even still believe democracies to be devious systems.

Afghanistan could have been a great informative example for Iranians because of its similarity to Iran in terms of demography and because of a strong tie between the people of the two nation. Given that I believe both the Iraq and Afghanistan war were justified, although the Iraq war went well1, the state of Afghanistan is now in a mess and this chance for eduction is currently being lost. lets face it, the international community in Afghanistan has failed both militarily and socially.

The Airships, had the technology been available, could have changed the odds in both fronts. In the military aspect, Al-Qa'ida has been active mostly in small villages and rough mountainous regions. Autonomous Airships could have provided a great surveillance option to the authorities over the movement of forces on dirt roads and on the mountains. They could have traced every single vehicle in specific regions and they could have spotted human activities in unknown mountainous hideouts.

From the social aspect, communications and mass media (here radio and TV mostly) play a massive role in educating the public, neither of which existed in Afghanistan, and neither of which is easy to provide for in a country with no infrastructure. Airship could have been a viable solution for providing communications and mass media for the type of small communities that exist in Afghanistan.

We can see in Iran how the success of the campaign in Iraq is putting pressure on Iranian authorities and this is evident by the sort of propaganda they are trying to feed us about the current situation in Iraq (apparently the Iraqis are all dying!). Had better technology been used, Afghanistan would have been the same nightmare to the Sepah dwellers in Tehran.

All is not that bad though, we have got plenty of time to develop these technologies to meet economical communication demands in the world and war demands in upcoming conflicts.

1--- In my opinion, the Iraq war was as successful as it could ever be. In a country with so many Ideologies that prescribe murder for the opposing Ideology, you actually can not try to set things right without some of those madmen killing civilians. Furthermore I am sure that the country will flourish in 5 to 20 years time as already their civilian death toll from violence is far less than the death toll from road accidents in Iran.

Thursday, November 19, 2009

Even longer duration high altitude airships

Lockheed Martin has been recently exploiting the idea of using high altitude airships to perform long duration surveillance and communication relays here. Using very light photovoltaic panels, they plan to power an airship, eliminating the need to carry fuel on board. This allows the airships to stay airborne for a longer time. Currently they are planning to have systems that stay aloft for a minimum of a month.

It seems that their main problem for an even longer duration is the helium leakage. Although with modern materials they seem to have overcome the majority of the leakage problem, but there is still so much that the ships have to land once in a while (as far as I could figure, it was a month or two) to refill their helium.

One good Idea to extend the airships airborne duration is to replace the helium as it is lost, and although there is no source of helium in the stratosphere, we should be able to gather hydrogen at that height.

Before I go any further I would like to point out that by making the take-off and landing completely autonomous we can make the whole procedure very safe. I believe that the safety concerns of using hydrogen in unmanned aerial vehicles, although valid, have been too exaggerated, especially if the use of the H-gas would enables vehicles to stay aloft for literally years.

To obtain hydrogen we must first gather water from the air. This can be done using a cold plate in contact with the air. Much like the walls of a refrigerator the plate, when in contact with water molecules, will trap and solidify the molecules resulting in a layer of ice. Afterwards by heating up the plate the water can be collected and electrolysed into hydrogen and oxygen. The hydrogen can then be used to replace the lost gas.

Now all that remains is a question of numbers. For example whether the 15 KW solar systems on these demonstrative high altitude airships will be able to replace the lost gas? With 237 kj for one mol of hydrogen (20 liters at 1 atmosphere) I reckon it would be a close cut. Maybe I'll munch up the numbers next time. But I reckon that a wie bit larger airship can be set up to do this.
I actually came here to make a post on an Idea that I had, but though I'll give an update on my work first:
I used webots and imported maps from yahoo into a large flat piece of land with the provided blimp. I moved the blimp around and captured images with camera. Then I started testing my system with the provided images, trying to localize the blimp on a map taken of google. Note that the two different map sources means using images from different times.
So I started testing my localization scheme and that's when start it started to change. First the particle filter was too slow and I replaced it with an EKF (from opencv). But then the EKF would easily accumulate errors with wrong matches. Now I have switched to Multi hypothesis EKF(this I had to write myself) and its working ok, but the whole thing is underestimating the height of the vehicle.
I am guessing that the source of the underestimation is the input of the EKF update. What I am doing is literally I am feeding an average of several estimates for the input of the EKF update step. As for the height, I keep an estimate of the logarithm of the height. Since the height estimates are very inaccurate, as I am currently using the size of the features to obtain the estimates, averaging the logarithm gives a lot more pull to lower estimates than to higher estimates.
So what I will be doing now is changing the MHEKF to keep my height estimates in their original units...

Saturday, October 10, 2009

Report

Right now I have a particle filter that uses SIFT features to provide estimates on the location of a airborne camera. What happens is that SIFT features are pre-calculated for a given map and they are stored in a database where they can be quickly looked up.
Currently one aerial image is taken and its SIFT features are extracted. These are then matched against the features of the database and the features that have a good match are used to generate hypothesis about the location of the vehicle.
These hypothesis are then used to power the update phase of the particle filter. This is done by firstly strengthening the particles that fall in the range of one of the hypothesis, and then adding one sample single particle for each of the new hypothesis presented.
What happens is that the particles correctly accumulate around the position on the map where the centre of the taken image lies. They are, therefore, able to find the position of the image on the map.
What I am working on is a way to aggregated the information present in the particle filter into knowledge. Currently I am trying to use expectation maximization to find Gaussian functions that best represent the knowledge in the particles.

Saturday, May 23, 2009

Bayesian filter

In our work we are going to use a Bayesian filter to do the estimating of the position of the pictures that are being handed in. Given that the input data will include matches between points that will suggest very different possible points therefore filters that use a single modal function to represent their hypothesis are unsuitable for our purpose. Therefore we need to use Bayesian filters that can represent several hypothesis.

Thursday, May 21, 2009

Platform implementation for hierarchical localization

I need a platform for performing my tests and then implementing the system. There are several requirements for this platform. It has to provide basic image manipulation capabilities, It should help with performing tests and in the end I should be able to use it for implementing the final solution.

So what I have started to build my work on top of openCV that provides great vision features. Currently it reads a map from a directory of images and extracts SIFT features from that map. I have used a code by Rob Hess for the SIFT extraction (The code is clean (bad naming though) but I think some rather unconventional methods were used :( ).

Furthermore I extract features from a given image and match them with the features from the map. These matches will be used to aid a particle filter component provide the location of a given image in relation to the map.

Wednesday, April 29, 2009

Christian Siagian's sensor model

Mr Christian Siagian has a publication on how they managed to localize a camera in a scene. To do this they have used a particle filter to make and refine estimates of the location of a robot in a scene and. Now what I wanted to do is similar in that I want to use particle filter to localize.
Another similarity between my work and Mr. Siagian's is that I plan to use SIFT (or other patch encoding) features to aid my localization. What we both are doing essentially is using the matched SIFT features as sensor reading coming from the camera.
Now when a particle filter is used we need a sensor model to integrate the data from the sensors into the estimates of the particle filter. A sensor model provides us with a estimate of p(Rt|X) where Rt is a sensor reading and X is a hypothetical state of the system.
For my work I am going to perform a number of experiments to come up with an estimate of p(Rt|X) in the system that I will be using, but we were curious to know the sensor model that Mr. Siagian had used for his work, so I looked it up here(you'll have to read into the pdf file), and what he has done is assume a Gaussian profile for the SIFT sensor model.
To explain more clearly firstly he has an object recognition module. Here, an object is actually a number of SIFT features that appear together. So in the first runs the system extracts a number of objects (group of SIFT features) from the captured images and records these along with the place in the map where the objects were captured.
Afterwards in the test runs, when an object is recognized (a number of features are matched against a number of features of a single object in the data base) for each particle (in the particle filter) we need to update the weight of that particle by multiplying it by p(Rt|Xp) where Xp is the position (or state) of the particle in question and Rt is the event of observing the observed feature. Hence p(Rt|Xp) is the probability of seeing the object if we were indeed in the position that the particle tells us to be.
We now return to the thing that we were trying to clarify: how is p(Rt|Xp) calculated. As we have said with each object the position where the object was acquired is recorded. The value in question, is the chances of drawing a point further away from the position of the object than the particle. This chance is modelled using a Gaussian function with its sigma value set to 5% of the map diagonal.

Sunday, April 12, 2009

Why the camera is a good aerial sensor

We can use a number of different sensors for aerial vehicle use. We can name sonar, radar, lidar, GPS and camera as the most commonly used sensors.
The principle working behind sonar, radar and lidar are all nearly the same in that they all send out a signal that hits a target and returns. By intercepting this returning signal, the device can provide an estimate of the position of the objects in relation to the vehicle. Thus these devices are known as active devices.
The GPS on the other hand is a passive device that relies on the signals sent out by a number of satelites that orbit the earth. By calculating the time difference between the reception of these signals the GPS can calculate its own position in relation to the satelites and also in relation to the earth.
Finally we have the camera that senses the incomming rays of light from a large number of directions and provides an image that represents the strength of these rays.
For use in localization of course the GPS is the best choice, but there are situations in which the use of GPS or related technologies may not be possible. For example indoor environments or in between large buildings can have an unwanted effect on the signals that are sent by the satellites. Further problems are posed in combat situations where the signals may be jammed by the adversaries.
The problem with sonar is that, in high altitudes, a long time is required for the signal to reach earth and also the signal is dispersed alot

Thesis

My Msc Thesis is about hierarchical localization for aerial vehicle use. Localization by itself is about finding the location of an object. In our case in which we are working with aerial vehicles, we want to find the location of the vehicle. Of the sensors that are used for aerial localization the camera is best suited for localization (after GPS) as it can pick up images of the underlying terrain and register it against a provided map.
As outlined by the before, our approach towards this problem will be a hierarchical, meaning that we want to be able to find our position in a number of approximative steps. The procedure will first make a guess at the possible position of the aerial vehicle, and then, in each subsequent step it will refine its guess till it reaches an acceptable accuracy.
There already exist a number of work that try to perform localization hierarchically and these will be discussed in subsequent posts.

Sunday, March 29, 2009

Still writing

I am sooo slow at generating content! At a speed of 2 pages per day I think I have broken a slug world record or something. I promise to write more in this blog, especially for projects that need documentation.