Monday, September 23, 2013

Convnet issue: got nan or inf!

I was able to install the convnet library and  trying to replicate the 13% accuracy on the CIFAR10 dataset claimed. but my implementation would run a few epochs and then give me a message such as " got nan or inf" and the process would die. 
I would get a message such as  : 

5.1... logprob:  1.224800, 0.430300 (2.227 sec)
5.2... logprob:  1.251499, 0.436500 (2.165 sec)
5.3... logprob:     nan, 1.000000 ^ got nan or inf!


Sometimes it would run for 5 epochs and die other times would be 40. 

After emailing Alex Krizhevsky the author of the library, he said, "it can happen if the optimization becomes numerically unstable, but it can also be caused by a faulty GPU"

So I swtiched my GPU for a different one and it worked!
So if you see this problem, something simple you can do is just try a different GPU. Good luck

Thursday, February 28, 2013

prereq-opencv-linux


#!/bin/bash
echo ""
echo "starting installation of essential packages for opencv..."

apt-get install build-essential
apt-get install cmake
apt-get install pkg-config
apt-get install libpng12-0 libpng12-dev libpng++-dev libpng3
apt-get install libpnglite-dev libpngwriter0-dev libpngwriter0c2
apt-get install zlib1g-dbg zlib1g zlib1g-dev
apt-get install libjasper-dev libjasper-runtime libjasper1
apt-get install pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools
apt-get install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-prog
apt-get install ffmpeg libavcodec-dev libavcodec52 libavformat52 libavformat-dev
apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0  libgstreamer0.10-dev
apt-get install libxine1-ffmpeg  libxine-dev libxine1-bin
apt-get install libunicap2 libunicap2-dev
apt-get install libdc1394-22-dev libdc1394-22 libdc1394-utils
apt-get install swig
apt-get install libv4l-0 libv4l-dev
apt-get install python-numpy
apt-get install git

Thursday, May 24, 2012

Getting OpenCV libraries loaded in Matlab for Linux Ubuntu with LD_LIBRARY_PATH issues

It turns out there is a bug on Ubuntu that for some reason doesn't let you change LD_LIBRARY_PATH the way it used to. This is very annoying and you can read more about this on this link
So there are a few things you can do about this. What seemed to me simple to do and worked was to follow what this thread suggested which is basically use LD_PRELOAD before calling matlab in this way:

LD_PRELOAD=/home/OpenCV-2.0.0/lib/libcv.so:/home/OpenCV-2.0.0/lib/libcxcore.so matlab

One thing that I had to do was to be a super user (sudo su) before doing all this because I also needed root access from matlab and also it didn't seem to load these libraries if you just do "sudo matlab"
This is not a long term solution but at lest can get you going. I hope this helps.

Thursday, April 19, 2012

Installing Boost in Windows 7

I got this steps from
http://www.beroux.com/english/articles/boost_unit_testing/?part=2
However, the link to the download page was wrong. Here are more updated steps:

1. Download the latest Boost installer from BoostPro Computing: http://www.boostpro.com/download/
2. Install the setup:
Select whatever mirror you like and VS version you are working with.

[X] Mulithread Debug, DLL --DLL Debug, required when BOOST_DYN_LINK defined.
[X] Mulithread, DLL --DLL Release, required when BOOST_DYN_LINK defined.
[X] Mulithread --LIB (for CRT DLL) Release, default in Release.
[X] Mulithread Debug --LIB (for CRT DLL) Debug, default in Debug.
[X] Mulithread, static runtime --LIB (for CRT LIB) Release.
[ ] Mulithread Debug, static runtime --LIB (for CRT LIB) Debug.
[ ] Single thread, static runtime
[ ] Single thread Debug, static runtime

3. Add Boost to the include and library folders of Visual Studio:
Go to the menu Tools > Options...
Go to Project and Solutions > VC++ Directories
Add to your Include files: C:\Program Files\boost\boost_X_XX_X
Add to your Include files: C:\Program Files\boost\boost_X_XX_X\boost\tr1
Add to your Library files: C:\Program Files\boost\boost_X_XX_X\lib

Optional:
Path inclusion: If you use Boost DLLs (rare) you may add C:\Program Files\boost\boost_X_XX_X\lib to your system PATH.

Wednesday, April 4, 2012

How to use Bilateral Filter in Opencv

Here is an example of using the bilateral filter where 21 is the color sigma and and 3 is the spatial sigma

cvSmooth(gray_image_,smoothed_image,CV_BILATERAL, 0,0, 21, 3);

Thursday, February 23, 2012

Why Latex crashes when using \usepackage in windows

Today I had this problem again and seemed to be because latex usually downloads automatically the packages that it doesn't have. However, in windows when Latex doesn't have the rights, it won't download this files because windows might block this process thinking is a a virus.
One way to fix this is by running Latex as administrator. This is done by right clicking on the application and choose "run as administrator"
I hope this helps

Tuesday, February 7, 2012

Compiling a simple OpenCv program in Ubuntu

Here is a couple links that could help you in case you run into problems:
opencv.org and willowgarage.com

Update: Here I found a script that takes care of the whole installation in Ubuntu. You might want to try that first.
https://help.ubuntu.com/community/OpenCV

Otherwise:
First you need to install the required packages in your system.
You can use this script to do that. Feel free to edit it in case doesn't work for you.
Remember to use chmod 755 to change the execution rights of the file


1. Create a folder for opencv
mkdir opencv
cd opencv

2. Download the code from
git clone git://code.opencv.org/opencv.git
or
git clone https://github.com/Itseez/opencv.git

3. Create a release folder to store built files
cd ~/opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

(Remember that if you have a GPU installed you want to add the following parameters: -D WITH_CUDA=YES -D CUDA_TOOLKIT_ROOT_DIR="/usr/local/cuda/bin")
-Optionally you can add other options to the cmake line such as -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON

4. Run make inside release
make
sudo make install



5. Create a simple project using your favorite IDE. Here I just used vi:
vim image-display.c

6. Create a simple program such as:

#include "highgui.h"

int main( int argc, char** argv ) {
// cvLoadImage determines an image type and creates datastructure with appropriate size
IplImage* img = cvLoadImage( argv[1],1);

// create a window. Window name is determined by a supplied argument
cvNamedWindow( argv[1], CV_WINDOW_AUTOSIZE );
// Display an image inside and window. Window name is determined by a supplied argument
cvShowImage( argv[1], img );
// wait indefinitely for keystroke
cvWaitKey(0);

// release pointer to an object
cvReleaseImage( &img );
// Destroy a window
cvDestroyWindow( argv[1] );
}


7. gcc -ggdb `pkg-config --cflags opencv` image-display.c -o image-display `pkg-config --libs opencv`

8. run the program ./image-display "cat.jpg"