Skip to content

Commit

Permalink
Merge pull request #667 from StanfordVL/replicator-hot-fix
Browse files Browse the repository at this point in the history
Replicator hot fix
  • Loading branch information
cgokmen authored Mar 19, 2024
2 parents cc0316a + 896137c commit dfc5585
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions omnigibson/sensors/vision_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,16 @@ def _remap_instance_segmentation(self, img, id_to_labels, semantic_img, semantic
# If the category name is not in the registered systems,
# which happens because replicator sometimes returns segmentation map and id_to_labels that are not in sync,
# we will label this as "unlabelled" for now
# This only happens with a very small number of pixels, e.g. 0.1% of the image
else:
num_of_pixels = len(np.where(img == key)[0])
resolution = (self._load_config["image_width"], self._load_config["image_height"])
percentage = (num_of_pixels / (resolution[0] * resolution[1])) * 100
if percentage > 2:
og.log.warning(f"Marking {category_name} as unlabelled due to image & id_to_labels mismatch!"
f"Percentage of pixels: {percentage}%")
value = "unlabelled"
self._register_instance(value, id=id)
replicator_mapping[key] = value

registry = VisionSensor.INSTANCE_ID_REGISTRY if id else VisionSensor.INSTANCE_REGISTRY
Expand Down
9 changes: 8 additions & 1 deletion omnigibson/utils/vision_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import numpy as np
from PIL import Image, ImageDraw
import omnigibson as og
from omnigibson.utils.constants import semantic_class_name_to_id

try:
import accimage
Expand Down Expand Up @@ -66,6 +68,7 @@ class Remapper:
def __init__(self):
self.key_array = np.array([], dtype=np.uint32) # Initialize the key_array as empty
self.known_ids = set()
self.warning_printed = set()

def clear(self):
"""Resets the key_array to empty."""
Expand Down Expand Up @@ -137,7 +140,11 @@ def remap_bbox(self, semantic_id):
Returns:
int: The remapped id.
"""
assert semantic_id < len(self.key_array), f"Semantic id {semantic_id} is out of range!"
if semantic_id >= len(self.key_array):
if semantic_id not in self.warning_printed:
og.log.warning(f"We do not have semantic information about bounding box semantic id {semantic_id} yet. Marking as unlabelled.")
self.warning_printed.add(semantic_id)
return semantic_class_name_to_id()['unlabelled']
return self.key_array[semantic_id]


Expand Down

0 comments on commit dfc5585

Please sign in to comment.