diff --git a/README.md b/README.md index 5b78186..2753df1 100644 --- a/README.md +++ b/README.md @@ -11,27 +11,61 @@ Nearest neighbors are traditionally used to compute final decisions, e.g., in Su Download pretrained models for CUB-200, Cars-196, and Dogs-120 at [this link](https://drive.google.com/drive/folders/1pC_5bEi5DryDZCaKb51dzCE984r8EnqW?usp=sharing). -## Sampling → Training → Binary classify +## Training image comparator network + For CUB-200, -> sh cub_run.sh + +Step 1: Set `global_training_type = 'CUB'` and `self.set = 'train'` in `params.py` + +Step 2: +> sh train_cub.sh For Cars-196, -> sh cars_run.sh + +Step 1: Set `global_training_type = 'CARS'` and `self.set = 'train'` in `params.py` + +Step 2: +> sh train_cars.sh + For Dogs-120, -> sh dogs_run.sh -Notes: Set `global_training_type` to = `'CUB'` or `'CARS'` or `'DOGS'` +Step 1: Set `global_training_type = 'DOGS'` and `self.set = 'train'` in `params.py` + +Step 2: +> sh train_dogs.sh + +## Testing (Binary classification and Reranking) + +For CUB-200, + +Step 1: Set `global_training_type = 'CUB'` and `self.set = 'test'` in `params.py` + +Step 2: +> sh test_cub.sh + +For Cars-196, + +Step 1: Set `global_training_type = 'CARS'` and `self.set = 'test'` in `params.py` +Step 2: +> sh test_cars.sh -## Reranking +For Dogs-120, -> python cub_extract_feature_for_reranking.py +Step 1: Set `global_training_type = 'DOGS'` and `self.set = 'test'` in `params.py` -> python cub_reranking.py +Step 2: +> sh test_dogs.sh ## How to visualize qualitative figures +For CUB-120, + +Step 1: Set `global_training_type = 'CUB'` and `self.set = 'test'` in `params.py` + +Step 2: + 1. Corrections of S > python cub_visualize_corrections.py 2. Training pairs of S @@ -40,20 +74,3 @@ Notes: Set `global_training_type` to = `'CUB'` or `'CARS'` or `'DOGS'` > python cub_infer.py Same steps for Cars-196 and Dogs-120. - -[//]: # () -[//]: # (### RN50 image comparator improving NTSNet) - -[//]: # (Set NTSNET in params.py to True. Then set MODEL1_RESNET in cub_extract_feature_adv_process.py to False then run:) - -[//]: # (> python cub_extract_feature_adv_process.py) - -[//]: # () -[//]: # (Then set MODEL1_RESNET in cub_advising_process.py to False then run:) - -[//]: # (> python cub_advising_process.py) - -[//]: # () -[//]: # (You can also set PRODUCT_OF_EXPERTS in cub_advising_process.py to True/False to use/not use the product of experts.) - -[//]: # () diff --git a/cars-196/car_image_comparator_training.py b/cars-196/car_image_comparator_training.py index 4e7d2b8..75b102f 100644 --- a/cars-196/car_image_comparator_training.py +++ b/cars-196/car_image_comparator_training.py @@ -288,11 +288,10 @@ def train_model(model, loss_func, optimizer, scheduler, num_epochs=25): config=config, ) -wandb.save(os.path.basename(__file__), policy='now') -wandb.save('../params.py', policy='now') -wandb.save('../datasets.py', policy='now') -wandb.save('car_image_comparator_training.py', policy='now') -wandb.save('../transformer.py', policy='now') +wandb.save(f'{RunningParams.prj_dir}/params.py') +wandb.save(f'{RunningParams.prj_dir}/datasets.py') +wandb.save('car_image_comparator_training.py') +wandb.save(f'{RunningParams.prj_dir}/transformer.py') _, best_acc = train_model( MODEL2, diff --git a/cub-200/cub_image_comparator_training.py b/cub-200/cub_image_comparator_training.py index ddd5acb..d4a4c25 100644 --- a/cub-200/cub_image_comparator_training.py +++ b/cub-200/cub_image_comparator_training.py @@ -275,11 +275,10 @@ def train_model(model, loss_func, optimizer, scheduler, num_epochs=25): config=config, ) -wandb.save(os.path.basename(__file__), policy='now') -wandb.save('../params.py', policy='now') -wandb.save('../datasets.py', policy='now') -wandb.save('cub_image_comparator_training.py', policy='now') -wandb.save('../transformer.py', policy='now') +wandb.save(f'{RunningParams.prj_dir}/params.py') +wandb.save(f'{RunningParams.prj_dir}/datasets.py') +wandb.save('cub_image_comparator_training.py') +wandb.save(f'{RunningParams.prj_dir}/transformer.py') if RunningParams.VisionTransformer is True: _, best_acc = train_model( diff --git a/cub_run.sh b/cub_run.sh deleted file mode 100644 index a38da2f..0000000 --- a/cub_run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -#python cub-200/cub_extract_feature.py # sampling -#python cub-200/augment_images.py -CUDA_VISIBLE_DEVICES=4,5 python cub-200/cub_image_comparator_training.py # train -CUDA_VISIBLE_DEVICES=4 python cub-200/cub_binary_classify.py # test \ No newline at end of file diff --git a/dogs_run.sh b/dogs_run.sh deleted file mode 100644 index 31003f5..0000000 --- a/dogs_run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -python stanford-dogs/dogs_extract_feature.py -python stanford-dogs/augment_images.py -python stanford-dogs/dogs_image_comparator_training.py # train -python stanford-dogs/dogs_binary_classify.py # test \ No newline at end of file diff --git a/params.py b/params.py index 01e1c93..95487e7 100644 --- a/params.py +++ b/params.py @@ -17,7 +17,7 @@ def __init__(self, training_type=None): # Retrieving NNs and sample positive and negative pairs # Set it when you extract the NNs. data_dir is the folder containing query images for KNN retrieval # Set it when you run train/test - self.set = 'test' + self.set = 'train' self.parent_dir = '/home/giang/Downloads' self.prj_dir = '/home/giang/Downloads/advising_network' diff --git a/stanford-dogs/dogs_image_comparator_training.py b/stanford-dogs/dogs_image_comparator_training.py index 928b0e6..cb8e0dc 100644 --- a/stanford-dogs/dogs_image_comparator_training.py +++ b/stanford-dogs/dogs_image_comparator_training.py @@ -283,11 +283,10 @@ def train_model(model, loss_func, optimizer, scheduler, num_epochs=25): config=config, ) -wandb.save(os.path.basename(__file__), policy='now') -wandb.save(f'{RunningParams.prj_dir}/params.py', policy='now') -wandb.save(f'{RunningParams.prj_dir}/datasets.py', policy='now') -wandb.save('dogs_image_comparator_training.py', policy='now') -wandb.save(f'{RunningParams.prj_dir}/transformer.py', policy='now') +wandb.save(f'{RunningParams.prj_dir}/params.py') +wandb.save(f'{RunningParams.prj_dir}/datasets.py') +wandb.save('dogs_image_comparator_training.py') +wandb.save(f'{RunningParams.prj_dir}/transformer.py') if RunningParams.VisionTransformer is True: _, best_acc = train_model( diff --git a/test_cars.sh b/test_cars.sh new file mode 100644 index 0000000..1b3f286 --- /dev/null +++ b/test_cars.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +CUDA_VISIBLE_DEVICES=4 python cars-196/car_extract_feature.py # sampling for test set +python cars-196/augment_images.py +CUDA_VISIBLE_DEVICES=4 python cars-196/car_binary_classify.py # binary classification + +CUDA_VISIBLE_DEVICES=4 python cars-196/car_extract_feature_for_reranking.py # sampling for reranking +CUDA_VISIBLE_DEVICES=4,5 python cars-196/car_reranking.py # reranking \ No newline at end of file diff --git a/test_cub.sh b/test_cub.sh new file mode 100644 index 0000000..2cf2ce9 --- /dev/null +++ b/test_cub.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +CUDA_VISIBLE_DEVICES=4 python cub-200/cub_extract_feature.py # sampling for test set +python cub-200/augment_images.py +CUDA_VISIBLE_DEVICES=4 python cub-200/cub_binary_classify.py # binary classification + +CUDA_VISIBLE_DEVICES=4 python cub-200/cub_extract_feature_for_reranking.py # sampling for reranking +CUDA_VISIBLE_DEVICES=4,5 python cub-200/cub_reranking.py # reranking \ No newline at end of file diff --git a/test_dogs.sh b/test_dogs.sh new file mode 100644 index 0000000..9a3007d --- /dev/null +++ b/test_dogs.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +CUDA_VISIBLE_DEVICES=4 python stanford-dogs/dogs_extract_feature.py # sampling for test set +python stanford-dogs/augment_images.py +CUDA_VISIBLE_DEVICES=4 python stanford-dogs/dogs_binary_classify.py # binary classification + +CUDA_VISIBLE_DEVICES=4 python stanford-dogs/dogs_extract_feature_for_reranking.py # sampling for reranking +CUDA_VISIBLE_DEVICES=4,5 python stanford-dogs/dogs_reranking.py # reranking \ No newline at end of file diff --git a/cars_run.sh b/train_cars.sh similarity index 52% rename from cars_run.sh rename to train_cars.sh index 26596ca..5ac1273 100644 --- a/cars_run.sh +++ b/train_cars.sh @@ -2,7 +2,6 @@ rm -rf /home/giang/Downloads/Cars/Stanford-Cars-dataset/train/ cp -r /home/giang/Downloads/Cars/Stanford-Cars-dataset/BACKUP/train /home/giang/Downloads/Cars/Stanford-Cars-dataset/train/ -python CUDA_VISIBLE_DEVICES=4 cars-196/car_extract_feature.py +CUDA_VISIBLE_DEVICES=4 python cars-196/car_extract_feature.py python cars-196/augment_images.py -python CUDA_VISIBLE_DEVICES=4,5 cars-196/car_image_comparator_training.py # train -python CUDA_VISIBLE_DEVICES=4 cars-196/car_binary_classify.py # test \ No newline at end of file +CUDA_VISIBLE_DEVICES=4,5 python cars-196/car_image_comparator_training.py # train \ No newline at end of file diff --git a/train_cub.sh b/train_cub.sh new file mode 100644 index 0000000..08ced66 --- /dev/null +++ b/train_cub.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +CUDA_VISIBLE_DEVICES=4 python cub-200/cub_extract_feature.py # sampling +python cub-200/augment_images.py +CUDA_VISIBLE_DEVICES=4,5 python cub-200/cub_image_comparator_training.py # train diff --git a/train_dogs.sh b/train_dogs.sh new file mode 100644 index 0000000..1e9fcf3 --- /dev/null +++ b/train_dogs.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +CUDA_VISIBLE_DEVICES=4 python stanford-dogs/dogs_extract_feature.py +python stanford-dogs/augment_images.py +CUDA_VISIBLE_DEVICES=4,5 python stanford-dogs/dogs_image_comparator_training.py # train