Update license_info.py
Browse files34 unmodified lines353637383940411 unmodified line43444546474849505116 unmodified lines686970717273741 unmodified line7677787980818249 unmodified lines13213313413513613713813914014114214334 unmodified lines1781791801811821831842 unmodified lines1871881891901911929 unmodified lines2022032042052062072085 unmodified lines214215216217218219103 unmodified lines32332432532632732837 unmodified lines3663673683693703713723733743753763773783793803813823833843851 unmodified line3873883893903913923932 unmodified lines3963973983994004014024034041 unmodified line40640740840941041141217 unmodified lines4304314324334344353 unmodified lines43944044144244344444544644744844934 unmodified lines@contextmanagerdef stream_pkg(entry: dict, config_name: str, buffer_size: int = 8192, repo_id: str = REPO):"""Streams a single compressed archive (tar.zst) from within a shard using1 unmodified linecontiguously; the entry's offset and size identify the byte range forone archive. This context manager exposes an open tarfile."""url = hf_hub_url(repo_id=repo_id,filename=f"{config_name}/shards/{entry['shard_id']:05d}.tar",repo_type="dataset",revision="main",)16 unmodified linesyield tardef _extract_h5_buffers(entry: dict, config_name: str):"""Streams the archive for the given entry and extracts onlythe h5 buffers, keyed by batch id. Also returns the scene_info string.1 unmodified linescene_info = Nonebatch_to_h5 = {}with stream_pkg(entry, config_name) as tar:for member in tar:if not member.name.endswith(".h5"):continue49 unmodified linesreturn Nonedef iterate_episode_info(entry: dict, config_name: str):"""Yields per-episode obs_scene metadata (config, scene_id, traj_id, etc.)by streaming only the h5 data from the archive."""scene_info, batch_to_h5 = _extract_h5_buffers(entry, config_name)for batch, h5_bytes in batch_to_h5.items():with h5py.File(io.BytesIO(h5_bytes), "r") as f:34 unmodified linesreturn Nonedef resolve_scene_source(scene_idx, scene_objects):"""Finds which molmospaces scene source best matches the given sceneby comparing object sets. Results are cached across calls.2 unmodified linesscene_sources = ["mujoco__scenes__procthor-objaverse-train__20251205","mujoco__scenes__ithor__20251217",]scene_objects = set(scene_objects)9 unmodified lines_CACHED_IDX_TO_ENTRY[source] = {}for entry in ds:stem = entry["path"].split("/")[-1].replace(source_name, "")if "FloorPlan" in stem or "house" in stem or "train" in stem:idx = extract_number_substring(stem)if idx is not None:_CACHED_IDX_TO_ENTRY[source][idx] = entry5 unmodified linesif scene_idx not in _CACHED_IDX_TO_OBJECTS[source]:with stream_pkg(_CACHED_IDX_TO_ENTRY[source][scene_idx],source.replace("__", "/"),repo_id=repo_id,) as tar:103 unmodified linesds = load_dataset(repo_id, name=meta_source, split="pkgs")with stream_pkg(ds[0],meta_source.replace("__", "/"),repo_id=repo_id,) as tar:37 unmodified linesreturn scene_licensedef list_configs():"""Print every config name in the dataset together with its entry count."""for config in TASK_CONFIGS:ds = load_dataset(REPO, name=config, split="pkgs")print(f"{config}: {len(ds)} entries")print("\nUse --config CONFIG --index INDEX to show licenses for a specific entry.")def licenses_for_entry(config_name: str, index: int):"""Print license information for every episode contained in thedataset entry at the given index within the given config."""ds = load_dataset(REPO, name=config_name, split="pkgs")if index < 0 or index >= len(ds):raise IndexError(f"Index {index} out of range for config '{config_name}' "1 unmodified line)entry = ds[index]print(f"Config: {config_name}")print(f"Entry index: {index}")print(f"Path: {entry['path']}")print(2 unmodified linesprint()episode_count = 0for obs_scene in iterate_episode_info(entry, config_name):scene_id = obs_scene["scene_id"]scene_idx = extract_number_substring(scene_id.split("_part")[0])traj_id = obs_scene["traj_id"]added_objects = obs_scene["config"].task_config.added_objectsscene_objects = sorted(1 unmodified line- set(added_objects.keys()))scene_source = resolve_scene_source(scene_idx, scene_objects)episode_id = make_episode_id(config_name, scene_id, traj_id)license_info = resolve_episode_licenses(episode_id, scene_source, scene_idx, added_objects17 unmodified lineschoices=TASK_CONFIGS,help="Config name (task configuration).",)parser.add_argument("--index",type=int,3 unmodified linesargs = parser.parse_args()if args.config is not None and args.index is not None:licenses_for_entry(args.config, args.index)elif args.config is not None or args.index is not None:parser.error("Both --config and --index are required together.")else:list_configs()if __name__ == "__main__":34 unmodified lines35363738394041424344451 unmodified line474849505152535455565758596016 unmodified lines777879808182831 unmodified line8586878889909149 unmodified lines14114214314414514614714814915015115234 unmodified lines1871881891901911921932 unmodified lines1961971981992002012022032042052062079 unmodified lines2172182192202212222232242252262272285 unmodified lines234235236237238239240103 unmodified lines34434534634734834935037 unmodified lines3883893903913923933943953963973983994004014024034044054064071 unmodified line4094104114124134144152 unmodified lines4184194204214224234244254261 unmodified line42842943043143243343417 unmodified lines4524534544554564574584594604614624633 unmodified lines46746846947047147247347447547647734 unmodified lines@contextmanagerdef stream_pkg(entry: dict,split: str | None,config_name: str,buffer_size: int = 8192,repo_id: str = REPO,):"""Streams a single compressed archive (tar.zst) from within a shard using1 unmodified linecontiguously; the entry's offset and size identify the byte range forone archive. This context manager exposes an open tarfile."""if split is None:split = ""else:split = f"{split}_"url = hf_hub_url(repo_id=repo_id,filename=f"{config_name}/{split}shards/{entry['shard_id']:05d}.tar",repo_type="dataset",revision="main",)16 unmodified linesyield tardef _extract_h5_buffers(entry: dict, split: str, config_name: str):"""Streams the archive for the given entry and extracts onlythe h5 buffers, keyed by batch id. Also returns the scene_info string.1 unmodified linescene_info = Nonebatch_to_h5 = {}with stream_pkg(entry, split, config_name) as tar:for member in tar:if not member.name.endswith(".h5"):continue49 unmodified linesreturn Nonedef iterate_episode_info(entry: dict, split: str, config_name: str):"""Yields per-episode obs_scene metadata (config, scene_id, traj_id, etc.)by streaming only the h5 data from the archive."""scene_info, batch_to_h5 = _extract_h5_buffers(entry, split, config_name)for batch, h5_bytes in batch_to_h5.items():with h5py.File(io.BytesIO(h5_bytes), "r") as f:34 unmodified linesreturn Nonedef resolve_scene_source(scene_idx, split: str, scene_objects):"""Finds which molmospaces scene source best matches the given sceneby comparing object sets. Results are cached across calls.2 unmodified linesscene_sources = ["mujoco__scenes__procthor-objaverse-train__20251205","mujoco__scenes__ithor__20251217","mujoco__scenes__procthor-objaverse-val__20251205","mujoco__scenes__procthor-10k-train__20251122","mujoco__scenes__holodeck-objaverse-train__20251217","mujoco__scenes__procthor-10k-val__20251217","mujoco__scenes__holodeck-objaverse-val__20251217","mujoco__scenes__procthor-10k-test__20251121",]scene_objects = set(scene_objects)9 unmodified lines_CACHED_IDX_TO_ENTRY[source] = {}for entry in ds:stem = entry["path"].split("/")[-1].replace(source_name, "")if ("FloorPlan" in stemor "house" in stemor "train" in stemor "val" in stem):idx = extract_number_substring(stem)if idx is not None:_CACHED_IDX_TO_ENTRY[source][idx] = entry5 unmodified linesif scene_idx not in _CACHED_IDX_TO_OBJECTS[source]:with stream_pkg(_CACHED_IDX_TO_ENTRY[source][scene_idx],None,source.replace("__", "/"),repo_id=repo_id,) as tar:103 unmodified linesds = load_dataset(repo_id, name=meta_source, split="pkgs")with stream_pkg(ds[0],None,meta_source.replace("__", "/"),repo_id=repo_id,) as tar:37 unmodified linesreturn scene_licensedef list_configs(split: str):"""Print every config name in the dataset together with its entry count."""for config in TASK_CONFIGS:ds = load_dataset(REPO, name=config, split=f"{split}_pkgs")print(f"{config}: {len(ds)} entries")print("\nUse --config CONFIG --index INDEX to show licenses for a specific entry.")def licenses_for_entry(config_name: str, split: str, index: int):"""Print license information for every episode contained in thedataset entry at the given index within the given config."""ds = load_dataset(REPO, name=config_name, split=f"{split}_pkgs")if index < 0 or index >= len(ds):raise IndexError(f"Index {index} out of range for config '{config_name}' "1 unmodified line)entry = ds[index]print(f"Config: {config_name} {split}")print(f"Entry index: {index}")print(f"Path: {entry['path']}")print(2 unmodified linesprint()episode_count = 0for obs_scene in iterate_episode_info(entry, split, config_name):scene_id = obs_scene["scene_id"]scene_idx = extract_number_substring(scene_id.split("_")[-1])traj_id = obs_scene["traj_id"]added_objects = obs_scene["config"].task_config.added_objectsscene_objects = sorted(1 unmodified line- set(added_objects.keys()))scene_source = resolve_scene_source(scene_idx, split, scene_objects)episode_id = make_episode_id(config_name, scene_id, traj_id)license_info = resolve_episode_licenses(episode_id, scene_source, scene_idx, added_objects17 unmodified lineschoices=TASK_CONFIGS,help="Config name (task configuration).",)parser.add_argument("--split",type=str,default="train",help="Split (one of `train`or `val`)",)parser.add_argument("--index",type=int,3 unmodified linesargs = parser.parse_args()if args.config is not None and args.index is not None:licenses_for_entry(args.config, args.split, args.index)elif args.config is not None or args.index is not None:parser.error("Both --config and --index are required together.")else:list_configs(args.split)if __name__ == "__main__":
license_info.py+46-18