# HSA-DINO: Environment Setup & Data Preparation

This guide describes how to configure the OV-DINO environment and prepare datasets.(In the code, SP refers to Scale Prompt, which corresponds to the multi-scale prompt bank (MSPB) described in the paper.
Similarly, asar denotes the adaptive Semantic-Aware Router, equivalent to the SAR module in the paper.)

the MSPB are located in HSA-DINO/ovdino/projects/ovdino/modeling/ovdino_spbank.py, and the SAR module is implemented in codes/HSA-DINO/ovdino/asar.py.
---

## 1. Installation

```bash
# 1. Enter project directory
cd OV-DINO
export root_dir=$(realpath ./)
cd $root_dir/ovdino

# 2. (Optional) Set CUDA_HOME if your CUDA is not 11.6.
export CUDA_HOME="your_cuda11.6_path"
export PATH=$CUDA_HOME/bin:$PATH
export LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH
echo -e "cuda version:\n$(nvcc -V)"

# 3. Create and activate conda env
conda create -n ovdino python=3.9 -y
conda activate ovdino

# 4. Install PyTorch with CUDA 11.6
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia -y

# 5. (Optional) Install gcc 9 for compatibility
conda install gcc=9 gxx=9 -c conda-forge -y

# 6. Install detectron2 (edit path if needed)
python -m pip install -e detectron2-717ab9

# 7. Install OV-DINO
pip install -e ./


## 2. Data Preparation

### COCO Dataset

Download COCO from the official website and place the data under `datas/coco`:

```bash
cd $root_dir
mkdir -p datas/coco
wget http://images.cocodataset.org/zips/train2017.zip -O datas/coco/train2017.zip
wget http://images.cocodataset.org/zips/val2017.zip -O datas/coco/val2017.zip
wget http://images.cocodataset.org/annotations/annotations_trainval2017.zip -O datas/coco/annotations_trainval2017.zip

# Extract the files and remove the zip archives
unzip datas/coco/train2017.zip -d datas/coco
unzip datas/coco/val2017.zip -d datas/coco
unzip datas/coco/annotations_trainval2017.zip -d datas/coco
rm datas/coco/train2017.zip datas/coco/val2017.zip datas/coco/annotations_trainval2017.zip

### Target Datasets

Additional target datasets can be easily downloaded from the following links:

- [Google Drive Download Link](https://drive.google.com/drive/folders/16SDv_V7RDjTKDk8uodL2ubyubYTMdd5q?usp=drive_link)
- [百度云盘下载链接](https://pan.baidu.com/s/1MpTwmJQF6GtmnxauVUPNAw?pwd=ni5j)

> **Note:** If you use these datasets, please remember to cite the corresponding papers.

## 3. Evaluation

Download the pre-trained model from the provided source and place it in the `init` directory.

- [WEIGHT](https://pan.baidu.com/s/1jhQ9Ult8pAjtPd4FtglcxA?pwd=da8d)

To run evaluation, use the following scripts:

```bash
bash scripts/eval_sp_lora_domain_router.sh
bash scripts/eval_sp_lora_coco_router.sh
