提交 017b7b3a 编写于 作者: W Wei Shengyu

Merge branch 'PaddlePaddle:develop_reg' into develop_reg

...@@ -148,9 +148,9 @@ Infer: ...@@ -148,9 +148,9 @@ Infer:
Metric: Metric:
Train: Train:
- Topk: - TopkAcc:
k: [1, 5] topk: [1, 5]
Eval: Eval:
- Topk: - TopkAcc:
k: [1, 5] topk: [1, 5]
# global configs # global configs
Trainer:
name: TrainerReID
Global: Global:
checkpoints: null checkpoints: null
pretrained_model: null pretrained_model: null
...@@ -16,8 +14,7 @@ Global: ...@@ -16,8 +14,7 @@ Global:
# used for static mode and model export # used for static mode and model export
image_shape: [3, 224, 224] image_shape: [3, 224, 224]
save_inference_dir: "./inference" save_inference_dir: "./inference"
num_split: 1 eval_mode: "retrieval"
feature_normalize: True
# model architecture # model architecture
Arch: Arch:
...@@ -99,10 +96,10 @@ DataLoader: ...@@ -99,10 +96,10 @@ DataLoader:
loader: loader:
num_workers: 6 num_workers: 6
use_shared_memory: False use_shared_memory: False
Eval:
Query: Query:
# TOTO: modify to the latest trainer # TOTO: modify to the latest trainer
dataset: dataset:
name: "VeriWild" name: "VeriWild"
image_root: "/work/dataset/VeRI-Wild/images" image_root: "/work/dataset/VeRI-Wild/images"
cls_label_path: "/work/dataset/VeRI-Wild/train_test_split/test_3000_id_query.txt" cls_label_path: "/work/dataset/VeRI-Wild/train_test_split/test_3000_id_query.txt"
...@@ -114,18 +111,18 @@ DataLoader: ...@@ -114,18 +111,18 @@ DataLoader:
mean: [0.485, 0.456, 0.406] mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225] std: [0.229, 0.224, 0.225]
order: '' order: ''
sampler: sampler:
name: DistributedBatchSampler name: DistributedBatchSampler
batch_size: 64 batch_size: 64
drop_last: False drop_last: False
shuffle: False shuffle: False
loader: loader:
num_workers: 6 num_workers: 6
use_shared_memory: False use_shared_memory: False
Gallery: Gallery:
# TOTO: modify to the latest trainer # TOTO: modify to the latest trainer
dataset: dataset:
name: "VeriWild" name: "VeriWild"
image_root: "/work/dataset/VeRI-Wild/images" image_root: "/work/dataset/VeRI-Wild/images"
cls_label_path: "/work/dataset/VeRI-Wild/train_test_split/test_3000_id.txt" cls_label_path: "/work/dataset/VeRI-Wild/train_test_split/test_3000_id.txt"
...@@ -137,15 +134,21 @@ DataLoader: ...@@ -137,15 +134,21 @@ DataLoader:
mean: [0.485, 0.456, 0.406] mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225] std: [0.229, 0.224, 0.225]
order: '' order: ''
sampler: sampler:
name: DistributedBatchSampler name: DistributedBatchSampler
batch_size: 64 batch_size: 64
drop_last: False drop_last: False
shuffle: False shuffle: False
loader: loader:
num_workers: 6 num_workers: 6
use_shared_memory: False use_shared_memory: False
Metric:
Eval:
- Recallk:
topk: [1, 5]
- mAP: {}
Infer: Infer:
infer_imgs: "docs/images/whl/demo.jpg" infer_imgs: "docs/images/whl/demo.jpg"
batch_size: 10 batch_size: 10
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
import numpy as np import numpy as np
import paddle import paddle
import paddle.nn as nn import paddle.nn as nn
from functools import lru_cache
# TODO: fix the format # TODO: fix the format
...@@ -38,23 +39,13 @@ class TopkAcc(nn.Layer): ...@@ -38,23 +39,13 @@ class TopkAcc(nn.Layer):
class mAP(nn.Layer): class mAP(nn.Layer):
def __init__(self, max_rank=50): def __init__(self):
super().__init__() super().__init__()
self.max_rank = max_rank
def forward(self, similarities_matrix, query_img_id, gallery_img_id): def forward(self, similarities_matrix, query_img_id, gallery_img_id):
metric_dict = dict() metric_dict = dict()
num_q, num_g = similarities_matrix.shape _, all_AP, _ = get_metrics(similarities_matrix, query_img_id,
q_pids = query_img_id.numpy().reshape((query_img_id.shape[0])) gallery_img_id)
g_pids = gallery_img_id.numpy().reshape((gallery_img_id.shape[0]))
if num_g < self.max_rank:
self.max_rank = num_g
print('Note: number of gallery samples is quite small, got {}'.
format(num_g))
indices = paddle.argsort(
similarities_matrix, axis=1, descending=True).numpy()
_, all_AP, _ = get_metrics(indices, num_q, num_g, q_pids, g_pids,
self.max_rank)
mAP = np.mean(all_AP) mAP = np.mean(all_AP)
metric_dict["mAP"] = mAP metric_dict["mAP"] = mAP
...@@ -62,23 +53,13 @@ class mAP(nn.Layer): ...@@ -62,23 +53,13 @@ class mAP(nn.Layer):
class mINP(nn.Layer): class mINP(nn.Layer):
def __init__(self, max_rank=50): def __init__(self):
super().__init__() super().__init__()
self.max_rank = max_rank
def forward(self, similarities_matrix, query_img_id, gallery_img_id): def forward(self, similarities_matrix, query_img_id, gallery_img_id):
metric_dict = dict() metric_dict = dict()
num_q, num_g = similarities_matrix.shape _, _, all_INP = get_metrics(similarities_matrix, query_img_id,
q_pids = query_img_id.numpy().reshape((query_img_id.shape[0])) gallery_img_id)
g_pids = gallery_img_id.numpy().reshape((gallery_img_id.shape[0]))
if num_g < self.max_rank:
max_rank = num_g
print('Note: number of gallery samples is quite small, got {}'.
format(num_g))
indices = paddle.argsort(
similarities_matrix, axis=1, descending=True).numpy()
_, _, all_INP = get_metrics(indices, num_q, num_g, q_pids, g_pids,
self.max_rank)
mINP = np.mean(all_INP) mINP = np.mean(all_INP)
metric_dict["mINP"] = mINP metric_dict["mINP"] = mINP
...@@ -86,34 +67,37 @@ class mINP(nn.Layer): ...@@ -86,34 +67,37 @@ class mINP(nn.Layer):
class Recallk(nn.Layer): class Recallk(nn.Layer):
def __init__(self, max_rank=50, topk=(1, 5)): def __init__(self, topk=(1, 5)):
super().__init__() super().__init__()
self.max_rank = max_rank
assert isinstance(topk, (int, list)) assert isinstance(topk, (int, list))
if isinstance(topk, int): if isinstance(topk, int):
topk = [topk] topk = [topk]
self.topk = topk self.topk = topk
self.max_rank = max(self.topk) if max(self.topk) > 50 else 50
def forward(self, similarities_matrix, query_img_id, gallery_img_id): def forward(self, similarities_matrix, query_img_id, gallery_img_id):
metric_dict = dict() metric_dict = dict()
num_q, num_g = similarities_matrix.shape all_cmc, _, _ = get_metrics(similarities_matrix, query_img_id,
q_pids = query_img_id.numpy().reshape((query_img_id.shape[0])) gallery_img_id, self.max_rank)
g_pids = gallery_img_id.numpy().reshape((gallery_img_id.shape[0]))
if num_g < self.max_rank:
max_rank = num_g
print('Note: number of gallery samples is quite small, got {}'.
format(num_g))
indices = paddle.argsort(
similarities_matrix, axis=1, descending=True).numpy()
all_cmc, _, _ = get_metrics(indices, num_q, num_g, q_pids, g_pids,
self.max_rank)
for k in self.topk: for k in self.topk:
metric_dict["recall{}".format(k)] = all_cmc[k - 1] metric_dict["recall{}".format(k)] = all_cmc[k - 1]
return metric_dict return metric_dict
def get_metrics(indices, num_q, num_g, q_pids, g_pids, max_rank=50): @lru_cache()
def get_metrics(similarities_matrix, query_img_id, gallery_img_id,
max_rank=50):
num_q, num_g = similarities_matrix.shape
q_pids = query_img_id.numpy().reshape((query_img_id.shape[0]))
g_pids = gallery_img_id.numpy().reshape((gallery_img_id.shape[0]))
if num_g < max_rank:
max_rank = num_g
print('Note: number of gallery samples is quite small, got {}'.format(
num_g))
indices = paddle.argsort(
similarities_matrix, axis=1, descending=True).numpy()
all_cmc = [] all_cmc = []
all_AP = [] all_AP = []
all_INP = [] all_INP = []
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册