spear-sim / spear

SPEAR: A Simulator for Photorealistic Embodied AI Research
MIT License
237 stars 17 forks source link

semantic segmentation is not enabled in `apartment_0000` and `kujiale_0000` scenes #234

Open RachithP opened 1 year ago

RachithP commented 1 year ago

The actors and static mesh components in apartment_0000 and kujiale_0000 scenes do not have semantic tags as part of their tags. These are required to enable semantic segmentation in these scenes. Also, the programmatic way to process these semantic tags, and convert them to custom depth stencil value is missing.

How to reproduce:

mikeroberts3000 commented 1 year ago

We are already requiring the artist to group actors into top-level folders in the World Outliner view, based on their semantic categories. Using folders in the World Outliner view is convenient for editing and debugging, but the folder structure is not available at runtime, so we need to somehow convert the folder structure to tags, and ultimately to custom depth-stencil values.

We could require the artist to do this manually, but that seems error-prone. Instead, we should automate this tagging procedure via a Python script that can be invoked via the command-line, the Unreal console, or via a custom editor button. In principle, this Python script could also be used to set custom depth-stencil values, so we wouldn't need to do it at runtime.

RachithP commented 1 year ago

I agree. Since we cannot obtain the World Outliner view folder structure in runtime, and allowing this process to be manual is error-prone, we can use Python APIs to perform this task. This way we can execute this script on a need-basis, whenever new actors/components are added, and are re-arranged.

Some references:

I've a pseudo code here. One drawback in this code is that we cannot specify different semantic tags for the components under the same actor. This could be a problem for actors that have components merged, yet each component needs to have different semantic tags.

import unreal

editor_subsytem = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
level_actors = editor_subsystem.get_all_level_actors()
for actor in level_actors:
    # get semantic tags 
    actor_path = actor.get_folder_path()
    semantic_tag = actor_path.split('_')[-1]

    # get all staticmeshcomponents
    static_mesh_components = actor.get_components_by_class(unreal.StaticMeshComponent)

    # apply semantic tags to all components
    for component in static_mesh_components:
        component.set_editor_property("component_tags", [semantic_tag])
mikeroberts3000 commented 1 year ago

This sketch is useful, thank you for that.