Monday, May 18, 2015

Read Matlab File Into LMDB/LevelDB

I found current Caffe lacking this functionality to read Matlab .mat file (of arbitrary channels, not restricted to RGB) into LMDB/LevelDB, and was motivated to write an extension for this:

convert_mat.cpp

To use it, put it under Caffe_directory/tools, and include proper Matlab headers and libraries in Caffe Makefile. I also included an example of the CMakeLists.txt:

CMakeLists.txt 

This works for Mac. Under linux, the matlab path would probably be

-I/opt/matlab/extern/include
-L/opt/matlab/bin/glnxa64

Hope this small piece of code would be helpful.

Thursday, May 14, 2015

Reading .mat file in C++

The CMakeLists.txt:

cmake_minimum_required(VERSION 3.1)
project(mat2lmdb_cpp)

include_directories(/Applications/MATLAB_R2015a.app/extern/include)
link_directories(/Applications/MATLAB_R2015a.app/bin/maci64)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lmx -lmat")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")

set(SOURCE_FILES    convert_mat.cpp)

add_executable(mat2lmdb_cpp ${SOURCE_FILES})

Before you run, add the following:

export MATLAB="/Applications/MATLAB_R2015a.app"
export DYLD_LIBRARY_PATH=$MATLAB/bin/maci64/:DYLD_LIBRARY_PATH

Wednesday, May 13, 2015

A Quick Look at How to Mount SFTP Drive on Mac

1. Install macfuse.
2. Install sshfs
3. Mount using:

sshfs -o defer_permissions -o ServerAliveInterval=10 harryyang@***.***.edu:/ /Users/temp/sshfs2

Unmount

umount -f /Users/temp/sshfs

Thursday, May 7, 2015

Git switch branch

1. initialize from remote
git clone

2. update:
git pull

3. new branch:
git branch iss53
git checkout iss53

4. pull remote changes:
git reset --hard HEAD
git pull

Wednesday, May 6, 2015

CMakeLists Example

cmake_minimum_required(VERSION 3.1)
project(WebRun)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
include_directories(revlib/include include)
set(SOURCE_FILES main.cpp) add_executable(WebRun ${SOURCE_FILES}) TARGET_LINK_LIBRARIES(WebRun libboost_system.a libboost_filesystem.a libsqlite3.a)

Another example:

cmake_minimum_required(VERSION 3.1)
project(Occlusion)
find_package(PCL 1.3 REQUIRED COMPONENTS common io octree surface)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")

set(SOURCE_FILES    main.cpp)

add_executable(Occlusion ${SOURCE_FILES})
target_link_libraries(Occlusion ${PCL_LIBRARIES})

Monday, April 27, 2015

Atom not found symbol index for...

Turn off the strip optimization (-s).

The credit should go to some Chinese tech websites. Although I dislike searching in Chinese, but I found sometimes when you get stuck in some technical issues and become helpless with discussions on stackoverflow etc, they could be your last resort. =)


Friday, April 17, 2015

MatlabMPI



MPI_func('eval_bmaps_mpi',[40],{'localhost'},randomDirName('/share/project/shapes/harry'),mymaps,imnames,category,mymaps,SBDopts.path);

put config to get SBDopts.path

Monday, April 13, 2015

A Line Never Processed

It took me two hours to find out a bug in my code. At this time, two hours could mean a real saboteur. It is not something classic, but still it's worth marking down.

So I wanted to read 1000 lines from a huge file at a time, and I did the following:

while (true)
{
count := 0;
while (infile>> xyz && count <1000)
{
        do something with xyz;
        count ++;
}

do something;
if (count < 1000)
      break;
}
}

The code runs smooth, however it takes a long time for me to find out some lines are missing from the output.

Eventually I found out it all occurs at 

while (infile>> xyz && count <1000)

which means if count == 1000 it will still read another line to xyz but stops at the condition count<1000, and that line will never be processed.

Looks silly, but it does caused me a lot of panic. 

Wednesday, April 8, 2015

Ubuntu Launcher Stays Behind

Open your terminal by pressing Ctrl + Alt + T and type this following to solve this problem:
unity&disown

Emacs Parenthesis Highlight and Indent Region

Parenthesis Highlight:

M-x show-paren-mode RET
Indent Region:
C-M-\ 

Caffe Compile Problem

#error -- unsupported GNU version! gcc 4.9 and up are not supported!


comment this line out:

CUSTOM_CXX := /gcc-4.9.2/bin/g++
You may need to remove "/gcc-4.9.2/lib64" from LIBRARY_DIRS too.
Change this back when it's time to compile "matcaffe".

You need to run source  ~/.bashrc everytime you update it

Tuesday, April 7, 2015

Matlab visualization

hold on;
plot(y,x,'o',color,marker,'markersize',msz);
clf;

drawBoundary([],regions,color,width);

[x,y]=find(ucm>.1);plot(y,x,'r.','markersize',1)

h=iimagesc(b);
set(h,'AlphaData',0.5);



clf;
id=125;
name=ds.imnames{id};
mat=load(fullfile(ds.spdirs.slic,[name,'_slic_k600_m15.mat']));
im=mat.im;
p=load(['/share/data/vision-greg/harry/aeroplane/',name,'_pos.mat']);
pos_res=p.pos_res;
pos_res=pos_res';
t=cell2mat(pos_res);
t1=t(:,1);
t2=t(:,2);
imshow(im);
hold on;
plot(t2+17,t1+17,'o','Color','magenta','Marker','x','MarkerSize',8);
ucm=ds.loadUCM(id);
ucm=ucm>0.1;
hold on;
h=imagesc(ucm);
set(h,'AlphaData',0.4);

clf;
im2=rgb2gray(im);
samples=GetSamplePointsUCM(im2,ucm);
t3=samples(:,1);
t4=samples(:,2);
imshow(im);
hold on;
plot(t4,t3,'o','Color','magenta','Marker','x','MarkerSize',8);

clf;
gt=ds.loadGT(id);
gt=gt.groundTruth{1}.Segmentation;
gt(gt==255)=0;
gt=gt>1;
imshow(im);
hold on;
h2=imagesc(gt);
set(h2,'AlphaData',0.4);

Sunday, April 5, 2015

SSHFS

sudo sshfs -o allow_other harryyang@sXXX.XXX:/share/ /mnt/share
fuse unmount: sudo umount

show using process fuser -mu /mnt/

Saturday, March 28, 2015

caffe make runtest problem

 error while loading shared libraries: libcudart.so.7.0: cannot open shared object file: No such file or directory

Solution:

sudo ldconfig /usr/local/cuda-7.0/lib64

Thursday, March 26, 2015