GithubHelp home page GithubHelp logo

how to use your cmc.py about dgd_person_reid HOT 7 CLOSED

cysu avatar cysu commented on August 19, 2024
how to use your cmc.py

from dgd_person_reid.

Comments (7)

Cysu avatar Cysu commented on August 19, 2024

Suppose you have 3 gallery samples with ID 0,1,1 and 4 probe samples with ID 0,0,1,1, then you need to

  • Compute 3x4 pairwise distance matrix D, where D[i, j] = distance between gallery-i and probe-j
  • Create a gallery ID list gids = [0,1,1]
  • Create a probe ID list pids = [0,0,1,1]

Then you can call cmc(D, gids, pids) to get CMC.

from dgd_person_reid.

Phoebe-star avatar Phoebe-star commented on August 19, 2024

sorry I don't know
if I have the cuhk03 person id ,like : 000_1 ,000_2 , 001_1 , 001_2 , 002_1 , 002_2
000_1 ,000_2 is the same person ; 001_1 , 001_2 is the same person ; 002_1 , 002_2 is the same person

A network can compute the person is the same or not , output is true or false
how to know the CMC?

and the CMC is relationship with rank-1 , rank-2 ...... ?
thanks you

from dgd_person_reid.

Cysu avatar Cysu commented on August 19, 2024

@Phoebe-star Our network does not compute whether two persons are the same or not. It receives only one image as input, and outputs the feature vector. After getting the features of all the gallery and probe images, we can compute pairwise Euclidean distances. Based on which we can compute CMC.

A brief introduction of CMC can be found here.

from dgd_person_reid.

Phoebe-star avatar Phoebe-star commented on August 19, 2024

where can I find rank-m?
thanks

from dgd_person_reid.

Cysu avatar Cysu commented on August 19, 2024

@Phoebe-star CMC top-1 is rank-1. They are the same, literally.

from dgd_person_reid.

Phoebe-star avatar Phoebe-star commented on August 19, 2024

################################
import numpy as np

def _cmc_core(D, G, P):
m, n = D.shape
order = np.argsort(D, axis=0)
match = (G[order] == P)
return (match.sum(axis=1) * 1.0 / n).cumsum()

def cmc(distmat, glabels=None, plabels=None, ds=None, repeat=None):
"""Compute the Cumulative Match Characteristic (CMC)
This function assumes that gallery labels have no duplication. If there are
duplications, random downsampling will be performed on gallery labels, and
the computation will be repeated to get an average result.
Parameters
----------
distmat : numpy.ndarray
The distance matrix. distmat[i, j] is the distance between i-th
gallery sample and j-th probe sample.
glabels : numpy.ndarray or None, optional
plabels : numpy.ndarray or None, optional
If None, then gallery and probe labels are assumed to have no
duplications. Otherwise, they represent the vector of gallery and probe
labels. Default is None.
ds : int or None, optional
If None, then no downsampling on gallery labels will be performed.
Otherwise, it represents the number of gallery labels to be randomly
selected. Default is None.
repeat : int or None, optional
If None, then the function will repeat the computation for 100 times
when downsampling is performed. Otherwise, it specifies the number of
repetition. Default is None.
Returns
-------
out : numpy.ndarray
The rank-1 to rank-m accuracy, where m is the number of (downsampled)
gallery labels.
"""
m, n = distmat.shape
if glabels is None and plabels is None:
glabels = np.arange(0, m)
plabels = np.arange(0, n)
if isinstance(glabels, list):
glabels = np.asarray(glabels)
if isinstance(plabels, list):
plabels = np.asarray(plabels)
ug = np.unique(glabels)
if ds is None:
ds = ug.size
if repeat is None:
if ds == ug.size and ug.size == len(glabels):
repeat = 1
else:
repeat = 100

ret = 0
for __ in xrange(repeat):
    # Randomly select gallery labels
    G = np.random.choice(ug, ds, replace=False)
    # Select corresponding probe samples
    p_inds = [i for i in xrange(len(plabels)) if plabels[i] in G]
    P = plabels[p_inds]
    # Randomly select one gallery sample per label selected
    D = np.zeros((ds, P.size))
    for i, g in enumerate(G):
        samples = np.where(glabels == g)[0]
        j = np.random.choice(samples)
        D[i, :] = distmat[j, p_inds]
    # Compute CMC
    ret += _cmc_core(D, G, P)
return ret / repeat

gids = [0,1,1]
pids = [0,0,1,1]
D =np.matrix("0.8 0.9 0.3 0.5;0.3 0.5 0.6 0.1;0.9 0.1 0.1 0.1")
print ( cmc(D, gids, pids) )
###################################

I run the cmc.py code
and the result is [ 0.52 1. ] [ from the code print ( cmc(D, gids, pids) ) ]
what dose it mean?
thanks thanks

from dgd_person_reid.

Cysu avatar Cysu commented on August 19, 2024

It means the top-1 accuracy is 52% and the top-2 accuracy is already 100%.

from dgd_person_reid.

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.