forked from norouzi/mih
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRUN.sh
153 lines (136 loc) · 3.92 KB
/
RUN.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# change matlab_root_dir to your matlab root dir
matlab_root_dir=
# add matlab to the PATH if it is not already there
# download the data, and create data/inria/ folder that includes ANN_SIFT1B folder and files
# if number of bits (nb) is not provided from outside, set it to 64
if [ -z "$nb" ]
then
nb=64;
fi
echo $nb
# some sanity checks
if [ "$matlab_root_dir" = "" ]
then
echo "set matlab_root_dir to your matlab root dir."
exit 1
fi
if [ ! -d data/inria/ANN_SIFT1B ]
then
echo "data/inria/ANN_SIFT1B does not exist."
exit 1
fi
if [ ! -d data/inria/matlab ]
then
echo "data/inria/matlab does not exist."
exit 1
fi
# compilation
mkdir -p build
cd build
cmake .. -DMATLABROOT=$matlab_root_dir
make
cd ..
# creation of the binary codes
# runs matlab, and then create_lsh_codes script inside it.
$matlab_root_dir/bin/matlab -nojvm -nodisplay -nosplash -r "nb=$nb;create_lsh_codes;quit"
if [ $? != 0 ]; then
echo "Could not run matlab to create lsh codes... Aborting"
exit 1
fi
# Multi-index hashing is being run for 12 different subsets of the
# binary codes (10K 100K 1M 2M 5M 10M 20M 100M 200M 500M 1B
# items). Number of substrings to be used for each case is stored in a
# bash array nch.
if [ "$nb" = "64" ]
then
nch[1]=5;
nch[2]=4;
nch[3]=4;
nch[4]=3;
nch[5]=3;
nch[6]=3;
nch[7]=3;
nch[8]=2;
nch[9]=2;
nch[10]=2;
nch[11]=2;
nch[12]=2;
else
if [ "$nb" = "128" ]
then
nch[1]=10;
nch[2]=8;
nch[3]=8;
nch[4]=6;
nch[5]=6;
nch[6]=5;
nch[7]=5;
nch[8]=5;
nch[9]=5;
nch[10]=4;
nch[11]=4;
nch[12]=4;
else
if [ "$nb" = "256" ]
then
nch[1]=19;
nch[2]=15;
nch[3]=13;
nch[4]=12;
nch[5]=11;
nch[6]=11;
nch[7]=10;
nch[8]=10;
nch[9]=10;
nch[10]=9;
nch[11]=9;
nch[12]=8;
else
echo "nb = $nb is not supported";
fi
fi
fi
db_file="codes/lsh/lsh_"$nb"_sift_1B.mat";
mih_results="cache/mih_"$nb"_1B.mat";
linscan_results="cache/linscan_"$nb"_1B.mat";
for ((nm=1; nm<=12; nm=nm+1))
do
build/mih $db_file $mih_results -Q 1000 -nMs 0.01 0.10 1 2 5 10 20 50 100 200 500 1000 -nM $nm -m ${nch[$nm]}
if [ $? != 0 ]; then
echo "Could not run mih for some reason... Aborting"
exit 1
fi
done
# Linear scan is being run for 12 different subsets of the binary
# codes. The number of queries is set to 100 (-Q 100) to increase the
# speed. The K in K-NN is set to 1000 (-K 1000)
for ((nm=1; nm<=12; nm=nm+1))
do
build/linscan $db_file $linscan_results -Q 100 -nMs 0.01 0.10 1 2 5 10 20 50 100 200 500 1000 -nM $nm -K 1000
if [ $? != 0 ]; then
echo "Could not run linscan for some reason... Aborting"
exit 1
fi
done
# Testing the results of mih with the results of linscan
$matlab_root_dir/bin/matlab -nojvm -nodisplay -nosplash -r "addpath('test');test_mih_with_linscan('$db_file',$((nb/8)),'$mih_results','$linscan_results');quit"
if [ $? != 0 ]; then
echo "Could not run test_mih_with_linscan for some reason... Aborting"
exit 1
fi
exit 0;
# Plots: If you run the following commands inside matlab, it will
# generate plots similar to the ones in the paper. (Note: this is not
# a bash script)
addpath matlab;
plot_time('cache/mih_64_1B.mat', 'cache/linscan_64_1B.mat');
plot_time('cache/mih_64_1B.mat', 'cache/linscan_64_1B.mat', [], 0, [.01 1000], [0 .2]);
plot_time('cache/mih_64_1B.mat', 'cache/linscan_64_1B.mat', [], .0002, [.01 1000], [0 20]);
addpath matlab;
plot_time('cache/mih_mlh_128_1B.mat', 'cache/linscan_mlh_128_1B.mat');
plot_time('cache/mih_mlh_128_1B.mat', 'cache/linscan_mlh_128_1B.mat', [], 0, [.01 1000], [0 1.1]);
plot_time('cache/mih_mlh_128_1B.mat', 'cache/linscan_mlh_128_1B.mat', [], .0002, [.01 1000], [0 30]);
addpath matlab;
plot_time('cache/mih_256_1B.mat', 'cache/linscan_256_1B.mat');
plot_time('cache/mih_256_1B.mat', 'cache/linscan_256_1B.mat', [], 0, [.01 1000], [0 1.1]);
plot_time('cache/mih_256_1B.mat', 'cache/linscan_256_1B.mat', [], .0002, [.01 1000], [0 30]);