Skip to content

Commit

Permalink
fix: flush transformed images to state before detection
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Aug 21, 2024
1 parent 904afc3 commit 022d09b
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/nrtk_explorer/app/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,25 @@ def schedule_transformed_images(self, *args, **kwargs):

async def update_transformed_images(self, dataset_ids):
self._updating_transformed_images = True
try:
await self._update_transformed_images(dataset_ids)
finally:
self._updating_transformed_images = False

async def _update_transformed_images(self, dataset_ids):
if not ("transformed" in self.state.visible_columns):
return

transform = self._transforms[self.state.current_transform]

try:
id_to_matching_size_img = {}
for id in dataset_ids:
async with SetStateAsync(self.state):
id_to_matching_size_img = {
dataset_id_to_transformed_image_id(id): get_transformed_image(transform, id)
for id in dataset_ids
}
except asyncio.CancelledError:
self._updating_transformed_images = False
raise
transformed = get_transformed_image(transform, id)
id_to_matching_size_img[dataset_id_to_transformed_image_id(id)] = transformed

try:
async with SetStateAsync(self.state):
annotations = self.compute_annotations(id_to_matching_size_img)
except asyncio.CancelledError:
self._updating_transformed_images = False
raise
async with SetStateAsync(self.state):
annotations = self.compute_annotations(id_to_matching_size_img)

predictions = convert_from_predictions_to_second_arg(annotations)
scores = compute_score(
Expand Down Expand Up @@ -178,8 +176,6 @@ async def update_transformed_images(self, dataset_ids):

self.state.flush() # needed cuz in async func and modifying state or else UI does not update

self._updating_transformed_images = False

def compute_annotations(self, id_to_image: Dict[str, Image]):
"""Compute annotations for the given image ids using the object detector model."""
return get_annotations(self.detector, id_to_image)
Expand Down

0 comments on commit 022d09b

Please sign in to comment.