GithubHelp home page GithubHelp logo

Comments (12)

huanghoujing avatar huanghoujing commented on July 20, 2024 1

The core part of the metric code is from open-reid.

Here gallery_ids has shape [num_gallery], indices has shape [num_query, num_gallery], thus gallery_ids[indices] has shape [num_query, num_gallery]. Each row of gallery_ids[indices] is for a query, containing the sorted gallery ids.

query_ids has shape [num_query], thus query_ids[:, np.newaxis] has shape [num_query, 1].

matches = (gallery_ids[indices] == query_ids[:, np.newaxis]) has shape [num_query, num_gallery]. Each row of matches contains True and False values, where True means same id as query.

The part confusing you may be this gallery_ids[indices]. May the following example helps:

from __future__ import print_function
import numpy as np

gallery_ids = np.array([5, 8, 12, 7, 3])
indices = np.array([[0, 1, 3, 4, 2],
                    [1, 3, 0, 2, 4],
                    [1, 0, 3, 4, 2]])
print(gallery_ids[indices])

The result is

[[ 5  8  7  3 12]
 [ 8  7  5 12  3]
 [ 8  5  7  3 12]]

from alignedreid-re-production-pytorch.

yxxxxxxxx avatar yxxxxxxxx commented on July 20, 2024

Thank you for taking time to solve my problem, now I understand your meaning but when I run the following code, the matches always return false.
`
from future import print_function
import numpy as np

gallery_ids = np.array([1, 2, 4, 3, 1])
query_ids = np.array([1, 2, 4, 5, 1])
indices = np.array([[0, 1, 3, 4, 2],
[1, 3, 0, 2, 4],
[1, 0, 3, 4, 2]])
matches = (gallery_ids[indices] == query_ids[:, np.newaxis])
print(matches)
`
the result is only a False. Is this problem caused by my Numpy Version or somgthing else is wrong.thank you!

from alignedreid-re-production-pytorch.

huanghoujing avatar huanghoujing commented on July 20, 2024

I made a mistake in the previous answer. I have updated it now. This line gallery_ids = np.array([5, 8, 12, 7, 3]) is updated.

from alignedreid-re-production-pytorch.

yxxxxxxxx avatar yxxxxxxxx commented on July 20, 2024

Ok I have noticed your error and that's all right. But I found another problem as commented just now ,could you explian this problem for me? Thank you very much.

from alignedreid-re-production-pytorch.

yxxxxxxxx avatar yxxxxxxxx commented on July 20, 2024

Ok. so I should remove the [:, np.newaxis] behind the query_ids?but the code doesn't remove it.

from alignedreid-re-production-pytorch.

huanghoujing avatar huanghoujing commented on July 20, 2024

I gave a wrong example in which the dimension of indices is not consistent with [num_query, num_gallery].

The following one should be practical:

from __future__ import print_function
import numpy as np

gallery_ids = np.array([1, 2, 4, 3, 1])
query_ids = np.array([1, 2, 4])
indices = np.array([[0, 1, 3, 4, 2],
                    [1, 3, 0, 2, 4],
                    [1, 0, 3, 4, 2]])

print(gallery_ids[indices])

print(gallery_ids[indices] == query_ids[:, np.newaxis])

It outputs:

[[1 2 3 1 4]
 [2 3 1 4 1]
 [2 1 3 1 4]]
[[ True False False  True False]
 [ True False False False False]
 [False False False False  True]]

from alignedreid-re-production-pytorch.

yxxxxxxxx avatar yxxxxxxxx commented on July 20, 2024

Thank you very much! I understand this problem!

from alignedreid-re-production-pytorch.

huanghoujing avatar huanghoujing commented on July 20, 2024

You're welcome. The high dimension data, argsort, indexing, etc also confuse me at times.

from alignedreid-re-production-pytorch.

yxxxxxxxx avatar yxxxxxxxx commented on July 20, 2024

Sorry to disturb you again but I am not confused with the code

delta = 1. / (len(index) * repeat)

and what the delta stands for?for the Market1501 dataset the value of delta always equals to 1,so why add delta in the code below
ret[i, k - j] += delta
thank you!

from alignedreid-re-production-pytorch.

huanghoujing avatar huanghoujing commented on July 20, 2024

delta is for the option first_match_break. When analyzing line delta = 1. / (len(index) * repeat), you can just consider repeat == 1, and it becomes delta = 1. / len(index). The * repeat here is just a way of implementing averaging over repeats.

  • If first_match_break is True, the resulting CMC curve for a query is a step function turning from 0 to 1 at the point where the first valid match in gallery list appears.
  • If first_match_break is False, the resulting CMC curve for a query is a staircase function going up by delta wherever a valid match in gallery list appears. This function finally goes up to 1. The delta for a query is 1 / num-of-valid-match.

In the case of Market1501, first_match_break == True, thus delta is not used. The following three lines instead of ret[k - j] += delta are executed.

if first_match_break:
    ret[k - j] += 1
    break

from alignedreid-re-production-pytorch.

yxxxxxxxx avatar yxxxxxxxx commented on July 20, 2024

Hello houjing, now I am reproducing your code on the cuhk03 dataset, now I understand the new protocol which split the training set and testing set which consist of 767 identities and 700 identities respectively. But I want to use the papers protocol which split the dataset once for training and testing, and the gallery includes 200 identities. I have noticed that you use the re_ranking_train_test_split.pkl to produce the partition file. So I wonder if I want to produce the paper's protocol,how or where you get this .pkl file so that I can imitate to get a new .pkl file, for example if there is a script to produce it. thank you!

from alignedreid-re-production-pytorch.

huanghoujing avatar huanghoujing commented on July 20, 2024

Sorry, I do not have this 1267/200 train/test split file.

To generate a train_test_partition_file for this function, you have to know the structure of this .pkl file. It is a dictionary (denoted by train_test_partition in the following) having two keys detected and labeled. The following takes the detected subset as an example. train_test_partition['detected'] is a dictionary with keys train_im_names, query_im_names and gallery_im_names.

If you want to generate a 1267/200 train/test split file, train_test_partition['detected']['train_im_names'] should contain image names of the 1267 ids and train_test_partition['detected']['query_im_names'] + train_test_partition['detected']['gallery_im_names'] should contain image names of the rest 200 ids. Which 1267 ids to select as training ids, and how the test set is split into query and gallery sets are up to you.

from alignedreid-re-production-pytorch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.