def test_shape_score(self): """ Test class-specific shape score metric """ # verify no offset gives sim = 1 evaluator = BBEvaluator(self.submission, self.ground_truth, self.settings) shape_similarity = evaluator.shape_score() self.assertAlmostEqual(shape_similarity, 1) # verify that no submission gives sim = 0 scene = ProjectScene("bounding_box") evaluator2 = BBEvaluator(scene, self.ground_truth, self.settings) semantic_score = evaluator2.shape_score() self.assertEqual(semantic_score, 0) # verify that missed detection gives sim < 1 self.submission.elements.pop("1069") evaluator3 = BBEvaluator(self.submission, self.ground_truth, self.settings) semantic_score = evaluator3.shape_score() self.assertTrue(semantic_score < 1) # verify that extra detection gives sim < 1 self.ground_truth.elements.pop("57") self.ground_truth.elements.pop("1069") evaluator4 = BBEvaluator(self.submission, self.ground_truth, self.settings) semantic_score = evaluator4.shape_score() self.assertTrue(semantic_score < 1)
def test_shape_similarity(self): """ Verify that the shape similarity measure is producing sane outputs. """ # make a dummy scene scene = ProjectScene("bounding_box") evaluator = BBEvaluator(scene, scene, self.settings) obj1 = next(iter(self.submission.elements.values())) # ::: Temp only, use copy of obj1 if deep copy can be made to work obj2 = next(iter(self.ground_truth.elements.values())) # verify no offset gives sim = 1 sim = evaluator._shape_similarity(obj1, obj2) self.assertAlmostEqual(sim, 1) # verify small offset gives sim between 0 and 1 pose_orig = obj2.pose obj2.pose = Pose3(t=pose_orig.t + [0.1, 0, 0], R=pose_orig.R) sim = evaluator._shape_similarity(obj1, obj2) self.assertTrue(sim < 1 and sim > 0) # verify large offset gives sim = 0 obj2.pose = Pose3(t=pose_orig.t + [5, 5, 5], R=pose_orig.R) sim = evaluator._shape_similarity(obj1, obj2) self.assertAlmostEqual(sim, 0)
def test_shape_similarity(self): """ Verify that the shape similarity measure is producing sane outputs. """ # make a dummy scene scene = ProjectScene("voxels") # TODO: Get deepcopy working for ProjectScene and make a simpler example for faster unit test. evaluator = VoxelEvaluator(self.submission, self.ground_truth, self.settings) obj1 = self.submission.elements["1069"] obj2 = self.ground_truth.elements["1069"] # verify no offset gives sim = 1 sim = evaluator._shape_similarity(obj1, obj2) self.assertAlmostEqual(sim, 1) # verify small offset gives sim between 0 and 1 voxel_centers_orig = obj2.voxel_centers obj2.voxel_centers = obj2.voxel_centers + np.array([0.2, 0, 0]) sim = evaluator._shape_similarity(obj1, obj2) self.assertTrue(sim < 1 and sim > 0) # verify large offset gives sim = 0 obj2.voxel_centers = obj2.voxel_centers + np.array([1, 0, 0]) sim = evaluator._shape_similarity(obj1, obj2) self.assertAlmostEqual(sim, 0) obj2.voxel_centers = voxel_centers_orig shape_score = evaluator.shape_score() self.assertAlmostEqual(shape_score, 1)
def test_bounding_box_io(self): """ Save and load a bounding_box project. Also try overwriting the project (should fail). """ project_scene = ProjectScene(project_type="bounding_box") bounds = Box3d([-0.5, -0.5, -0.5], [0.5, 0.5, 0.5]) po = ProjectObject(id="1", bounds=bounds, category="chair") project_scene.elements["1"] = po # test saving project_scene.save(path=self.temp_directory, project_name="test") xml_path = os.path.join(self.temp_directory, "test", "test.xml") self.assertTrue(os.path.isfile(xml_path)) # test overwriting self.assertRaises(OSError, project_scene.save, path=self.temp_directory, project_name="test") # test loading project_scene = ProjectScene.load(path=self.temp_directory, project_name="test") self.assertIsInstance(project_scene, ProjectScene) self.assertIsInstance(project_scene.elements, ProjectObjectDict) # ::: TODO: improve check with equality test on project_scene # Check bounding box for the first ProjectObject po = project_scene.elements["1"] self.assertTrue(po.bounds.almost_equal(bounds, atol=0.01)) self.assertEqual(po.category, "chair")
def run(self, project, target_type): """ Convert an in-memory project to the target type Inputs: project (ProjectScene) - input project target_type (string) - voxels or bounding_box Return: new_project (ProjectScene) - a project with the target project type Exceptions: ValueError - if target_type is not allowed for the given input project. See above for allowed conversions. """ if (project.project_type, target_type) not in self.allowed_conversions: raise ValueError("Invalid target_type ({}) for \ project with type {}".format(target_type, project.project_type)) new_settings = deepcopy(project.settings) new_elements = ProjectObjectDict() for element in project.elements.values(): new_element = self.convert_element(element, target_type) new_elements[new_element.id] = new_element new_project = ProjectScene(project_type=target_type, elements=new_elements, settings=new_settings) return new_project