Recompute candidate views every policy update

This commit is contained in:
Michel Breyer 2021-10-08 14:14:15 +02:00
parent 6ec5272394
commit 13dfaa47d0

View File

@ -62,18 +62,6 @@ class NextBestView(MultiViewPolicy):
def activate(self, bbox, view_sphere): def activate(self, bbox, view_sphere):
super().activate(bbox, view_sphere) super().activate(bbox, view_sphere)
with Timer("view_generation"):
self.generate_view_candidates()
self.info["view_candidates_count"] = len(self.view_candidates)
def generate_view_candidates(self):
thetas = np.deg2rad([15, 30, 45])
phis = np.arange(8) * np.deg2rad(45)
self.view_candidates = []
for theta, phi in itertools.product(thetas, phis):
view = self.view_sphere.get_view(theta, phi)
if self.is_feasible(view):
self.view_candidates.append(view)
def update(self, img, x, q): def update(self, img, x, q):
if len(self.views) > self.max_views or self.best_grasp_prediction_is_stable(): if len(self.views) > self.max_views or self.best_grasp_prediction_is_stable():
@ -81,7 +69,8 @@ class NextBestView(MultiViewPolicy):
else: else:
with Timer("state_update"): with Timer("state_update"):
self.integrate(img, x, q) self.integrate(img, x, q)
views = self.view_candidates with Timer("view_generation"):
views = self.generate_views()
with Timer("ig_computation"): with Timer("ig_computation"):
gains = [self.ig_fn(v, 10) for v in views] gains = [self.ig_fn(v, 10) for v in views]
with Timer("cost_computation"): with Timer("cost_computation"):
@ -109,6 +98,16 @@ class NextBestView(MultiViewPolicy):
return True return True
return False return False
def generate_views(self):
thetas = np.deg2rad([15, 30, 45])
phis = np.arange(6) * np.deg2rad(60)
view_candidates = []
for theta, phi in itertools.product(thetas, phis):
view = self.view_sphere.get_view(theta, phi)
if self.is_feasible(view):
view_candidates.append(view)
return view_candidates
def ig_fn(self, view, downsample): def ig_fn(self, view, downsample):
tsdf_grid, voxel_size = self.tsdf.get_grid(), self.tsdf.voxel_size tsdf_grid, voxel_size = self.tsdf.get_grid(), self.tsdf.voxel_size
tsdf_grid = -1.0 + 2.0 * tsdf_grid # Open3D maps tsdf to [0,1] tsdf_grid = -1.0 + 2.0 * tsdf_grid # Open3D maps tsdf to [0,1]