Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyengiangbkhn committed Feb 5, 2024
1 parent 7a4cf22 commit 3004d69
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 56 deletions.
67 changes: 42 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.)

[//]: # ()
9 changes: 4 additions & 5 deletions cars-196/car_image_comparator_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions cub-200/cub_image_comparator_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 0 additions & 6 deletions cub_run.sh

This file was deleted.

6 changes: 0 additions & 6 deletions dogs_run.sh

This file was deleted.

2 changes: 1 addition & 1 deletion params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 4 additions & 5 deletions stanford-dogs/dogs_image_comparator_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions test_cars.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions test_cub.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions test_dogs.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions cars_run.sh → train_cars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
CUDA_VISIBLE_DEVICES=4,5 python cars-196/car_image_comparator_training.py # train
5 changes: 5 additions & 0 deletions train_cub.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions train_dogs.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3004d69

Please sign in to comment.