Re-ID Market和Duke统计 及 gallery导致后置的摄像头统计

了解常用数据集:

https://www.cnblogs.com/geoffreyone/p/10314062.html

 

××××××××××××××××××××××××××××××××××××××××××××××××××××××

Market-1501 和 DukeMTMC:

先贴结果:

解释:前两拨为Market-1501的训练集和测试集,后两拨为DukeMTMC的训练集和测试集;

              每一拨中,横向为每个摄像头和图片数,纵向为每个摄像头下的人数。

如:

        Market-1501中:

       训练集中第一个摄像头:有2017张图片,有652位训练对象。(看第一行

       测试集第一个摄像头:有3156张图片,有671位测试对象。(看第二行

代码:

import zipfile
import os


M_data_path = '/ssd2/lin/linshaochuan/Market_data/Market-1501-v15.09.15';
D_data_path = "/ssd2/lin/linshaochuan/Duke_data/DukeMTMC-reID"
"""
if not os.path.isdir(data_path):
    print('please change the download_path')

"""

part1 = "/bounding_box_train"
part2 = "/bounding_box_test"


#***************************************when only have zip**************************************************

def un_zip(file_name):
    """unzip zip file"""
    name=file_name.split(".z")
    zip_file = zipfile.ZipFile(file_name)
    if os.path.isdir(name[0]):
        print("Have file.")
    else:
        print("No file.")
        os.mkdir(str(name[0]))
    for names in zip_file.namelist():
        #print(names)
        zip_file.extract(names, name[0]+"/")
    zip_file.close()

# ******************************the main part*****************************


def Market1501_count(data_path, part):
    train_path = data_path + part  # '/bounding_box_train'
    cnt_picture = {}
    cnt_people={}

    for root, dirs, files in os.walk(train_path, topdown=True):
        for name in files:
            if not name[-3:] == 'jpg':
                continue
            tmp = name.split('.')
            ID = tmp[0].split('_')  # get the picture name


            # count picture
            if (ID[1][1] in cnt_picture.keys()):
                cnt_picture[ID[1][1]] += 1
            else:
                cnt_picture[ID[1][1]] = 1

            # count people
            if(ID[1][1] not in cnt_people.keys()): #
                cnt_people[ID[1][1]]={ID[0]:1}
                #print(cnt_people_ID)
            else:  #
                if (ID[0] not in cnt_people[ID[1][1]].keys()):
                    cnt_people[ID[1][1]][ID[0]]=1
                else:
                    cnt_people[ID[1][1]][ID[0]]+= 1


    print(part, ":", cnt_picture)
   

    for key in cnt_people:
        print("M camera",key,"people:",len(cnt_people[key]))



def DukeMTMC(data_path, part):
    train_path = data_path + part  # '/bounding_box_train'
    cnt_picture = {}
    cnt_people={}

    for root, dirs, files in os.walk(train_path, topdown=True):
        for name in files:
            if not name[-3:] == 'jpg':
                continue
            tmp = name.split('.')
            ID = tmp[0].split('_')  #


            #
            if (ID[1][1] in cnt_picture.keys()):
                cnt_picture[ID[1][1]] += 1
            else:
                cnt_picture[ID[1][1]] = 1

            #
            if(ID[1][1] not in cnt_people.keys()): #
                cnt_people[ID[1][1]]={ID[0]:1}
                #print(cnt_people_ID)
            else:  #
                if (ID[0] not in cnt_people[ID[1][1]].keys()):
                    cnt_people[ID[1][1]][ID[0]]=1
                else:
                    cnt_people[ID[1][1]][ID[0]]+= 1


    print(part, ":", cnt_picture)
    #print(cnt_people_ID)

    for key in cnt_people:
        print("D camera",key,"people:",len(cnt_people[key]))





#******************************************************************************************



#un_zip(data_path+".zip")  #
Market1501_count(M_data_path,part1)
Market1501_count(M_data_path,part2)
DukeMTMC(D_data_path, part1)
DukeMTMC(D_data_path, part2)

 

×××××××××××××××××××××××××××××××××××××××××××××××××××××××

Gallery 中对结果影响不好的摄像头:

说明:结果为一个字典{ “query数”:{ “ 摄像头 ” :图片个数}}。 如需对某一个query分析,再取用。

代码(取Person_reID_baseline_pytorch 的evaluate_gpu.py中的evaluate函数):

def evaluate(qf,ql,qc,gf,gl,gc, outer_i, my_cnt):  # 'my_cnt' change the original parameters

    #print(qf.shape)
    query = qf.view(-1, 1)  #??
    score = torch.mm(gf, query)
    score = score.squeeze(1).cpu()
    score = score.numpy()
    index = np.argsort(score)  #from small to large
    index = index[::-1]

    # good index
    query_index = np.argwhere(gl==ql)
    
    #sort the 'query_index' by the order of sorted ‘score’
    Z=zip(score,query_index)
    Z=sorted(Z,reverse=True)
    tmp_score,query_index=zip(*Z)

    camera_index = np.argwhere(gc == qc)
    good_index = np.setdiff1d(query_index, camera_index, assume_unique=True)

    junk_index1 = np.argwhere(gl==-1)  #?
    junk_index2 = np.intersect1d(query_index, camera_index)
    junk_index = np.append(junk_index2, junk_index1) #.flatten())
    #good_index = np.setdiff1d(query_index, junk_index)

    #count
    for i in range(len(query_index)):
        if (query_index[i]!=index[i]):  
            if(str(outer_i) not in my_cnt.keys()):  # if my_cnt doesn't have key: str(outer_i)
                my_cnt[str(outer_i)]={str(gc[query_index[i]]):1}
            else:
                if(str(gc[query_index[i]]) not in my_cnt[str(outer_i)].keys()):  ## if my_cnt[str(outer_i)] doesn't have key: str(outer_i)
                    my_cnt[str(outer_i)][str(gc[query_index[i]])]=1
                else:
                    my_cnt[str(outer_i)][str(gc[query_index[i]])]+=1


    camera_index = np.argwhere(gc == qc)
    
    CMC_tmp = compute_mAP(index, good_index, junk_index)
    return CMC_tmp

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值