提交 5b3d4031 编写于 作者: D dongshuilong

fix map minp metric bugs

上级 914e6967
...@@ -41,7 +41,7 @@ class mAP(nn.Layer): ...@@ -41,7 +41,7 @@ class mAP(nn.Layer):
super().__init__() super().__init__()
def forward(self, similarities_matrix, query_img_id, gallery_img_id, def forward(self, similarities_matrix, query_img_id, gallery_img_id,
*args): keep_mask):
metric_dict = dict() metric_dict = dict()
choosen_indices = paddle.argsort( choosen_indices = paddle.argsort(
...@@ -55,8 +55,19 @@ class mAP(nn.Layer): ...@@ -55,8 +55,19 @@ class mAP(nn.Layer):
choosen_label = paddle.index_sample(gallery_labels_transpose, choosen_label = paddle.index_sample(gallery_labels_transpose,
choosen_indices) choosen_indices)
equal_flag = paddle.equal(choosen_label, query_img_id) equal_flag = paddle.equal(choosen_label, query_img_id)
if keep_mask is not None:
keep_mask = paddle.index_sample(
keep_mask.astype('float32'), choosen_indices)
equal_flag = paddle.logical_and(equal_flag,
keep_mask.astype('bool'))
equal_flag = paddle.cast(equal_flag, 'float32') equal_flag = paddle.cast(equal_flag, 'float32')
num_rel = paddle.sum(equal_flag, axis=1)
num_rel = paddle.greater_than(num_rel, paddle.to_tensor(0.))
num_rel_index = paddle.nonzero(num_rel.astype("int"))
num_rel_index = paddle.reshape(num_rel_index, [num_rel_index.shape[0]])
equal_flag = paddle.index_select(equal_flag, num_rel_index, axis=0)
acc_sum = paddle.cumsum(equal_flag, axis=1) acc_sum = paddle.cumsum(equal_flag, axis=1)
div = paddle.arange(acc_sum.shape[1]).astype("float32") + 1 div = paddle.arange(acc_sum.shape[1]).astype("float32") + 1
precision = paddle.divide(acc_sum, div) precision = paddle.divide(acc_sum, div)
...@@ -74,7 +85,7 @@ class mINP(nn.Layer): ...@@ -74,7 +85,7 @@ class mINP(nn.Layer):
super().__init__() super().__init__()
def forward(self, similarities_matrix, query_img_id, gallery_img_id, def forward(self, similarities_matrix, query_img_id, gallery_img_id,
*args): keep_mask):
metric_dict = dict() metric_dict = dict()
choosen_indices = paddle.argsort( choosen_indices = paddle.argsort(
...@@ -87,15 +98,26 @@ class mINP(nn.Layer): ...@@ -87,15 +98,26 @@ class mINP(nn.Layer):
]) ])
choosen_label = paddle.index_sample(gallery_labels_transpose, choosen_label = paddle.index_sample(gallery_labels_transpose,
choosen_indices) choosen_indices)
tmp = paddle.equal(choosen_label, query_img_id) equal_flag = paddle.equal(choosen_label, query_img_id)
tmp = paddle.cast(tmp, 'float64') if keep_mask is not None:
keep_mask = paddle.index_sample(
keep_mask.astype('float32'), choosen_indices)
equal_flag = paddle.logical_and(equal_flag,
keep_mask.astype('bool'))
equal_flag = paddle.cast(equal_flag, 'float64')
num_rel = paddle.sum(equal_flag, axis=1)
num_rel = paddle.greater_than(num_rel, paddle.to_tensor(0.))
num_rel_index = paddle.nonzero(num_rel.astype("int"))
num_rel_index = paddle.reshape(num_rel_index, [num_rel_index.shape[0]])
equal_flag = paddle.index_select(equal_flag, num_rel_index, axis=0)
#do accumulative sum #do accumulative sum
div = paddle.arange(tmp.shape[1]).astype("float64") + 2 div = paddle.arange(equal_flag.shape[1]).astype("float64") + 2
minus = paddle.divide(tmp, div) minus = paddle.divide(equal_flag, div)
auxilary = paddle.subtract(tmp, minus) auxilary = paddle.subtract(equal_flag, minus)
hard_index = paddle.argmax(auxilary, axis=1).astype("float64") hard_index = paddle.argmax(auxilary, axis=1).astype("float64")
all_INP = paddle.divide(paddle.sum(tmp, axis=1), hard_index) all_INP = paddle.divide(paddle.sum(equal_flag, axis=1), hard_index)
mINP = paddle.mean(all_INP) mINP = paddle.mean(all_INP)
metric_dict["mINP"] = mINP.numpy()[0] metric_dict["mINP"] = mINP.numpy()[0]
return metric_dict return metric_dict
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册