Wednesday, April 10, 2019

Object Detection With Deep Neural Networks

Recently I red a series of papers about object detection using deep neural networks. Here is summary of the reading.

R-CNN: Region-based Convolutional Networks for Accurate Object Detection and Segmentation
用传统方法提出region proposal,train一个classifier和一个location regressor。classifier为了提高精度先用softmax train,然后fc层提出来的feature用svm fit,regressor单独作为一个network

用到了selective search生成proposal,从一个over-segmentation开始repeatedly merge similar regions. 然后每个region用传统的descriptor提feature,用bag-of-words model+ svm分类

Fast R-CNN


Faster R-CNN
提出一个region proposal network (RPN) 共享feature extraction的networks,不增加计算开销的情况下把上一版最耗时的region proposal步骤变成自动从network生成。

[Linux Tips] Bash Shell (I)

1.to declare a new variable:
variable_name=initial_value;
2. in linux, before you run you shell-script, you need to change the mod of script file.
chmod 755 script_name
(This will change the mode of file to owner: rwx, group and others: r-x)
maybe ./script_name is more precisely. This command will add the permission of execution to this script file.
3. use a variable:
$variable_name
4. to do something on all certain files under current directory:
for file in ` ls *[^smp].byu `
do
# do something on every file $file
echo $file
done

if ...
do
else
fi # end of if :)

5. substring:
To take part of a string:
string="test"
substring=${string:1:2}
echo subtring
result: es
note:
substring=${string_variable_name:starting_position:length}
The string starting position is zero-based.

6. Searching and Replacing Substrings within Strings:
In this method you can replace one or more instances of a string with another string. Here is the basic syntax:
alpha="This is a test string in which the word \"test\" is replaced."
beta="${alpha/test/replace}"
The string "beta" now contains an edited version of the original string in which the first case of the word "test" has been replaced by "replace". To replace all cases, not just the first, use this syntax:
beta="${alpha//test/replace}"

Note the double "//" symbol.

Here is an example in which we replace one string with another in a multi-line block of text:

list="cricket frog cat dog"
poem="I wanna be a x\n\
A x is what I'd love to be\n\
If I became a x\n\
How happy I would be.\n"
for critter in $list; do
echo -e ${poem//x/$critter}
done
Run this example:
$ ./myscript.sh
result:
I wanna be a cricket
A cricket is what I'd love to be
If I became a cricket
How happy I would be.
I wanna be a frog
A frog is what I'd love to be
If I became a frog
How happy I would be.
I wanna be a cat
A cat is what I'd love to be
If I became a cat
How happy I would be.
I wanna be a dog
A dog is what I'd love to be
If I became a dog
How happy I would be.
Silly example, huh? It should be obvious that this search & replace capability could have many more useful purposes.

7. to run matlab (e.g plot some graph) without start matlab window
matlab -nodesktop -nosplash -r "plot_data;quit;"
#here we have a .m file named "plot_data.m" under current dir

Tuesday, April 2, 2019

[Machine Learning] from distance to kernel (classification via SVM)

Since for many machine learning techniques, you can use kernel trick. This is important to find a kernel, or explicitly construct a kernel from your data. One possible way to do this is calculate metric distance.
This article only gives some fundamental ideas for this transformation, without any strict provment.

Once you have a matrix of distance to measure the difference or distance between a pair of instances, denote I_i, I_j. You may define a kernel function /rho (I_i, I_j) = f(d(I_i,I_j)), where d(I_i,I_j) is the distance you've obtained. The most common choice is natural exponential.
http://math.stackexchange.com/questions/221704/transforming-a-distance-function-to-a-kernel

Another webpage to list some ways to calculate kernel from original feature space:
http://scikit-learn.org/stable/modules/metrics.html

For the requirement for positive kernel, you may refer to this paper:
http://www.kyb.mpg.de/fileadmin/user_upload/files/publications/attachments/scholkopf00kernel_3781%5b0%5d.pdf


Monday, April 1, 2019

[Linux Tips] Screen, date

[Linux Tips] includes a series of very common tips for development in Linux environment. By default, I am using Ubuntu.

Screen.
This is used to create/maintain a session. This is very useful when you ssh to a remote machine and running some jobs in a interactive mode. Imagine if your network is disconnected, the thread to run your job will be killed. Screen can help you to create a session. You can attach (enter) or detach (quit) from the session.
1. To create a session
screen -S session_name
or simply,
screen

2. To list all sessions available.
screen -ls

3. Attach a session
screen -r session_name (a prefix is enough)

4. Detach a session
ctrl+a+d

5. Delete a session
screen -X -S session_name kill


Date
When you run some bash script. It's common that you want to name your output with current date/time.
In bash shell script you can do it as below.
dt_suffix=`date +'%d%m%H%M'`
Basically, it just assigns the date/time to a variable. And the string comes from date command. The +"%d%m%H%M" is the optional format parameter.


Bash Shell script, some common usages.
For-loop with an array.

declare -a your_array=(
foo
bar
baz
)
array_len=${#your_array[@]}
for ((i = 0; i< ${array_len}; i++));
do
echo "processing" ${your_array[${i}]}
# Do something here.
done

Check whether directory or file already exists.
file_path=PathToYourFile
dir_path=PathToYourDir
if [ ! -f ${file_path} ]; then
echo "File ${file_path} does not exist!"
else
echo "File ${file_path} already exists!"
fi

if [ ! -d ${dir_path} ]; then
echo "Directory ${dir_path} does not exist!"
else
echo "Directory ${dir_path} already exists!"
fi