Skip to content

LINEA: Fast and accurate line detection using scalable transformers

License

Notifications You must be signed in to change notification settings

SebastianJanampa/LINEA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LINEA: Fast and accurate line detection using scalable transformers

colab colab

đź“„ This is the official implementation of the paper:
LINEA: Fast and accurate line detection using scalable transformers

Sebastian Janampa and Marios Pattichis

The University of New Mexico
Department of Electrical and Computer Engineering

LINEA is a powerful real-time line detector that introduces Line Attention mechanism, achieving outstanding performance without being pretrained on COCO or Object365 datasets.

Attention Mechanishm

We compare line attention with traditional attention and deformable attention. We highlight two advantages of our proposed mechanism:

  • Line attention is a sparse mechanism like deformable attention. This significantly reduces memory complexity.
  • Line attention pays attention to the line endpoints like traditional attention but also attends locations between the endpoints.

🚀 Updates

đź“ť TODO

  • Upload paper (currently under review)
  • Upload requirements
  • Upload LINEA weigths.
  • Create HuggingFace 🤗 space.
  • Create Collab demo.

Model Zoo

Wireframe

Model Dataset AP5 AP10 AP15 #Params Latency GFLOPs config checkpoint
LINEA‑N Wireframe 58.7 65.0 67.9 3.9M 2.54ms 12.1 py 65.0
LINEA‑S Wireframe 58.4 64.7 67.6 8.6M 3.08ms 31.7 py 64.7
LINEA‑M Wireframe 59.5 66.3 69.1 13.5M 3.87ms 45.6 py 66.3
LINEA‑L Wireframe 61.0 67.9 70.8 25.2M 5.78ms 83.8 py 67.9

YorkUrban

Model Dataset AP5 AP10 AP15 #Params Latency GFLOPs config checkpoint
LINEA‑N YorkUrban 27.3 30.5 32.5 3.9M 2.54ms 12.1 py 65.0
LINEA‑S YorkUrban 28.9 32.6 34.8 8.6M 3.08ms 31.7 py 64.7
LINEA‑M YorkUrban 30.3 34.5 36.7 13.5M 3.87ms 45.6 py 66.3
LINEA‑L YorkUrban 30.9 34.9 37.3 25.2M 5.78ms 83.8 py 67.9

Notes:

  • Latency is evaluated on a single NVIDIA RTX A5500 GPU with $batch\_size = 1$, $fp16$, and $TensorRT==10.5.0$.

Quick start

Open In Colab Open in Spaces

Setup

conda create -n linea python=3.11.9
conda activate linea
pip install -r requirements.txt

Data Preparation

Wireframe Dataset

TODO

YorkUrban Dataset TODO

Usage

Wireframe
  1. Set Model
export model=l  # n s m l
  1. Training
CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --master_port=7777 --nproc_per_node=4 main.py -c configs/linea/linea_hgnetv2_${model}.py --coco_path data/wireframe_processed --amp 
  1. Testing
CUDA_VISIBLE_DEVICES=0 torchrun --master_port=7777 --nproc_per_node=1 main.py -c configs/linea/linea_hgnetv2_${model}.py --coco_path data/wireframe_processed --amp  --eval --resume <checkpoit.pth>
  1. Replicate results (optional)
# First, download the official weights
wget https://github.com/SebastianJanampa/storage/releases/download/LINEA/linea_hgnetv2_${model}.pth

# Second, run test
CUDA_VISIBLE_DEVICES=0 torchrun --master_port=7777 --nproc_per_node=1 main.py -c configs/linea/linea_hgnetv2_${model}.py --coco_path data/wireframe_processed --amp  --eval --resume linea_hgnetv2_${model}.pth
YorkUrban
  1. Set Model
export model=l  # n s m l
  1. Testing
CUDA_VISIBLE_DEVICES=0 torchrun --master_port=7777 --nproc_per_node=1 main.py -c configs/linea/linea_hgnetv2_${model}.py --coco_path data/york_processed --amp  --eval --resume linea_hgnetv2_${model}.pth
  1. Replicate results (optional)
# First, download the official weights
wget https://github.com/SebastianJanampa/storage/releases/download/LINEA/linea_hgnetv2_${model}.pth

# Second, run test
CUDA_VISIBLE_DEVICES=0 torchrun --master_port=7777 --nproc_per_node=1 main.py -c configs/linea/linea_hgnetv2_${model}.py --coco_path data/york_processed --amp  --eval --resume linea_hgnetv2_${model}.pth
Customizing Batch Size

For example, if you want to train with a total batch size of 16 when training LINEA-L on Wireframe:

CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --master_port=7777 --nproc_per_node=4 main.py -c configs/linea/linea_hgnetv2_l.py --coco_path data/wireframe_processed --amp --options batch_size_train=16
Customizing Input Size

If you'd like to train LINEA-L on Wireframe with an input size of 320x320 (we only support square shapes):

CUDA_VISIBLE_DEVICES=0 torchrun --master_port=7777 --nproc_per_node=1 main.py -c configs/linea/linea_hgnetv2_l.py --coco_path data/wireframe_processed --amp --options eval_spatial_size=320,320

or

CUDA_VISIBLE_DEVICES=0 torchrun --master_port=7777 --nproc_per_node=1 main.py -c configs/linea/linea_hgnetv2_l.py --coco_path data/wireframe_processed --amp --options eval_spatial_size=320
Multiple Costumizations

If you'd like to train LINEA-L on Wireframe with an input size of 480x480 and a total batch size of 4:

CUDA_VISIBLE_DEVICES=0 torchrun --master_port=7777 --nproc_per_node=1 main.py -c configs/linea/linea_hgnetv2_l.py --coco_path data/wireframe_processed --amp --options eval_spatial_size=320 batch_size_train=4

Tools

Deployment
  1. Setup
pip install onnx onnxsim
export model=l  # n s m l
  1. Export onnx
python tools/deployment/export_onnx.py --check -c configs/linea/linea_hgnetv2_${model}_coco.yml -r linea_hgnetv2_${model}.pth
  1. Export tensorrt For a specific file
trtexec --onnx="model.onnx" --saveEngine="model.engine" --fp16

or, for all files inside a folder

python export_tensorrt.py
Inference (Visualization)
  1. Setup
pip install -r tools/inference/requirements.txt
export model=l  # n s m l
  1. Inference (onnxruntime / tensorrt / torch)

Inference on images and videos is supported.

For a single file

python tools/inference/onnx_inf.py --onnx model.onnx --input example/example1.jpg  
python tools/inference/trt_inf.py --trt model.engine --input example/example1.jpg
python tools/inference/torch_inf.py -c configs/linea/linea_hgnetv2_${model}.yml -r <checkpoint.pth> --input example/example1.jpg --device cuda:0

For a folder

python tools/inference/onnx_inf.py --onnx model.onnx --input example  
python tools/inference/trt_inf.py --trt model.engine --input example
python tools/inference/torch_inf.py -c configs/linea/linea_hgnetv2_${model}.yml -r linea_hgnetv2_${model}t.pth --input example --device cuda:0
Benchmark
  1. Setup
pip install -r tools/benchmark/requirements.txt
export model=l  # n s m l
  1. Model FLOPs, MACs, and Params
python tools/benchmark/get_info.py --config configs/linea/linea_hgnetv2_${model}.py 
  1. TensorRT Latency
python tools/benchmark/trt_benchmark.py --infer_dir ./data/wireframe_processed/val2017 --engine_dir trt_engines
  1. Pytorch Latency
python tools/benchmark/torch_benchmark.py -c ./configs/linea/linea_hgnetv2_${model}.py --resume linea_hgnetv2_${model}.pth --infer_dir ./data/wireframe_processed/val2017
Visualization: Line attention
python tools/visualization/line_attention.py -c ./configs/linea/linea_hgnetv2_${model}.py --resume linea_hgnetv2_${model}.pth --data-path ./data/wireframe_processed -d cuda --num_images 10
Visualization: Feature maps from the backbone and encoder
python tools/visualization/backbone_encoder.py -c ./configs/linea/linea_hgnetv2_${model}.py --resume linea_hgnetv2_${model}.pth --data-path ./data/wireframe_processed -d cuda --num_images 10

Citation

If you use LINEA or its methods in your work, please cite the following BibTeX entries:

bibtex
TODO

Acknowledgement

Our work is built upon DT-LSD and D-FINE. Thanks to the inspirations from DT-LSD, D-FINE, RT-DETR, and LETR.

✨ Feel free to contribute and reach out if you have any questions! ✨

About

LINEA: Fast and accurate line detection using scalable transformers

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published