| |
| """ |
| Statistics of asset library distribution in different datasets. |
| Analyzes the proportion of 3D assets from different sources. |
| """ |
|
|
| import json |
| import os |
| import sys |
| from pathlib import Path |
| from collections import defaultdict |
|
|
| BASE_PATH = Path("/home/v-meiszhang/backup/datas/InternScenes/Layout_info") |
|
|
| def extract_asset_library(uid): |
| """Extract the asset library name from a model uid.""" |
| if uid.startswith("objaverse/"): |
| return "objaverse" |
| elif uid.startswith("objaverse_old/"): |
| return "objaverse_old" |
| elif uid.startswith("partnet_mobility"): |
| return "partnet_mobility" |
| elif uid.startswith("3D-FUTURE-model"): |
| return "3D-FUTURE-model" |
| elif uid.startswith("hssd-models"): |
| return "hssd-models" |
| elif uid.startswith("gen_assets"): |
| return "gen_assets" |
| elif uid.startswith("gr100"): |
| return "gr100" |
| else: |
| return "unknown" |
|
|
| def process_dataset(dataset_name, dataset_path): |
| """Process a single dataset and return statistics.""" |
| |
| total_instances = 0 |
| library_stats = defaultdict(lambda: {"count": 0, "scenes": set()}) |
| category_stats = defaultdict(lambda: defaultdict(int)) |
| scene_count = 0 |
| scenes_with_instances = 0 |
| |
| |
| if dataset_name == "arkitscenes": |
| |
| search_dirs = [] |
| for split in ["Training", "Validation"]: |
| split_path = dataset_path / split |
| if split_path.exists(): |
| search_dirs.extend(sorted(split_path.iterdir())) |
| else: |
| |
| search_dirs = sorted(dataset_path.iterdir()) |
| |
| |
| for scene_dir in search_dirs: |
| if not scene_dir.is_dir(): |
| continue |
| |
| scene_count += 1 |
| layout_file = scene_dir / "layout.json" |
| |
| if not layout_file.exists(): |
| continue |
| |
| try: |
| with open(layout_file, 'r') as f: |
| data = json.load(f) |
| |
| |
| if isinstance(data, list): |
| instances = data |
| else: |
| instances = data.get("instances", []) |
| |
| if not instances: |
| continue |
| |
| scenes_with_instances += 1 |
| |
| for instance in instances: |
| total_instances += 1 |
| |
| uid = instance.get("model_uid", "") |
| category = instance.get("category", "unknown") |
| |
| if not uid: |
| library = "empty_uid" |
| else: |
| library = extract_asset_library(uid) |
| |
| library_stats[library]["count"] += 1 |
| library_stats[library]["scenes"].add(scene_dir.name) |
| category_stats[library][category] += 1 |
| |
| except Exception as e: |
| print(f" Error {scene_dir.name}: {e}", file=sys.stderr) |
| |
| return { |
| "total_instances": total_instances, |
| "library_stats": library_stats, |
| "category_stats": category_stats, |
| "scene_count": scene_count, |
| "scenes_with_instances": scenes_with_instances |
| } |
|
|
| def print_statistics(dataset_name, stats): |
| """Print statistics for a dataset.""" |
| total_instances = stats["total_instances"] |
| library_stats = stats["library_stats"] |
| category_stats = stats["category_stats"] |
| scene_count = stats["scene_count"] |
| scenes_with_instances = stats["scenes_with_instances"] |
| |
| print("=" * 80) |
| print(f"{dataset_name.upper()} ASSET LIBRARY STATISTICS") |
| print("=" * 80) |
| print() |
| |
| print(f"Total scenes: {scene_count}") |
| print(f"Scenes with instances: {scenes_with_instances}") |
| print(f"Total instances: {total_instances}") |
| print() |
| |
| if total_instances == 0: |
| print("No instances found!") |
| print() |
| return |
| |
| print("-" * 80) |
| print("ASSET LIBRARY DISTRIBUTION") |
| print("-" * 80) |
| print() |
| |
| |
| sorted_libs = sorted(library_stats.items(), key=lambda x: x[1]["count"], reverse=True) |
| |
| print(f"{'Library':<25} {'Count':<10} {'Percentage':<12} {'Scenes':<10}") |
| print("-" * 80) |
| |
| for library, stats_data in sorted_libs: |
| count = stats_data["count"] |
| percentage = 100.0 * count / total_instances if total_instances > 0 else 0 |
| scenes_count = len(stats_data["scenes"]) |
| print(f"{library:<25} {count:<10} {percentage:>10.2f}% {scenes_count:<10}") |
| |
| print("-" * 80) |
| print() |
| |
| |
| print("-" * 80) |
| print("TOP CATEGORIES BY ASSET LIBRARY") |
| print("-" * 80) |
| print() |
| |
| for library, _ in sorted_libs[:8]: |
| categories = category_stats[library] |
| sorted_cats = sorted(categories.items(), key=lambda x: x[1], reverse=True) |
| |
| print(f"{library}:") |
| for category, count in sorted_cats[:5]: |
| percentage = 100.0 * count / library_stats[library]["count"] |
| print(f" - {category:<30} {count:<8} ({percentage:>6.2f}%)") |
| print() |
| |
| print("=" * 80) |
| print() |
|
|
| def main(): |
| datasets = ["scannet", "arkitscenes", "3rscan", "matterport3d"] |
| |
| if len(sys.argv) > 1: |
| |
| datasets = sys.argv[1:] |
| |
| for dataset_name in datasets: |
| dataset_path = BASE_PATH / dataset_name |
| |
| if not dataset_path.exists(): |
| print(f"Warning: {dataset_path} not found, skipping") |
| continue |
| |
| print(f"Processing {dataset_name}...") |
| stats = process_dataset(dataset_name, dataset_path) |
| print_statistics(dataset_name, stats) |
|
|
| if __name__ == "__main__": |
| main() |
|
|