| """Resolve per-scene license information for RING trajectory data. |
| |
| Reads scene asset lists and annotation excerpts from a bulk-download directory:: |
| |
| <download_dir>/<task_config>/metadata/ |
| annotations_used.json.gz |
| train_assets.jsonl.gz |
| val_assets.jsonl.gz |
| |
| Objaverse assets (present in annotations_used) are resolved from their |
| ``license_info``. All other assets are treated as THOR / in-house Ai2 assets. |
| |
| Usage:: |
| |
| python license_info.py <download_dir> --split train --house-index 0 |
| python license_info.py <download_dir> --split train --list-all |
| """ |
|
|
| from __future__ import annotations |
|
|
| import argparse |
| import gzip |
| import json |
| import sys |
| from pathlib import Path |
| from typing import Any |
|
|
| DEFAULT_TASK = "ObjectNavType" |
| SPLITS = ("train", "val") |
|
|
| METADATA_FILES = ( |
| "annotations_used.json.gz", |
| "train_assets.jsonl.gz", |
| "val_assets.jsonl.gz", |
| ) |
|
|
| DEFAULT_LICENSE = { |
| "license": "CC-BY-4.0", |
| "license_url": "https://creativecommons.org/licenses/by/4.0/", |
| "creator_name": "Allen Institute for AI (Ai2)", |
| "source": "In-house", |
| } |
|
|
| ATTRIBUTION_TEMPLATE = ( |
| "{assets}" |
| f" by the {DEFAULT_LICENSE['creator_name']}," |
| f" licensed under {DEFAULT_LICENSE['license'].replace('-', ' ')}." |
| ) |
|
|
| ANNOTATION_FIELDS = ( |
| "uid", |
| "size_annotated_by", |
| "synset_labeled_by", |
| "scale_annotated_by", |
| "wn_version", |
| "license_info", |
| ) |
|
|
|
|
| class MetadataStore: |
| """Lazy loader for metadata under <download_dir>/<task_config>/metadata/.""" |
|
|
| def __init__(self, download_dir: Path, task_config: str): |
| self.metadata_dir = download_dir / task_config / "metadata" |
| self._annotations: dict[str, dict[str, Any]] | None = None |
|
|
| missing = [ |
| name for name in METADATA_FILES if not (self.metadata_dir / name).is_file() |
| ] |
| if missing: |
| raise FileNotFoundError( |
| f"Missing metadata file(s) in {self.metadata_dir}: {', '.join(missing)}" |
| ) |
|
|
| @property |
| def annotations(self) -> dict[str, dict[str, Any]]: |
| if self._annotations is None: |
| with gzip.open( |
| self.metadata_dir / "annotations_used.json.gz", "rt", encoding="utf-8" |
| ) as f: |
| self._annotations = json.load(f) |
| return self._annotations |
|
|
| def scene_asset_ids(self, split: str, house_index: int) -> list[str] | None: |
| if split not in SPLITS: |
| raise ValueError(f"split must be one of {SPLITS}, got {split!r}") |
|
|
| path = self.metadata_dir / f"{split}_assets.jsonl.gz" |
| with gzip.open(path, "rt", encoding="utf-8") as f: |
| for line_no, line in enumerate(f): |
| if line_no == house_index: |
| return json.loads(line) |
| raise IndexError( |
| f"house_index {house_index} out of range for {split} " |
| f"(file has {line_no + 1} lines)" |
| ) |
|
|
| def iter_valid_house_indices(self, split: str) -> list[int]: |
| path = self.metadata_dir / f"{split}_assets.jsonl.gz" |
| indices: list[int] = [] |
| with gzip.open(path, "rt", encoding="utf-8") as f: |
| for line_no, line in enumerate(f): |
| if json.loads(line) is not None: |
| indices.append(line_no) |
| return indices |
|
|
| def scene_count(self, split: str) -> int: |
| path = self.metadata_dir / f"{split}_assets.jsonl.gz" |
| with gzip.open(path, "rt", encoding="utf-8") as f: |
| return sum(1 for _ in f) |
|
|
|
|
| def _annotation_excerpt(annotation: dict[str, Any]) -> dict[str, Any]: |
| return {key: annotation.get(key) for key in ANNOTATION_FIELDS} |
|
|
|
|
| def resolve_objaverse_license( |
| asset_id: str, annotation: dict[str, Any] |
| ) -> dict[str, Any]: |
| lic = annotation["license_info"] |
| creator_profile_url = lic.get("creator_profile_url", "") |
| if "sketchfab" not in creator_profile_url: |
| raise ValueError( |
| f"Only sketchfab assets expected for {asset_id=}, " |
| f"got {creator_profile_url=}" |
| ) |
|
|
| cur_license: dict[str, Any] = { |
| "data_type": "objects", |
| "data_source": "objaverse", |
| "asset_id": asset_id, |
| "creator_username": lic["creator_username"], |
| "creator_display_name": lic["creator_display_name"], |
| "creator_profile_url": lic["creator_profile_url"], |
| "source": "Sketchfab", |
| "uri": lic["uri"], |
| "downloaded": "2021-2022", |
| "license_determination": ( |
| "License inferred from Sketchfab designation at time of download " |
| "(circa 2021/2022)." |
| ), |
| "modifications": ( |
| "The model has been significantly modified to reduce memory and " |
| "processing requirements, including mesh decimation, convex collider " |
| "extraction, and baking of visual effects via Blender scripts. " |
| "The provided quality may not reflect the original model." |
| ), |
| "dataset_license": "This subset of Objaverse is licensed under ODC-BY 1.0.", |
| "annotation": _annotation_excerpt(annotation), |
| } |
|
|
| license_code = lic["license"] |
| if license_code == "by": |
| cur_license["license"] = "CC-BY-4.0" |
| cur_license["license_url"] = "https://creativecommons.org/licenses/by/4.0/" |
| cur_license["derivative_notice"] = ( |
| "This work is a derivative of the original model." |
| ) |
| cur_license["attribution"] = ( |
| f"Model by {lic['creator_display_name']} ({lic['creator_username']}), " |
| "licensed under CC BY 4.0." |
| ) |
| elif license_code == "by-sa": |
| cur_license["license"] = "CC-BY-SA-4.0" |
| cur_license["license_url"] = "https://creativecommons.org/licenses/by-sa/4.0/" |
| cur_license["derivative_license"] = ( |
| "This derivative work is licensed under CC BY-SA 4.0." |
| ) |
| cur_license["attribution"] = ( |
| f"Model by {lic['creator_display_name']} ({lic['creator_username']}), " |
| "licensed under CC BY-SA 4.0." |
| ) |
| elif license_code == "cc0": |
| cur_license["license"] = "CC0-1.0" |
| cur_license["license_url"] = ( |
| "https://creativecommons.org/publicdomain/zero/1.0/" |
| ) |
| cur_license["derivative_notice"] = ( |
| "This work is a derivative of the original asset, which was released " |
| "under CC0." |
| ) |
| cur_license["attribution"] = ( |
| f"Model by {lic['creator_display_name']} ({lic['creator_username']}), " |
| "licensed under CC0-1.0." |
| ) |
| elif license_code == "by-nc": |
| cur_license["license"] = "CC-BY-NC-4.0" |
| cur_license["license_url"] = "https://creativecommons.org/licenses/by-nc/4.0/" |
| cur_license["commercial_use"] = False |
| cur_license["derivative_notice"] = ( |
| "This work is a derivative of the original asset and may not be used " |
| "for commercial purposes." |
| ) |
| cur_license["attribution"] = ( |
| f"Model by {lic['creator_display_name']} ({lic['creator_username']}), " |
| "licensed under CC BY-NC 4.0. Non-commercial use only." |
| ) |
| elif license_code == "by-nc-sa": |
| cur_license["license"] = "CC-BY-NC-SA-4.0" |
| cur_license["license_url"] = ( |
| "https://creativecommons.org/licenses/by-nc-sa/4.0/" |
| ) |
| cur_license["commercial_use"] = False |
| cur_license["derivative_license"] = ( |
| "This derivative work is licensed under CC BY-NC-SA 4.0." |
| ) |
| cur_license["derivative_notice"] = ( |
| "This work is a derivative of the original asset and may not be used " |
| "for commercial purposes." |
| ) |
| cur_license["attribution"] = ( |
| f"Model by {lic['creator_display_name']} ({lic['creator_username']}), " |
| "licensed under CC BY-NC-SA 4.0. Non-commercial use only." |
| ) |
| else: |
| raise NotImplementedError(f"Unsupported Sketchfab license {license_code!r}") |
|
|
| return cur_license |
|
|
|
|
| def resolve_thor_license(asset_id: str) -> dict[str, Any]: |
| return { |
| "data_type": "objects", |
| "data_source": "thor", |
| "asset_id": asset_id, |
| **DEFAULT_LICENSE, |
| "attribution": ATTRIBUTION_TEMPLATE.format(assets="Model(s)"), |
| } |
|
|
|
|
| def resolve_object_license( |
| asset_id: str, annotations: dict[str, dict[str, Any]] |
| ) -> dict[str, Any]: |
| annotation = annotations.get(asset_id) |
| if annotation is not None: |
| return resolve_objaverse_license(asset_id, annotation) |
| return resolve_thor_license(asset_id) |
|
|
|
|
| def resolve_scene_license( |
| store: MetadataStore, |
| *, |
| split: str, |
| house_index: int, |
| task_config: str, |
| ) -> dict[str, Any]: |
| asset_ids = store.scene_asset_ids(split, house_index) |
| if asset_ids is None: |
| raise ValueError( |
| f"No house at {split} house_index={house_index} (scene is null)" |
| ) |
|
|
| annotations = store.annotations |
| includes = [ |
| resolve_object_license(asset_id, annotations) for asset_id in sorted(asset_ids) |
| ] |
|
|
| scene_license: dict[str, Any] = { |
| "data_type": "scenes", |
| "data_source": task_config, |
| "split": split, |
| "house_index": house_index, |
| **DEFAULT_LICENSE, |
| "attribution": ATTRIBUTION_TEMPLATE.format(assets="Scene"), |
| "scope": ( |
| "Scene composition, layout, non-object-specific textures, and metadata." |
| ), |
| "relationship_to_assets": "collection", |
| "asset_licenses": ( |
| "Assets are independently licensed; see assets info below for details." |
| ), |
| "license_determination": ( |
| "Scenes are collections referencing independently licensed assets; " |
| f"{DEFAULT_LICENSE['license']} applies only to scene composition, " |
| "layout, and metadata." |
| ), |
| } |
| if includes: |
| scene_license["assets"] = includes |
| return scene_license |
|
|
|
|
| def print_license_info( |
| download_dir: str | Path, |
| *, |
| split: str, |
| house_index: int | str, |
| task_config: str = DEFAULT_TASK, |
| ) -> None: |
| store = MetadataStore(Path(download_dir).resolve(), task_config) |
|
|
| if house_index == "--list_all": |
| for sp in SPLITS: |
| valid = store.iter_valid_house_indices(sp) |
| print(f"{sp}: {len(valid)} valid houses (of {store.scene_count(sp)} lines)") |
| return |
|
|
| license_info = resolve_scene_license( |
| store, |
| split=split, |
| house_index=int(house_index), |
| task_config=task_config, |
| ) |
| print(json.dumps(license_info, indent=2)) |
|
|
|
|
| def main() -> None: |
| parser = argparse.ArgumentParser( |
| description="License information for RING scene houses.", |
| formatter_class=argparse.RawDescriptionHelpFormatter, |
| epilog=( |
| "Examples:\n" |
| " python license_info.py ./ring_download --split train --house-index 0\n" |
| " python license_info.py ./ring_download --split val --list-all\n" |
| ), |
| ) |
| parser.add_argument( |
| "download_dir", |
| type=Path, |
| help="Root directory passed to bulk_download.py.", |
| ) |
| parser.add_argument( |
| "--config", |
| default=DEFAULT_TASK, |
| help=f"Task config subdirectory (default: {DEFAULT_TASK}).", |
| ) |
| parser.add_argument( |
| "--split", |
| choices=SPLITS, |
| default="train", |
| help="Scene split (default: train).", |
| ) |
| group = parser.add_mutually_exclusive_group(required=True) |
| group.add_argument( |
| "--house-index", |
| type=int, |
| help="0-based house index within the split asset list.", |
| ) |
| group.add_argument( |
| "--list-all", |
| action="store_true", |
| help="List valid house counts per split.", |
| ) |
| args = parser.parse_args() |
|
|
| try: |
| if args.list_all: |
| print_license_info( |
| args.download_dir, |
| split=args.split, |
| house_index="--list_all", |
| task_config=args.config, |
| ) |
| else: |
| print_license_info( |
| args.download_dir, |
| split=args.split, |
| house_index=args.house_index, |
| task_config=args.config, |
| ) |
| except (FileNotFoundError, IndexError, ValueError, NotImplementedError) as exc: |
| print(exc, file=sys.stderr) |
| raise SystemExit(1) from exc |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|