facebookresearch/ego4d

repository·main·Indexed 20 days ago

https://github.com/facebookresearch/ego4d

A suite of tools for the Ego4D and Ego-Exo4D datasets, featuring CLI downloaders, feature extraction APIs, research code, and video reading abstractions for egocentric video machine learning. Includes support for AWS S3 data retrieval, feature inference using models like SlowFast and MViT, SLURM cluster scheduling, and a COLMAP pipeline for 3D processing.

Tokens
30.4K
Snippets
84
Records
132
Agent score
70%

What's inside ego4d

  1. Overview of the ego4d repository components

    main

    The ego4d repository provides tools for working with the Ego4D and Ego-Exo4D datasets. Key components include:

    • Downloaders:
      • ego4d CLI (command: ego4d) for the Ego4D dataset.
      • egoexo CLI (command: egoexo) for the Ego-Exo4D dataset.
    • Feature Extraction: An API for extracting features, including wrappers for models like Omnivore and SlowFast.
    • Research Tools: Includes dataloaders and research code (e.g., clep for Contrastive Language Ego-centric video Pre-training).
    • Video Reading: A simple API abstracting libraries like TorchAudio and PyAV.
    • Visualization: A visualization engine located in the viz directory.
  2. Overview of the Human Pose Estimation Pipeline steps

    main

    The Human Pose Estimation pipeline follows these logical stages:

    1. Preprocess egoexo data: Includes downloading files, Aria frame extraction, Exo camera frame extraction, and exporting paths/camera calibrations to JSON.
    2. Obtain human bounding boxes: Utilizes Aria trajectory, FasterRCNN, and heuristics.
    3. 2D Pose Detection
    4. Triangulation
    5. Smoothing
  3. Understand the Review Interface structure

    main

    The review interface is a React application built using a create-react-app template with the mephisto-review template.

    If you need to update the interface to integrate upstream changes from the template, you can re-run the create-react-app command and manually migrate the following files/folders:

    • review/src/custom/
    • review/src/index.js
    npx create-react-app review --template mephisto-review
  4. Access Proficiency Scores and Path Drawing data

    main

    For a specific commentary, you can access the proficiency rating (a 1-10 score and text reason) and the drawing/path data.

    1. Locate the data.json file for a specific commentary. The path is typically constructed using the commentary ID: os.path.join(annotation_root, "expert_commentary/", commentary_id, "data.json").
    2. The proficiency key in this JSON contains the performance rating.
    3. The annotations list within this JSON contains events which represent the drawing paths.
    import json
    
    # Assuming 'ann' is an annotation object from the dataset
    data_path = os.path.join(egoexo_annotation_root, "expert_commentary/", ann["commentary"], "data.json")
    data = json.load(open(data_path))
    
    # Access proficiency
    print(data["proficiency"])
    
    # Access drawing events
    for comm in data["annotations"]:
        if len(comm["events"]) > 0:
            print("Found drawing events")
            break
  5. Run the narrations visualization pipeline

    main

    To download and view narrations in the Mephisto review interface, run the following pipeline from the recipes/ folder. This command gathers the first 5 IDs, downloads the corresponding videos, prepares the input, and launches the review server:

    ./1_gather_ids.sh 5 | ./2_dl_videos.sh | ./3_prepare_input.sh | ./4_review.sh

    Prerequisites:

    • Ego4D CLI
    • Mephisto CLI
    • jq (Optional: required only if creating custom input files from the recipes/ folder)
    $ ./1_gather_ids.sh 5 | ./2_dl_videos.sh | ./3_prepare_input.sh | ./4_review.sh
  6. Create a review app using the Mephisto Review template

    main

    The Mephisto Review App is a customizable React template for building data exploration interfaces. It integrates with the mephisto review CLI command to serve a web UI for reviewing datasets.

    Setup Steps

    1. Generate the app: Use create-react-app with the mephisto-review template.

      npx create-react-app my-review --template mephisto-review
    2. Build the app: Navigate to your project directory and build the production assets.

      cd my-review
      yarn build
    3. Run the review command: Pipe your data (CSV or JSONL) into the mephisto review command, pointing it to your build directory. Note: Mephisto must be installed to use this command.

      # For CSV data
      cat sample-data.csv | mephisto review ~/path/to/your/my-review/build --all -o results.csv
      
      # For JSONL data (use the --json flag)
      cat sample-data.jsonl | mephisto review ~/path/to/your/my-review/build --json --all -o results.csv
    4. Review data: Open the URL provided in the terminal (e.g., http://127.0.0.1:5000/) in your browser to interact with the UI prompts. Results will be saved to the file specified by the -o flag.

    npx create-react-app my-review --template mephisto-review
    cd my-review
    yarn build
    cat sample-data.csv | mephisto review ~/path/to/your/my-review/build --all -o results.csv
  7. Use the Ego4D CLI to download datasets

    main

    Use the ego4d command to download specific datasets to a local directory.

    Example: Download full scale videos and annotations for version 2 to ~/ego4d_data:

    ego4d --output_directory="~/ego4d_data" --datasets full_scale annotations --metadata

    If the ego4d command is not in your PATH, you can use the python module syntax:

    python -m ego4d.cli.cli --output_directory="~/ego4d_data" --datasets full_scale annotations --metadata --version v2
  8. Run the Ego4D visualization interface

    main

    The easiest way to launch the review interface is using the run_viz.sh script located in the repository root. This script installs the ego4d viz dataset and launches the interface.

    Prerequisites:

    1. Install Mephisto: pip install mephisto
    2. Install the Ego4D CLI.

    Configuration: If your videos or the viz dataset are not located in the default directory (~ ano4d_data), you must update the VID_ROOT configuration. You can modify configuration options by passing flags to the script or by examining the script's contents.

    ./run_viz.sh
  9. Install the ego4d Python module

    main

    You can install the ego4d module using either PyPi or by cloning the repository. Ensure you are using Python 3.10 or higher. It is highly recommended to use a conda or pyenv environment.

    ### Option 1: From the PyPi package
    
    ```bash
    pip install ego4d --upgrade

    Option 2: Clone/Download the Code

    Step 1: Create or Use an Environment

    conda create -n ego4d python=3.11 -y
    conda activate ego4d

    Step 2: Install from source

    pip install .
  10. Customize the Mephisto Review interface layout

    main

    To change how data is displayed, modify index.js in your generated app. The interface is controlled via two main components under the / route:

    1. Customize the Collection Layout (<CollectionView />)

    Located around line 35 of index.js. This controls the layout for all data.

    • pagination (boolean): Set to false to disable pagination (defaults to true).
    • resultsPerPage (integer): Adjust the number of items shown per page.
    • collectionRenderer (React component): A custom component to render the entire collection. It receives two props:
      • items: An array of all review items.
      • itemRenderer: A component used to render individual items within the collection.
    • itemRenderer (React component): Passed to AllItemView to customize how individual items appear within the collection. It receives an item prop containing the JSON data and an id (the 0-indexed position).

    2. Customize Individual Item Views (<ItemView />)

    Located around line 24 of index.js. This controls the layout for specific item views.

    • itemRenderer (React component): A custom component to render the item. It receives an item prop containing:
      • The JSON data properties of the review item.
      • id: The 0-indexed position of the item in the review data.