### Setup Conda Environment and Install Dependencies Source: https://github.com/mrzilinxiao/longcontextreranker/blob/master/README.md Create and activate a new conda environment, then install project dependencies from requirements.txt. ```bash conda create -n locore python=3.9 conda activate locore pip install -r requirements.txt ``` -------------------------------- ### Prepare TopK Global Indices for Reranking Source: https://github.com/mrzilinxiao/longcontextreranker/blob/master/README.md Generate topk indices for various datasets. Replace 'data_dir' in the script with your actual data directory. This step is crucial before performing reranking. ```bash PYTHONPATH=. python extract/prepare_topk_global.py --dataset gldv2-train --desc_name dinov2 ``` ```bash PYTHONPATH=. python extract/prepare_topk_global.py --dataset roxford5k+1m --desc_name dinov2 ``` ```bash PYTHONPATH=. python extract/prepare_topk_global.py --dataset rparis6k+1m --desc_name dinov2 ``` ```bash PYTHONPATH=. python extract/prepare_topk_global.py --dataset roxford5k --desc_name dinov2 ``` ```bash PYTHONPATH=. python extract/prepare_topk_global.py --dataset rparis6k --desc_name dinov2 ``` -------------------------------- ### Train LOCORE Model Source: https://github.com/mrzilinxiao/longcontextreranker/blob/master/README.md Initiate the training process for the LOCORE model. Ensure Longformer weights and local features paths are correctly set. This command uses distributed training and specifies various hyperparameters for the training process. ```bash torchrun --nproc-per-node=8 train_ames.py \ --output_dir ./checkpoints/dinov2_locore_base \ --use_pretrained True \ --language_model_name ./longformer-base-5120 \ --num_train_epochs 3 \ --per_device_train_batch_size 8 \ --per_device_eval_batch_size 4 \ --gradient_accumulation_steps 4 \ --evaluation_strategy "no" \ --save_strategy "steps" \ --save_steps 1000 \ --save_total_limit 99 \ --learning_rate 5e-5 \ --weight_decay 0. \ --lr_scheduler_type constant \ --logging_steps 10 \ --dataloader_num_workers 4 \ --log_on_each_node False \ --shuffle_pos True \ --ddp_find_unused_parameters False \ --query_global_attention True \ --gradient_checkpointing True \ --local_dim 768 \ --global_dim 768 \ --local_hdf5_path /workspace/ames/my_data/gldv2-train/dinov2_local.hdf5 \ --nn_ids_path /workspace/ames/my_data/gldv2-train/nn_dinov2.pkl \ --sample_txt_path /workspace/ames/my_data/gldv2-train/train_750k.txt \ --global_pt_path /workspace/ames/my_data/gldv2-train/dinov2_global.pt \ --num_descriptors 48 ``` -------------------------------- ### Perform Sliding Window Reranking with Selected Parameters Source: https://github.com/mrzilinxiao/longcontextreranker/blob/master/README.md Execute the reranking process using the selected alpha and temperature values. This command enables hard negative mining, includes 1M data, and specifies the sliding window reranking type. ```bash python eval_revisitop.py \ --checkpoint_path ./checkpoints/dinov2_locore_base \ --device cuda:0 --alpha 0.5 --temp 0.1 --with_hard --with_1m --sliding_reranking_type end-to-start ``` -------------------------------- ### Evaluate LOCORE Model on GLDv2 Validation Set Source: https://github.com/mrzilinxiao/longcontextreranker/blob/master/README.md Run the evaluation script to perform a grid search for the best alpha and temperature parameters on the GLDv2 validation set. This step is essential for selecting optimal hyperparameters before final reranking. ```bash python eval_revisitop.py \ --checkpoint_path ./checkpoints/dinov2_locore_base \ --device cuda:0 --gldv2_val ``` -------------------------------- ### Extract DINOv2 Local Features for Datasets Source: https://github.com/mrzilinxiao/longcontextreranker/blob/master/README.md Use this script to extract DINOv2 local features. Ensure the detector model path and dataset paths are correctly specified. This is necessary for the model to operate on local features. ```bash CUDA_VISIBLE_DEVICES=0 PYTHONPATH=. python extract/extract_descriptors.py \ --detector /scratch/zx51/ames/networks/dinov2_detector.pt \ --save_path /scratch/zx51/ames/my_data/ \ --data_path /scratch/zx51/google-landmark \ --file_name /scratch/zx51/ames/data/gldv2/train_750k.txt \ --backbone dinov2 \ --dataset gldv2_train \ --topk 100 \ --imsize 770 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.