Skip to content

Commit

Permalink
update ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Heaven authored and Tom Heaven committed Jan 12, 2020
1 parent 7378841 commit 486e0a2
Show file tree
Hide file tree
Showing 147 changed files with 7,098 additions and 756 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.idea
__pycache__
.DS_Store
.vscode
csrc/eval_cylib/*.so
logs/
.ipynb_checkpoints
dist_mats
submit
third_party
*.out
Empty file modified README.md
100755 → 100644
Empty file.
86 changes: 0 additions & 86 deletions aligned_resnet101.log

This file was deleted.

Empty file modified config/__init__.py
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions config/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
# List of the dataset names for testing
_C.DATASETS.TEST_NAMES = "market1501"
_C.DATASETS.ROOT_DIR = ('/Volumes/Data/比赛/行人重识别2019/data')
_C.DATASETS.PRELOAD_IMAGE = True # 是否将图像加载到内存
_C.DATASETS.PRELOAD_IMAGE = True # 是否将图像加载到内存

# -----------------------------------------------------------------------------
# DataLoader
Expand Down Expand Up @@ -173,4 +173,4 @@
# ---------------------------------------------------------------------------- #
# Misc options
# ---------------------------------------------------------------------------- #
_C.OUTPUT_DIR = "/Volumes/Data/比赛/行人重识别2019/logs/"
_C.OUTPUT_DIR = "/Volumes/Data/比赛/行人重识别2019/logs/"
Empty file modified configs/softmax.yml
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion configs/softmax_triplet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SOLVER:
EVAL_PERIOD: 10

TEST:
IMS_PER_BATCH: 64
IMS_PER_BATCH: 8
WEIGHT: "path"


Expand Down
2 changes: 1 addition & 1 deletion configs/softmax_triplet_resnext.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SOLVER:
EVAL_PERIOD: 10

TEST:
IMS_PER_BATCH: 32
IMS_PER_BATCH: 16
WEIGHT: "path"


Expand Down
Empty file modified csrc/eval_cylib/Makefile
100755 → 100644
Empty file.
Empty file modified csrc/eval_cylib/__init__.py
100755 → 100644
Empty file.
Empty file modified csrc/eval_cylib/eval_metrics_cy.c
100755 → 100644
Empty file.
Empty file modified csrc/eval_cylib/eval_metrics_cy.pyx
100755 → 100644
Empty file.
Empty file modified csrc/eval_cylib/setup.py
100755 → 100644
Empty file.
Empty file modified csrc/eval_cylib/test_cython.py
100755 → 100644
Empty file.
Empty file modified data/__init__.py
100755 → 100644
Empty file.
Empty file modified data/build.py
100755 → 100644
Empty file.
Empty file modified data/collate_batch.py
100755 → 100644
Empty file.
Empty file modified data/datasets/__init__.py
100755 → 100644
Empty file.
Empty file modified data/datasets/bases.py
100755 → 100644
Empty file.
20 changes: 17 additions & 3 deletions data/datasets/competition1910.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

from .bases import ImageDataset

def argsort(seq):
# http://stackoverflow.com/questions/3071415/efficient-method-to-calculate-the-rank-vector-of-a-list-in-python
return sorted(range(len(seq)), key=seq.__getitem__)


class Competition1910(ImageDataset):
"""
Expand All @@ -34,8 +38,8 @@ def __init__(self, root, test_phase=False, **kwargs):
self.query_dir = osp.join(self.dataset_dir, 'myval_query')
self.gallery_dir = osp.join(self.dataset_dir, 'myval_gallery')
else:
#self.train_dir = osp.join(self.dataset_dir, 'mytrain')
self.train_dir = osp.join(root, self.test_data_dir, 'myquery') # not used
self.train_dir = osp.join(self.dataset_dir, 'mytrain') # not used
#self.train_dir = osp.join(root, self.test_data_dir, 'mytrain') # not used
self.query_dir = osp.join(root, self.test_data_dir, 'myquery')
self.gallery_dir = osp.join(root, self.test_data_dir, 'mygallery')

Expand Down Expand Up @@ -70,9 +74,10 @@ def _process_dir(self, dir_path, relabel=False):
#print('dir_path', dir_path, 'img_paths', len(img_paths), img_paths[0])
#pattern = re.compile(r'([-\d]+)_c(\d)')


DEBUG = False
if DEBUG:
img_paths = img_paths[:200]
img_paths = img_paths[:1000]

pid_container = set()
for img_path in img_paths:
Expand All @@ -84,10 +89,13 @@ def _process_dir(self, dir_path, relabel=False):
pid2label = {pid: label for label, pid in enumerate(pid_container)}

dataset = []

original_filenames = []
for img_path in img_paths:
#pid, camid = map(int, pattern.search(img_path).groups())
pid = int(img_path.split('/')[-1].split('_')[0])
camid = int(img_path.split('/')[-1].split('_')[1][:-4])
original_filenames.append(img_path.split('/')[-1].split('_')[1])

if pid == -1:
continue # junk images are just ignored
Expand All @@ -98,4 +106,10 @@ def _process_dir(self, dir_path, relabel=False):
if relabel: pid = pid2label[pid]
dataset.append((img_path, pid, camid))

# sort dataset items according to filename in ascending order
idx = argsort(original_filenames)
dataset = [dataset[i] for i in idx]

#print('dataset', dataset[:10])

return dataset
Empty file modified data/datasets/cuhk03.py
100755 → 100644
Empty file.
Empty file modified data/datasets/deprecated/bases.py
100755 → 100644
Empty file.
Empty file modified data/datasets/deprecated/bases_bak.py
100755 → 100644
Empty file.
Empty file modified data/datasets/deprecated/dataset_loader_bak.py
100755 → 100644
Empty file.
Empty file modified data/datasets/dukemtmcreid.py
100755 → 100644
Empty file.
Empty file modified data/datasets/eval_reid.py
100755 → 100644
Empty file.
Empty file modified data/datasets/eval_threshold.py
100755 → 100644
Empty file.
Empty file modified data/datasets/market1501.py
100755 → 100644
Empty file.
Empty file modified data/datasets/msmt17.py
100755 → 100644
Empty file.
Empty file modified data/samplers/__init__.py
100755 → 100644
Empty file.
Empty file modified data/transforms/__init__.py
100755 → 100644
Empty file.
Empty file modified data/transforms/build.py
100755 → 100644
Empty file.
Empty file modified data/transforms/functional.py
100755 → 100644
Empty file.
Empty file modified data/transforms/transforms.py
100755 → 100644
Empty file.
Empty file modified demo.py
100755 → 100644
Empty file.
85 changes: 40 additions & 45 deletions engine/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from data.datasets.eval_reid import evaluate
from data.prefetcher import data_prefetcher
from utils.re_ranking import re_ranking, compute_distmat_using_gpu
from utils.distance import low_memory_local_dist
from utils.distance import low_memory_local_dist, fast_local_dist
import h5py
import time

Expand Down Expand Up @@ -340,47 +340,37 @@ def compute_distmat(cfg, num_query, feats, feats_flipped, local_feats, local_fea
local_distmat1 = None
local_distmat2 = None

aligned = True

if use_rerank:
#print('len(local_feats)', len(local_feats))
if len(local_feats) > 0 and use_local_feature:
# if True:
# calculate the local distance
lqf = lqf.permute(0, 2, 1)
lgf = lgf.permute(0, 2, 1)
local_qg_distmat = low_memory_local_dist(lqf.numpy(), lgf.numpy(), aligned=True)
local_qq_distmat = low_memory_local_dist(lqf.numpy(), lqf.numpy(), aligned=True)
local_gg_distmat = low_memory_local_dist(lgf.numpy(), lgf.numpy(), aligned=True)
local_distmat1 = np.concatenate(
[np.concatenate([local_qq_distmat, local_qg_distmat], axis=1),
np.concatenate([local_qg_distmat.T, local_gg_distmat], axis=1)],
axis=0)
del local_qg_distmat, local_qq_distmat, local_gg_distmat
local_distmat1 = fast_local_dist(lqf.numpy(), lgf.numpy(), aligned=aligned)
del lqf, lgf

query_num = qf.size(0)
gallery_num = gf.size(0)

distmat = compute_distmat_using_gpu(qf, gf)
distmat1 = re_ranking(distmat, query_num, gallery_num, k1=6, k2=2, lambda_value=0.3,
local_distmat=local_distmat1,
theta_value=theta,
distmat = compute_distmat_using_gpu(qf, gf, local_distmat1, theta=theta)
distmat1 = re_ranking(distmat, query_num, gallery_num, k1=12, k2=2, lambda_value=0.3,
#local_distmat=local_distmat1,
#theta_value=theta,
only_local=False)
del distmat, local_distmat1

if len(local_feats) > 0 and use_local_feature:
# flipped
lqf = lqf_flipped.permute(0, 2, 1)
lgf = lgf_flipped.permute(0, 2, 1)
local_qg_distmat = low_memory_local_dist(lqf.numpy(), lgf.numpy(), aligned=True)
local_qq_distmat = low_memory_local_dist(lqf.numpy(), lqf.numpy(), aligned=True)
local_gg_distmat = low_memory_local_dist(lgf.numpy(), lgf.numpy(), aligned=True)
local_distmat2 = np.concatenate(
[np.concatenate([local_qq_distmat, local_qg_distmat], axis=1),
np.concatenate([local_qg_distmat.T, local_gg_distmat], axis=1)],
axis=0)
del local_qg_distmat, local_qq_distmat, local_gg_distmat

distmat = compute_distmat_using_gpu(qf_flipped, gf_flipped)
distmat2 = re_ranking(distmat, query_num, gallery_num, k1=6, k2=2, lambda_value=0.3, local_distmat=local_distmat2, theta_value=theta,
only_local=False) # (current best)
local_distmat2 = fast_local_dist(lqf.numpy(), lgf.numpy(), aligned=aligned)
del lqf, lgf, lqf_flipped, lgf_flipped

distmat = compute_distmat_using_gpu(qf_flipped, gf_flipped, local_distmat2, theta=theta)
distmat2 = re_ranking(distmat, query_num, gallery_num, k1=12, k2=2, lambda_value=0.3, only_local=False) # (current best)
del distmat, local_distmat2
distmat = (distmat1 + distmat2) / 2

Expand Down Expand Up @@ -435,11 +425,19 @@ def inference_aligned_flipped(
if len(ret) == 4:
gf, bn_gf, lf, bn_lf = ret
gff, bn_gff, lff, bn_lff = ret_flip
else:
elif len(ret) == 2:
gf, bn_gf = ret
gff, bn_gff = ret_flip
lf, bn_lf = None, None
lff, bn_lff = None, None
elif ret is not tuple:
gf = bn_gf = ret
gff = bn_gff = ret_flip
lf, bn_lf = None, None
lff, bn_lff = None, None
else:
# print('ret', ret.size())
raise Exception("Unknown model returns, length = ", len(ret))

# 4 features
gfs.append(gf.cpu())
Expand Down Expand Up @@ -471,30 +469,27 @@ def inference_aligned_flipped(
g_pids = np.asarray(pids[num_query:])
g_camids = np.asarray(camids[num_query:])

logger.info(f"use_cross_feature = {use_cross_feature}, use_local_feature = {use_local_feature}, use_rerank = {use_rerank}")
logger.info(f"use_local_feature = {use_local_feature}, use_rerank = {use_rerank}")

if use_cross_feature:
logger.info("Computing distmat with bn_gf (+ lf)")
distmat2 = compute_distmat(cfg, num_query, bn_gfs, bn_gfs_flipped, lfs, lfs_flipped, theta=0.45,

logger.info("Computing distmat with bn_gf")
distmat2 = compute_distmat(cfg, num_query, bn_gfs, bn_gfs_flipped, lfs, lfs_flipped, theta=0.45,
use_local_feature=use_local_feature, use_rerank=use_rerank)
distmat = distmat2
#distmat = (distmat1 + distmat2) / 2
else:
logger.info("Computing distmat with gf + bn_lf")
distmat1 = compute_distmat(cfg, num_query, gfs, gfs_flipped, bn_lfs, bn_lfs_flipped, theta=0.95,


logger.info("Computing distmat with gf + bn_lf")
distmat1 = compute_distmat(cfg, num_query, gfs, gfs_flipped, bn_lfs, bn_lfs_flipped, theta=0.95,
use_local_feature=use_local_feature, use_rerank=use_rerank)
distmat = distmat1
#distmat1 = None
#distmat2 = None

#distmat = original_distmat
#distmat[:, new_gallery_index] = distmat1 - 100
for theta in np.linspace(0, 1, 21):
#theta = 0.55
distmat = distmat1 * (1 - theta) + distmat2 * theta

cmc, mAP = evaluate(distmat, q_pids, g_pids, q_camids, g_camids)
logger.info(f"mAP: {mAP:.1%}")
for r in [1, 5, 10]:
logger.info(f"CMC curve, Rank-{r:<3}:{cmc[r - 1]:.1%}")
logger.info(f"Score: {(mAP + cmc[0]) / 2.:.1%}")
cmc, mAP = evaluate(distmat, q_pids, g_pids, q_camids, g_camids)
logger.info(f"theta: {theta:.2%} mAP: {mAP:.1%}")
for r in [1, 5, 10]:
logger.info(f"CMC curve, Rank-{r:<3}:{cmc[r - 1]:.1%}")
logger.info(f"Score: {(mAP + cmc[0]) / 2.:.1%}")



Expand Down
Loading

0 comments on commit 486e0a2

Please sign in to comment.