# SAMPolyBuild **Repository Path**: labiao/SAMPolyBuild ## Basic Information - **Project Name**: SAMPolyBuild - **Description**: No description available - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-10-15 - **Last Updated**: 2024-12-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SAMPolyBuild Adapting the Segment Anything Model (SAM) for Polygonal Building Extraction ## Installation Conda virtual environment is recommended for installation. Please choose the appropriate version of torch and torchvision according to your CUDA version. ```shell conda create -n sampoly python=3.10 -y source activate sampoly # or conda activate sampoly pip install torch==2.0.0+cu117 torchvision==0.15.1+cu117 --index-url https://download.pytorch.org/whl/cu117 pip install -r requirements.txt ``` Download the SAM vit_b model from [here](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth) and place it in the 'segment_anything' folder. ## Dataset Preparation ### SpaceNet Vegas Dataset We converted the original images of the SpaceNet dataset to 8-bit and the annotations to coco format, and divided them into training, validation, and test sets in the ratio of 8:1:1, which are available for download from [here](https://aistudio.baidu.com/datasetdetail/269168). Place the train, val, test folders in the 'dataset/spacenet' folder. ### Custom Dataset The custom dataset should be in the following format, or change the **train_dataset_pth**, **val_dataset_pth** in the train.py and **dataset_pth** in the test.py to the corresponding path. ``` dataset ├── dataset_name ├── train | ├── images | ├── ann.json ├── val | ├── images | ├── ann.json ├── test ├── images ├── ann.json ``` ## Training Single gpu: ```shell python train.py --config configs/prompt_instance_spacenet.json --gpus 0 ``` Multi gpus: ```shell python train.py --config configs/prompt_instance_spacenet.json --gpus 0 1 --distributed ``` ## Testing Evaluate the model on the test set, and save the results: ```shell python test.py ``` You need to change the **--task_name** to the corresponding training task name, and the other arguments will be set automatically according to training configuration. ## Acknowledgement This project is developed based on the [Segment Anything Model (SAM)](https://github.com/facebookresearch/segment-anything) project. We thank the authors for their contributions. ## License This project is licensed under the [Apache 2.0 license](LICENSE). ## Contact If you have any questions, please contact wangchenhao22@mails.ucas.ac.cn.