7 from collections
import namedtuple
9 GlobalDescriptor = namedtuple(
'GlobalDescriptor',
10 [
'keyframe_id',
'robot_id',
'descriptor'])
14 params[
'robot_id'] = 0
15 params[
'max_nb_robots'] = 2
16 params[
'frontend.sensor_type'] =
'stereo'
17 params[
'frontend.similarity_threshold'] = 0.0
18 params[
"frontend.enable_sparsification"] =
True
19 params[
"evaluation.enable_sparsification_comparison"] =
False
24 """Unit tests for sparse matching
32 descriptor = np.random.rand(10)
33 descriptor = descriptor / np.linalg.norm(descriptor)
34 lcsm.add_local_global_descriptor(descriptor, 1)
35 for i
in range(len(descriptor)):
36 self.assertAlmostEqual(descriptor[i], lcsm.local_nnsm.data[0, i])
39 """Add other robot keyframe
43 descriptor = np.random.rand(10)
44 descriptor = descriptor / np.linalg.norm(descriptor)
46 lcsm.add_other_robot_global_descriptor(msg)
47 for i
in range(len(descriptor)):
48 self.assertAlmostEqual(descriptor[i],
49 lcsm.other_robots_nnsm[1].data[0, i])
52 """Test that cosine similarity matching gives the same ordering as euclidean distance
54 nb_descriptors_in_db = 100
56 for i
in range(nb_descriptors_in_db):
57 descriptor = np.random.rand(100)
58 descriptor = descriptor / np.linalg.norm(descriptor)
59 nnsm.add_item(descriptor, i)
61 nb_descriptors_to_test = 100
63 for i
in range(nb_descriptors_to_test):
64 query = np.random.rand(100)
65 query = query / np.linalg.norm(query)
66 ds = np.linalg.norm(query[np.newaxis, :] - nnsm.data[:nnsm.n], axis=1)
67 ns_dist = np.argsort(ds)[:k]
68 ns_sim, sims = nnsm.search(query, k)
70 self.assertTrue(np.all(sims[:-1] >= sims[1:]))
77 if (abs(sims[id_d] - sims[id_s]) < 1e-6)
or (abs(ds[id_d] - ds[id_s]) < 1e-6):
79 self.assertEqual(ns_dist[j], ns_sim[j])
80 ns_sim_best, sim_best = nnsm.search_best(query)
81 self.assertEqual(ns_dist[0], ns_sim_best)
84 """Matches between descriptors
89 descriptor0 = np.random.rand(10)
90 descriptor0 = descriptor0 / np.linalg.norm(descriptor0)
91 lcsm.add_local_global_descriptor(descriptor0, 2)
93 descriptor1 = 1 - descriptor0
94 descriptor1 = descriptor1 / np.linalg.norm(descriptor1)
96 lcsm.add_other_robot_global_descriptor(msg)
98 descriptor2 = descriptor0
101 descriptor2 = descriptor2 / np.linalg.norm(descriptor2)
103 lcsm.add_other_robot_global_descriptor(msg2)
105 id = lcsm.candidate_selector.candidate_edges[(0, 2, 1, 4)].robot1_id
106 best_match_descriptor = lcsm.other_robots_nnsm[id].data[0]
107 for i
in range(len(descriptor1)):
108 self.assertAlmostEqual(descriptor1[i], best_match_descriptor[i])
114 params[
'max_nb_robots'] = 3
118 for i
in range(nb_local_kfs):
119 descriptor = np.random.rand(10)
120 descriptor = descriptor / np.linalg.norm(descriptor)
121 lcsm.add_local_global_descriptor(descriptor, i)
123 for i
in range(nb_other_kfs):
124 descriptor = np.random.rand(10)
125 descriptor = descriptor / np.linalg.norm(descriptor)
127 lcsm.add_other_robot_global_descriptor(msg)
128 for i
in range(nb_other_kfs):
129 descriptor = np.random.rand(10)
130 descriptor = descriptor / np.linalg.norm(descriptor)
132 lcsm.add_other_robot_global_descriptor(msg)
135 is_robot_considered = {}
136 for i
in range(params[
'max_nb_robots']):
137 is_robot_considered[i] =
True
138 selection = lcsm.select_candidates(nb_candidates, is_robot_considered)
139 self.assertEqual(len(selection), nb_candidates)
146 params[
'max_nb_robots'] = 4
150 for i
in range(nb_local_kfs):
151 descriptor = np.random.rand(10)
152 descriptor = descriptor / np.linalg.norm(descriptor)
153 lcsm.add_local_global_descriptor(descriptor, i)
155 for i
in range(nb_other_kfs):
156 descriptor = np.random.rand(10)
157 descriptor = descriptor / np.linalg.norm(descriptor)
159 lcsm.add_other_robot_global_descriptor(msg)
160 for i
in range(nb_other_kfs):
161 descriptor = np.random.rand(10)
162 descriptor = descriptor / np.linalg.norm(descriptor)
164 lcsm.add_other_robot_global_descriptor(msg)
168 is_robot_considered = {}
169 for i
in range(params[
'max_nb_robots']):
170 is_robot_considered[i] =
True
171 selection = lcsm.select_candidates(nb_candidates, is_robot_considered)
172 self.assertEqual(len(selection), nb_candidates)
179 params[
'max_nb_robots'] = 4
180 params[
'robot_id'] = 1
184 for i
in range(nb_local_kfs):
185 descriptor = np.random.rand(10)
186 descriptor = descriptor / np.linalg.norm(descriptor)
187 lcsm.add_local_global_descriptor(descriptor, i)
189 for i
in range(nb_other_kfs):
190 descriptor = np.random.rand(10)
191 descriptor = descriptor / np.linalg.norm(descriptor)
193 lcsm.add_other_robot_global_descriptor(msg)
194 for i
in range(nb_other_kfs):
195 descriptor = np.random.rand(10)
196 descriptor = descriptor / np.linalg.norm(descriptor)
198 lcsm.add_other_robot_global_descriptor(msg)
202 is_robot_considered = {}
203 for i
in range(params[
'max_nb_robots']):
204 is_robot_considered[i] =
True
206 selection = lcsm.select_candidates(nb_candidates, is_robot_considered)
207 self.assertEqual(len(selection), nb_candidates)
210 if __name__ ==
"__main__":
def test_add_other_robot_global_descriptor(self)
def test_select_candidates0(self)
def test_similarity(self)
def test_select_candidates2(self)
def test_add_local_global_descriptor(self)
def test_select_candidates1(self)