NeuralRecon Documentation

repository·master·Indexed 25 days ago

https://github.com/zju3dv/neuralrecon

NeuralRecon is a system for real-time coherent 3D reconstruction from monocular video, supporting ScanNet and custom ARKit data. The documentation covers installation on Ubuntu 18.04+, data preparation using TSDF Fusion, training phases with GRUFusion, and running inference or real-time demos. It includes instructions for capturing custom video data via the ios_logger app and using the main.py CLI for distributed training and model evaluation.

Tokens
2.3K
Snippets
9
Records
14
Agent score
81%

What's inside NeuralRecon

  1. Train NeuralRecon on ScanNet

    master

    Training is initiated via ./train.sh. The process is divided into two manual phases:

    1. Phase 1 (Epochs 0-20): Training single fragments. Set: MODEL.FUSION.FUSION_ON=False, MODEL.FUSION.FULL=False

    2. Phase 2 (Epochs 21-50): Training with GRUFusion. Set: MODEL.FUSION.FUSION_ON=True, MODEL.FUSION.FULL=True

    Example train.sh content:

    #!/usr/bin/env bash
    export CUDA_VISIBLE_DEVICES=0,1
    python -m torch.distributed.launch --nproc_per_node=2 main.py --cfg ./config/train.yaml
  2. Download Pretrained ScanNet Models

    master

    To use the pretrained weights on ScanNet, download them and place them in PROJECT_PATH/checkpoints/release.

    You can use gdown to download them via command line:

    mkdir checkpoints && cd checkpoints
    gdown --id 1zKuWqm9weHSm98SZKld1PbEddgLOQkQV
  3. Run the NeuralRecon real-time demo

    master

    To run the NeuralRecon demo using captured ARKit data or the provided example data, follow these steps:

    1. Prepare Data: Ensure your data is in the format expected by ios_logger (a fragments.pkl file and an images directory containing .jpg files).
    2. Configure: Update the data path in config/demo.yaml.
    3. Execution: Run the demo.py script pointing to your configuration file.

    Optional Configuration Flags in demo.yaml:

    • VIS_INCREMENTAL: Enable this to see real-time visualization during reconstruction (recommended for local machines).
    • SAVE_INCREMENTAL: Set this to save incremental meshes at each step.
    • REDUCE_GPU_MEM: Disable this flag to achieve maximum inference speed (approximately 3 keyframes/sec speed-up).

    Output: The reconstructed mesh (PLY file) will be saved in the directory specified by the results path (e.g., results/scene_demo_checkpoints_fusion_eval_47). You can view the output using MeshLab.

    python demo.py --cfg ./config/demo.yaml
  4. Install NeuralRecon

    master

    NeuralRecon is recommended for Ubuntu 18.04 and above.

    1. Install system dependencies:
    sudo apt install libsparsehash-dev

    Note: If you lack sudo privileges, you can install sparsehash via conda (included in environment.yaml) and run export CPLUS_INCLUDE_PATH=$CONDA_PREFIX/include before installing torchsparse.

    1. Create the conda environment:
    conda env create -f environment.yaml
    conda activate neucon
    1. Install torchsparse following the official instructions.

    Troubleshooting torchsparse:

    • If you encounter AttributeError: module 'torchsparse_backend' has no attribute 'hash_forward', clone torchsparse locally, remove the build folder, and recompile/reinstall.
    sudo apt install libsparsehash-dev
    conda env create -f environment.yaml
    conda activate neucon
  5. Prepare ScanNet Data

    master

    Before training or inference, you must parse the raw ScanNet data into a processed pickle format and generate ground truth TSDFs using TSDF Fusion.

    Expected Directory Structure:

    DATAROOT
    └───scannet
        │   └───scans
        │       └───scene0000_00
        │           └───color
        │               │   0.jpg
        │               │   1.jpg
        │               ...
        │   └───scans_test
        │       └───scene0707_00
        │           └───color
        │               │   0.jpg
        │               │   1.jpg
        │               ...
        |   └───scannetv2_test.txt
        |   └───scannetv2_train.txt
        |   └───scannetv2_val.txt

    Run Data Preparation: Replace PATH_TO_SCANNET and OUTPUT_PATH with your actual paths.

    For training/val split:

    python tools/tsdf_fusion/generate_gt.py --data_path PATH_TO_SCANNET --save_name all_tsdf_9 --window_size 9

    For test split:

    python tools/tsdf_fusion/generate_gt.py --test --data_path PATH_TO_SCANNET --save_name all_tsdf_9 --window_size 9
    python tools/tsdf_fusion/generate_gt.py --data_path PATH_TO_SCANNET --save_name all_tsdf_9 --window_size 9
  6. Capture custom video data with ARKit

    master

    To capture your own data for NeuralRecon, you need an Apple device (iPhone/iPad) released after 2017 with ARKit support and a Mac for compilation.

    1. Compile ios_logger

    1. Install Xcode on your Mac.
    2. Clone the ios_logger repository:
      git clone https://github.com/Varvrar/ios_logger
    3. Generate a code signing certificate and a provisioning profile using Xcode.
    4. Build and run the app on your device following the ios_logger README instructions.

    2. Data Capture Best Practices

    • Environment: A clean indoor environment is preferred (similar to the ScanNet dataset), though outdoor scenarios are supported.
    • Movement: Move the device frequently to ensure high covisibility across different views of the same location.
    • Retrieval: Once captured, retrieve the saved datasets and transfer them to a GPU-enabled machine (minimum 2GB GPU memory) to run the demo.
    git clone https://github.com/Varvrar/ios_logger
  7. Resume or Load Model Checkpoints

    master

    NeuralRecon supports two ways to load weights during training or testing:

    1. Resuming Training (cfg.RESUME): If cfg.RESUME is enabled, the script automatically searches the cfg.LOGDIR for the latest .ckpt file, loads the model state, optimizer state, and the last epoch to continue training.
    2. Loading a Specific Checkpoint (cfg.LOADCKPT): If cfg.LOADCKPT is a non-empty string, the script loads that specific checkpoint file for the model and optimizer.

    When loading, the script handles map_location to ensure weights are correctly mapped to the current cfg.LOCAL_RANK in distributed settings.

  8. Training and Testing Modes

    master

    The execution flow of main.py is determined by the cfg.MODE configuration value:

    • train mode: Executes the train() function. It initializes the optimizer (Adam), sets up a learning rate scheduler (MultiStepLR), and iterates through the TrainImgLoader to perform gradient descent.
    • test mode: Executes the test() function. It iterates through the TestImgLoader to evaluate the model. If from_latest is set to True, it evaluates using the most recent checkpoint found in cfg.LOGDIR.
  9. Evaluate ScanNet Reconstruction

    master

    To evaluate the model on the ScanNet test-set, use tools/evaluation.py.

    Note on Headless Rendering: If you are running on a headless server, you must set the environment variable PYOPENGL_PLATFORM=osmesa to allow pyrender to work.

    Run Evaluation:

    python tools/evaluation.py --model ./results/scene_scannet_release_fusion_eval_47 --n_proc 16

    Visualize Previous Results: To print the results of a previous evaluation run:

    python tools/visualize_metrics.py --model ./results/scene_scannet_release_fusion_eval_47
    python tools/evaluation.py --model ./results/scene_scannet_release_fusion_eval_47 --n_proc 16
  10. Data format for ARKit captured data

    master

    If you are reusing data captured via ios_logger for other projects, the data follows this structure:

    Directory Structure:

    DATAROOT
    └───fragments.pkl
    └───images
        └───0.jpg
        └───1.jpg
        |   ...

    fragments.pkl Schema: A list of dictionaries, where each dictionary contains:

    • scene: scene_name [str]
    • fragment_id: fragment_id [int]
    • image_ids: image_ids [int]
    • extrinsics: poses [matrix: 4X4]
    • intrinsics: intrinsics [matrix: 3X3]

    Processing code for generating this format can be found in tools/process_arkit_data.py.

    [
    {'scene': scene_name: [str],
    'fragment_id': fragment id: [int],
    'image_ids': image id: [int],
    'extrinsics': poses: [matrix: 4X4],
    'intrinsics': intrinsics: [matrix: 3X3]
    }
    ...
    ]