This repository contains the official implementation of CVPR2023 paper "TopDiG: Class-agnostic Topological Directional Graph Extraction from Remote Sensing Images"
[2025/09/10] The training script is released.
- Setting the environment by command:
pip install requirements.txt- Set the config file in /configs and specify config file in the main.py/main_ddp.py. Change ["Model"]["detection_model"] to select different node detection models. The supported models include TCND (standard in this paper), TCSwin (from "UniVecMapper") and FPN.
- Phase 1: Train node detection network.
- In config file, set "pretrain" as 1
- Run:
python main.py
- Phase 2: Train the entire TopDiG:
- In config file, set all parameters from "pretrain" to "evaluate" as 0. specify "Paths":{"pretrained_detection_weight_path"}
- Run:
python main.py
- In config file, set "pretrain" as 0 while "infer_eval" as 1 to conduct inference and accuracy calculation. Specify "Paths":{"pretrained_detection_weight_path", "pretrained_match_weight_path"};
- Run:
python main.py
Experiment:
>>object_type: when set as 'line',extract centerline, otherwise extracting contours
>>save_shp:whether to save results as shapefile. The default is True
>>save_seg:whether to save results as binary mask
>>evaluate:whether to calculate accuracy metrics. If True, the script will firstly saves results as binary mask to SaveRoot and then calculate metrics.
>>dataset_name:dataset name
>>detection_resume:whether to load TCND checkpoints
>>match_resume:whether to load DiG generator checkpoints
Paths:
>>TrainRoot:Trainset path
>>ValRoot:Validset path
>>TestRoot:image path
>>TestLabelRoot:label path
>>SaveRoot:path to save results
>>records_filename:save intermedia outputs
>>pretrained_detection_weight_name: basename of TCND ckecpoint file
>>pretrained_match_weight_name: basename of DiG generator checkpoint file
Model:
>>NUM_POINTS:the total number of detected nodes per image
>>dilate_pixels:for evaluate boundary IoU
>>phi:distance among detected nodes
>>delta:tolarence when match detected and GT nodes
>>num_attention_layers,num_heads, hidden_dim:ViT layer number、head number and hidden dimensions. Recommand 12, 12, 768.
>>Sinkhorn:whether to conduct Sinkhorn. True for polygon shape objects; Flase for line shape objects
Examples for datasets with label:
"TrainRoot": /data02/ybn/Datasets/Building/Inria/train
"TestRoot": /data02/ybn/Datasets/Building/Inria/valid/image
"TestLabelRoot": /data02/ybn/Datasets/Building/Inria/valid/binary_map
If no accuracy evaluation step, this script can run without labels. In this case, set infer=1, infer_eval=0, evaluate=0
Google drive:https://drive.google.com/drive/folders/1E3jNSO8CGl_72V1rq38a-aagGEFL7S6c?usp=drive_link
Baidu drive:https://pan.baidu.com/s/1EddQLzkyWCoqZVFIxIuuAQ (password:yqxa)
The downloaded contents are /records/ which contains checkpoints for Inria, GID and Massachusetts. It should be downloaded to root path (./)
For any inquiries regarding this work, please contact: