Skip to content

Commit

Permalink
added scene_graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesKrW committed Apr 9, 2024
1 parent b2b24f5 commit b912ff8
Show file tree
Hide file tree
Showing 7 changed files with 551 additions and 0 deletions.
Empty file.
53 changes: 53 additions & 0 deletions igibson/scene_graphs/behavior_demo_sg_exporter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import argparse
import os

import h5py

import igibson
from igibson.examples.behavior.behavior_demo_batch import behavior_demo_batch
from igibson.scene_graphs.graph_exporter import SceneGraphExporter


def parse_args():
testdir = os.path.join(igibson.ig_dataset_path, "tests")
manifest = os.path.join(testdir, "test_manifest.txt")
parser = argparse.ArgumentParser(description="Build live scene graphs from BEHAVIOR demos in manifest.")
parser.add_argument(
"--demo_root", type=str, default=testdir, help="Directory containing demos listed in the manifest."
)
parser.add_argument(
"--log_manifest", type=str, default=manifest, help="Plain text file consisting of list of demos to replay."
)
parser.add_argument("--out_dir", type=str, default=testdir, help="Directory to store results in.")
parser.add_argument("--num_frames_per_demo", type=int, default=None, help="Number of frames to save per demo.")
return parser.parse_args()


def main():
args = parse_args()

def get_scene_graph_callbacks(demo_name, out_dir):
path = os.path.join(out_dir, demo_name + "_sg_data.hdf5")
h5py_file = h5py.File(path, "w")
extractors = [SceneGraphExporter(h5py_file, full_obs=True, num_frames_to_save=args.num_frames_per_demo)]

return (
[extractor.start for extractor in extractors],
[extractor.step for extractor in extractors],
[lambda a, b: h5py_file.close()],
[],
)

behavior_demo_batch(
args.demo_root,
args.log_manifest,
args.out_dir,
get_scene_graph_callbacks,
image_size=(640, 720),
ignore_errors=True,
debug_display=False,
)


if __name__ == "__main__":
main()
53 changes: 53 additions & 0 deletions igibson/scene_graphs/behavior_demo_to_scene_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import argparse
import os

import igibson
from igibson.examples.behavior.behavior_demo_batch import behavior_demo_batch
from igibson.scene_graphs.graph_builder import SceneGraphBuilderWithVisualization


def parse_args():
testdir = os.path.join(igibson.ig_dataset_path, "tests")
manifest = os.path.join(testdir, "test_manifest.txt")
parser = argparse.ArgumentParser(description="Build live scene graphs from BEHAVIOR demos in manifest.")
parser.add_argument(
"--demo_root", type=str, default=testdir, help="Directory containing demos listed in the manifest."
)
parser.add_argument(
"--log_manifest", type=str, default=manifest, help="Plain text file consisting of list of demos to replay."
)
parser.add_argument("--out_dir", type=str, default=testdir, help="Directory to store results in.")
return parser.parse_args()


def main():
args = parse_args()

def get_scene_graph_callbacks(demo_name, out_dir):
path = os.path.join(out_dir, demo_name)
if not os.path.exists(path):
os.mkdir(path)
graph_builder = SceneGraphBuilderWithVisualization(
show_window=False, out_path=path, only_true=True, realistic_positioning=True
)

return (
[graph_builder.start],
[graph_builder.step],
[],
[],
)

behavior_demo_batch(
args.demo_root,
args.log_manifest,
args.out_dir,
get_scene_graph_callbacks,
image_size=(640, 720),
ignore_errors=False,
debug_display=False,
)


if __name__ == "__main__":
main()
61 changes: 61 additions & 0 deletions igibson/scene_graphs/enum_obj_states.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from enum import Enum


class UnaryStatesEnum(Enum):
Burnt = 0
CleaningTool = 1
HeatSourceOrSink = 2
Cooked = 3
Dusty = 4
Frozen = 5
Open = 6
Sliced = 7
Slicer = 8
Soaked = 9
Stained = 10
ToggledOn = 11
WaterSource = 12
InFOVOfRobot = 13
InHandOfRobot = 14
InReachOfRobot = 15
InSameRoomAsRobot = 16


# Temperture and max temperature are not included


class BinaryStatesEnum(Enum):
InRoom = 0
Inside = 1
NextTo = 2
OnFloor = 3
OnTop = 4
Touching = 5
Under = 6


# Not in use, we use binary InRoom for these
class RoomStatesEnum(Enum):
IsInBathroom = 0
IsInBedroom = 1
IsInChildsRoom = 2
IsInCloset = 3
IsInCorridor = 4
IsInDiningRoom = 5
IsInEmptyRoom = 6
IsInExerciseRoom = 7
IsInGarage = 8
IsInHomeOffice = 9
IsInKitchen = 10
IsInLivingRoom = 11
IsInLobby = 12
IsInPantryRoom = 13
IsInPlayroom = 14
IsInStaircase = 15
IsInStorageRoom = 16
IsInTelevisionRoom = 17
IsInUtilityRoom = 18
IsInBalcony = 19
IsInLibrary = 20
IsInAuditorium = 21
IsInUndefined = 22
Loading

0 comments on commit b912ff8

Please sign in to comment.