Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cuda for inference in get_similar, add embed and similar scripts,… #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,9 @@ models/
*.pyc
debugs/
*.c


# data
outputs*/
data/*
mlruns/
28 changes: 6 additions & 22 deletions inference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,17 @@ Additional flag can be set `--images-in-subfolders` – only images in subfolder

**NOTE:** at the beggining of the script, there is `exctract_func` specified, which is used to extracy `pair_id` either from filename or from subfolder name. See the examples in the script and customize if needed.

```bash
python inference/create_embeddings.py \
--config_file="configs/256_resnet50.yml" \
GPU_IDS [0] \
DATASETS.ROOT_DIR '/data/my-image-dataset/' \
TEST.IMS_PER_BATCH 128 \
OUTPUT_DIR 'output-dir' \
TEST.ONLY_TEST True \
MODEL.PRETRAIN_PATH "logs/market1501/256_resnet50/train_ctl_model/version_0/checkpoints/epoch=119.ckpt"
```
#from repo root folder
bash test_scripts/embed.sh
```

## Running similarity serach
Example command to run similarity search using pretrained model and query images.
Path to images is controlled by `DATASETS.ROOT_DIR` and may be path to a single image file or to directory, which contains valid images.
Additional flag can be set `--images-in-subfolders` – only images in subfolders in the `DATASETS.ROOT_DIR` will be used.

```bash
python inference/get_similar.py \
--config_file="configs/320_resnet50_ibn_a.yml" \
--gallery_data='output-dir' \
--normalize_features \
--topk=100 \
GPU_IDS [0] \
DATASETS.ROOT_DIR '/data/query-images/' \
TEST.IMS_PER_BATCH 128 \
OUTPUT_DIR 'output-dir' \
TEST.ONLY_TEST True \
MODEL.PRETRAIN_PATH "logs/market1501/256_resnet50/train_ctl_model/version_0/checkpoints/epoch=119.ckpt" \
SOLVER.DISTANCE_FUNC 'cosine'
```
#from repo root folder
bash test_scripts/similar.sh
```
3 changes: 2 additions & 1 deletion inference/get_similar.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@

### Build model
model = CTLModel.load_from_checkpoint(cfg.MODEL.PRETRAIN_PATH)
use_cuda = True if torch.cuda.is_available() and cfg.GPU_IDS else False

### Inference
log.info("Running inference")
embeddings, paths = run_inference(
model, val_loader, cfg, print_freq=args.print_freq
model, val_loader, cfg, print_freq=args.print_freq, use_cuda=use_cuda
)

### Load gallery data
Expand Down
8 changes: 8 additions & 0 deletions test_scripts/embed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
python inference/create_embeddings.py \
--config_file="configs/256_resnet50.yml" \
GPU_IDS [0] \
DATASETS.ROOT_DIR 'data/ugv/' \
TEST.IMS_PER_BATCH 8 \
OUTPUT_DIR 'outputs/' \
TEST.ONLY_TEST True \
MODEL.PRETRAIN_PATH "models/market1501_resnet50_256_128_epoch_120.ckpt"
12 changes: 12 additions & 0 deletions test_scripts/similar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
python inference/get_similar.py \
--config_file="configs/256_resnet50.yml" \
--gallery_data='outputs' \
--normalize_features \
--topk=100 \
GPU_IDS [0] \
DATASETS.ROOT_DIR 'data/ugv/' \
TEST.IMS_PER_BATCH 128 \
OUTPUT_DIR 'outputs' \
TEST.ONLY_TEST True \
MODEL.PRETRAIN_PATH "models/market1501_resnet50_256_128_epoch_120.ckpt" \
SOLVER.DISTANCE_FUNC 'cosine'