CLRerNet Lane Detection

repository·main·Indexed 42 days ago

https://github.com/hirotomusiker/clrernet

Official implementation of a lane detection model that utilizes a novel LaneIoU loss to improve confidence scores, achieving state-of-the-art performance on the CULane benchmark. Built on mmdetection 3.3, the project includes tools for training, inference, and FPS speed testing, with a recommended deployment via Docker.

Tokens
2.2K
Snippets
12
Records
12
Agent score
54%

What's inside CLRerNet

  1. Train CLRerNet on CULane

    main

    To train the model on the CULane dataset, ensure the frame difference .npz file is located at dataset/culane/list/train_diffs.npz. Then, run the training script using the desired configuration file.

    python tools/train.py configs/clrernet/culane/clrernet_culane_dla34.py
  2. Build and run CLRerNet using Docker-Compose

    main

    Use docker-compose to build the development environment with your current user's UID and then run the container. This ensures file permissions are handled correctly within the container.

    docker-compose build --build-arg UID="`id -u`" dev
    docker-compose run --rm dev
  3. Calculate frame differences for training

    main

    To avoid overfitting during training, CLRerNet uses a frame difference calculation to filter out redundant frames. This script outputs an .npz file containing the difference values.

    python tools/calculate_frame_diff.py [culane_root_path]
  4. Prepare pretrained CLRerNet models

    main

    Before running inference or testing, download the pretrained weights for the CULane benchmark. You can choose between the standard CLRerNet or the version with Exponential Moving Average (EMA).

    CLRerNet:

    wget https://github.com/hirotomusiker/CLRerNet/releases/download/v0.1.0/clrernet_culane_dla34.pth

    CLRerNet\u2082 (w/ EMA):

    wget https://github.com/hirotomusiker/CLRerNet/releases/download/v0.1.0/clrernet_culane_dla34_ema.pth
  5. Install Docker-Compose and enable NVIDIA runtime

    main

    If you do not have a docker-compose environment, install it and start the docker service using apt.

    To install the NMS (Non-Maximum Suppression) extension, you must ensure the nvidia runtime is enabled during the build process. This is done by configuring /etc/docker/daemon.json to set nvidia as the default-runtime.

    # Install docker-compose and start service
    sudo apt install docker-compose
    sudo service docker start

    Configure /etc/docker/daemon.json

    { "runtimes": { "nvidia": { "path": "nvidia-container-runtime", "runtimeArgs": [] } }, "default-runtime": "nvidia" }

    Restart docker to apply changes

    sudo systemctl restart docker

  6. Prepare the CULane dataset

    main

    To use the CULane dataset with CLRerNet, you must create a specific directory structure in your home directory and download/extract the required files.

    1. Create the target directory: $HOME/dataset/culane.
    2. Download the dataset files using gdown or from the official Google Drive.
    3. Extract the .tar.gz files into the $HOME/dataset/culane directory.

    The final directory structure should contain the driver_* folders and the list folder.

    # 1. Create directory
    mkdir -p $HOME/dataset/culane && cd $HOME/dataset/culane
    
    # 2. Download files
    gdown "https://drive.google.com/uc?id=1LTdUXzUWcnHuEEAiMoG42oAGuJggPQs8"
    gdown "https://drive.google.com/uc?id=1daWl7XVzH06GwcZtF4WD8Xpvci5SZiUV"
    gdown "https://drive.google.com/uc?id=1Z6a463FQ3pfP54HMwF3QS5h9p2Ch3An7"
    gdown "https://drive.google.com/uc?id=1QbB1TOk9Fy6Sk0CoOsR3V8R56_eG6Xnu"
    gdown "https://drive.google.com/uc?id=18alVEPAMBA9Hpr3RDAAchqSj5IxZNRKd"
    
    # 3. Extract files
    tar xf driver_37_30frame.tar.gz
    tar xf driver_100_30frame.tar.gz
    tar xf driver_193_90frame.tar.gzt
    tar xf annotations_new.tar.gz
    tar xf list.tar.gz
  7. Install CLRerNet using Docker

    main

    The recommended way to install CLRerNet is via a Docker environment. This repository is based on the mmdetection 3.3 environment. If you require the older mmdet2x-based version, you must checkout the v0.2.1 branch.

    To build and run the development environment, use the following commands:

    docker compose build --build-arg UID="`id -u`" dev
    docker compose run --rm dev
  8. Troubleshoot NMS installation failures

    main

    If the NMS extension installation fails during the Docker build process, you can manually install it inside the running container.

    1. Modify the Dockerfile to skip the line: RUN python /tmp/nms/setup.py install.
    2. Build and run the container.
    3. Once inside the container, navigate to the NMS directory and run the installation manually.
    # Inside the container
    cd libs/models/layers/nms/
    python setup.py install
    cd /work
  9. Evaluate CLRerNet on the CULane dataset

    main

    To evaluate the model's performance on the CULane dataset, run the tools/test.py script with the appropriate config and checkpoint files. Ensure you have followed the Dataset Preparation guide first.

    python tools/test.py configs/clrernet/culane/clrernet_culane_dla34_ema.py clrernet_culane_dla34_ema.pth
  10. Run lane detection inference on an image

    main

    To detect lanes in a single image and visualize the results, use the demo/image_demo.py script. You must provide the configuration file, the pretrained checkpoint, and specify an output file path.

    python demo/image_demo.py demo/demo.jpg configs/clrernet/culane/clrernet_culane_dla34_ema.py clrernet_culane_dla34_ema.pth --out-file=result.png
  11. Run speed tests for FPS calculation

    main

    You can calculate the frames per second (FPS) by measuring inference iterations. Use the tools/speed_test.py script, specifying the config, checkpoint, a sample image, and the number of warmup and test iterations.

    python tools/speed_test.py configs/clrernet/culane/clrernet_culane_dla34.py clrernet_culane_dla34.pth --filename demo/demo.jpg --n_iter_warmup 1000 --n_iter_test 10000
  12. Configure the development environment with Docker Compose

    main

    The dev service in docker-compose.yaml provides a development environment with NVIDIA GPU support. It uses a custom Dockerfile located at ./docker/Dockerfile.

    Key configuration details:

    • Runtime: Uses nvidia runtime for GPU acceleration.
    • Shared Memory: shm_size is set to 16gb to support high-performance data loading.
    • Volumes:
      • The current directory is mounted to /work inside the container.
      • The host's $HOME/dataset directory is mounted to /work/dataset inside the container for dataset access.
    • Build Arguments: The image is built with specific versions of Python, PyTorch, and the OpenMMLab ecosystem (MIM, MMCV, MMDetection, MMengine).
    services:
      dev:
        runtime: nvidia
        build:
          context: .
          dockerfile: ./docker/Dockerfile
          args:
            PYTHON_VERSION: 3.11.9
            TORCH_VERSION: 2.1.0
            TORCHVISION_VERSION: 0.16.0
            TORCH_CUDA_ARCH_LIST: 7.5;8.0;8.6;9.0
            MIM_VERSION: 0.3.9
            MMCV_VERSION: 2.1.0
            MMDET_VERSION: 3.3.0
            MMENGINE_VERSION: 0.10.5
        shm_size: "16gb"
        tty: true
        volumes:
          - .:/work
          - $HOME/dataset:/work/dataset