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

Monday, March 2, 2015

My Dedication

It was another day at dinner. My friend said, 'Harry, you know David Sontag would come.' I said, 'I know.' Then I quickly added, 'I hope one day Harry Yang will be a name as big as David Sontag'.

This words feel like deeply rooted in my subconscious such that I didn't even try to be humble. It was also today, the same friend asked me to go for a walk, and asked me 'Do you love doing research?' I said, 'I do.' But I added 'I also want fame and fortune, or fame plus a descent life. I believe everyone who does research wants to make a name.'

I have been grateful to have known the friend, who is a genius guy since very young. As usual, I have been friendly and open-minded in a new place, but refrain myself from intentionally making friends. I always believe, if you are really the same type of people, sooner or later you will become very close.  It turns out we become very close after some time, and we talk a lot about anything, from pure research to rumors of scientists, and most of all, our excitement and frustration after long day's work.

He often asks 'How's your idol?' He is talking about Feifei Li, the Stanford Professor in AI. I have been a long-term fan of Feifei, and everyone around me knows it. It is very hard to explain why. But there are always mysterious chemicals between people. Just like the chemicals existing between Feifei, he, my genius college friend who is now going through painstaking life in Europe and me.

Research is never a world of any particular ethics. There is more emphasis on school name and your lineage than anywhere else. This year, if you are a PhD student at stanford working with Stephen Boyd, you will be invited to the job talk even with just one first-author paper on your resume. This is more reasonable than it sounds, as most of the research can hardly produce any immediate revenues. More likely it is just a game of intelligence and publication. Governments and companies pay you to play meaningless brain-teaser, such that they would hope you are having a good title to justify this. In this sense, no title is better than "MIT/Stanford/Berkerly/CMU" if you work on computer science (I tend to glorify computer science comparing with other subjects mostly because I love it). 

But all these dark corners should not stop anyone who is really passionate about the game from participating. The world is far from perfect, and it's already lucky that you know it's deficient rule. I play this game because I believe some day I can win the ticket to join the real match, and after entering the arena, I can be a rising star and really make a name (of course, plus a descent life when I can play with Emacs, Linux and Latex as much as I want). But it is also possible I will not be able to get a ticket even if I am no less good than all the players out there. Which is fine. A man will eventually learn to make peace and shake hands with life, letting go of his young ambition and living on.


Thursday, February 26, 2015

Remove Files From Repository but Keep Them Locally

git rm --cached -r somedir will stage the deletion of the directory, but doesn't touch anything on disk.
You should then add somedir/ to your .gitignore file so that git doesn't try and add it back.

Tuesday, February 17, 2015

Git: How to revert to a previous commit

This depends a lot on what you mean by "revert".

Temporarily switch to a different commit

If you want to temporarily go back to it, fool around, then come back to where you are, all you have to do is check out the desired commit:
# This will detach your HEAD, that is, leave you with no branch checked out:
git checkout 0d1d7fc32
Or if you want to make commits while you're there, go ahead and make a new branch while you're at it:
git checkout -b old-state 0d1d7fc32

Hard delete unpublished commits

If, on the other hand, you want to really get rid of everything you've done since then, there are two possibilities. One, if you haven't published any of these commits, simply reset:
# This will destroy any local modifications.
# Don't do it if you have uncommitted work you want to keep.
git reset --hard 0d1d7fc32

# Alternatively, if there's work to keep:
git stash
git reset --hard 0d1d7fc32
git stash pop
# This saves the modifications, then reapplies that patch after resetting.
# You could get merge conflicts, if you've modified things which were
# changed since the commit you reset to.

Undo published commits with new commits

On the other hand, if you've published the work, you probably don't want to reset the branch, since that's effectively rewriting history. In that case, you could indeed revert the commits. With Git, revert has a very specific meaning: create a commit with the reverse patch to cancel it out. This way you don't rewrite any history.
# This will create three separate revert commits:
git revert a867b4af 25eee4ca 0766c053

# It also takes ranges. This will revert the last two commits:
git revert HEAD~2..HEAD

# Reverting a merge commit
git revert -m 1 <merge_commit_sha>

# To get just one, you could use `rebase -i` to squash them afterwards
# Or, you could do it manually (be sure to do this at top level of the repo)
# get your index and work tree into the desired state, without changing HEAD:
git checkout 0d1d7fc32 .

# Then commit. Be sure and write a good message describing what you just did
git commit

Monday, February 16, 2015

NANO

Ctrl

^O
save contents without exiting (you will be prompted for a file to save to)
^X
exit nano (you will be prompted to save your file if you haven't)
^T
when saving a file, opens a browser that allows you to select a file name from a list of files and directories

SVN command

 svn add * --force

Wednesday, February 11, 2015

GIT Reconcile Detached HEAD with Master/origin

git branch temp
git checkout temp
git branch -f master temp
git checkout master
git branch -d temp
git push -f origin master

Thursday, January 29, 2015

opencv problem and boost problem

1. opencv:

open opencv.pc

and change path from .....libcalib3d.so to lcalib3d

2. boost:

boost:FOR EACH has not been declared

change to this:

 #include <boost/foreach.hpp>
 #include <boost/version.hpp>

 namespace boost {

 #if BOOST_VERSION != 104900
 namespace BOOST_FOREACH = foreach;
 #endif
 
 } // namespace boost
 
 #define foreach BOOST_FOREACH


Tuesday, January 27, 2015

Some unix commands:

grep -r "uniqueid"
find ./ | grep annotation | grep slu
apt-cache search yaml
less

Wednesday, January 14, 2015

Create Website Using Flask -- A Step by Step Guide

Part 1 How to compile and run the website

virtualenv env
. env/bin/activate

pip install Flask Flask-Script Flask-Mail Flask-SQLAlchemy Flask-Uploads Flask-WTF python-dateutil 

Next time:


mkdir flask
cd flask ; mv ~/path/to/Merlot .
virtualenv env
. flask/env/bin/activate
pip install pip install Flask Flask-Script Flask-Mail Flask-SQLAlchemy Flask-Uploads Flask-WTF python-dateutil merlot
cd Merlot
python mangae.py runserver
the only like you need to repeat the next time is the
. flask/env/bin/activate

Part 2 register and login

flask login and principal

Emacs Cheatsheet

C-x C-f: find file
C-s: search

C-x + enter: dir
C-w: delete selection

C-x u: undo

C-x 3: split window horizontally
C-x 2: split window vertically