StanfordVL / iGibson

A Simulation Environment to train Robots in Large Realistic Interactive Scenes
http://svl.stanford.edu/igibson
MIT License
643 stars 157 forks source link

Instance segmentation render returns 0 instead of -1 for background #259

Open alanlou opened 2 years ago

alanlou commented 2 years ago

Instance segmentation render returns 0 instead of -1 for background. Additionally, the 4th position of background pixels is 1 (valid) instead of 0 (invalid).

Screenshot from 2022-02-20 14-32-23 [Left to right: viewer, robot rgb renderer, robot ins_seg renderer]

Branch: 9c857db9

Here's code to reproduce the issue:

import os
import time
import numpy as np

import igibson
from igibson.render.mesh_renderer.mesh_renderer_settings import MeshRendererSettings
from igibson.robots import REGISTERED_ROBOTS
from igibson.scenes.igibson_indoor_scene import InteractiveIndoorScene
from igibson.simulator import Simulator
from igibson.utils.constants import MAX_INSTANCE_COUNT
from igibson.utils.utils import parse_config

if __name__ == "__main__":
    # Set up scene.
    s = Simulator(mode="gui_interactive", image_width=512, image_height=512)
    scene = InteractiveIndoorScene(
        "Rs_int",
        load_object_categories=[]
    )
    s.import_scene(scene)

    # Load robot.
    config = parse_config(os.path.join(igibson.configs_path, "robots", "turtlebot.yaml"))
    robot_config = config["robot"]
    robot_name = robot_config.pop("name")
    robot = REGISTERED_ROBOTS[robot_name](**robot_config)
    s.import_object(robot)
    robot.set_position_orientation([0, 0, 0], [0, 0, -0.5, 1])
    robot.reset()
    robot.keep_still()

    # Set viewer.
    s.viewer.initial_pos = [-0.6, 1.1, 1.1]
    s.viewer.initial_view_direction = [0.5, -0.8, -0.3]
    s.viewer.reset_viewer()

    # Keep still.
    for _ in range(5):
        s.step()
        raw_ins_seg = s.renderer.render_robot_cameras(modes=("ins_seg"))[0]
        ins_seg = np.round(raw_ins_seg[:, :, 0:1] * MAX_INSTANCE_COUNT).astype(np.int32)
        bids = s.renderer.get_pb_ids_for_instance_ids(ins_seg)
        print("="*10)
        print("seg:", np.unique(ins_seg))
        print("raw seg last dim:", np.unique(raw_ins_seg[:, :, -1]))
        print("bids:", np.unique(bids))

Output:

seg: [0 2 3 4 5]
raw seg last dim: [1.]
bids: [0 2 3 4 5]
alanlou commented 2 years ago

@fxia22 do you have any insight into this? thanks!