行人重識別CUHK03數據集及MATLAB cell array介紹---史上最全總結

1. 數據集整體描述

該數據集採集於港中文校園,是以MATLAB MAT file的格式來存儲的,是收集了1467個identities, 這1467個identities又是收集自5 different pairs of camera views. 5對攝像機,什麼意思? 是10個相機? 對的,是10個相機. 5對攝像機(或者也叫5個攝像機組)是有分工的,不是同一個人會路過5對(10個)全部攝像頭。a pair of camera 一對攝像機負責收取M10M*10個cells的數據,MM代表the number of identities.

For each identity, cell 1-5 are images from one camera and cell 6-10 are images from another camera. However, some identities may have less than 10 images. 但是, 有的人10張圖像不全有,可能缺一張這種,比如在detected cell裏就沒有1_003_2_05.png這張圖像. 也就是沒有編號爲5的圖像.

那麼,每一對裏,一個負責幹啥,另一個負責幹啥?

第一個攝像頭拍攝一個人的正面或側面5張,第二個攝像頭也拍攝這個人的5張(一定是與第一個攝像機不同視角的,比如背面),然後也沒像人臉一樣把他們放到以identity命名的文件夾裏。

因爲這就是正所謂的一對camera views,一個camera view,另一個不同的camera view,總共只有兩個view.

圖片

上述圖片引用自gmHappy的CSDN博客

在弄清數據是具體怎麼組織之前,有必要先介紹下如何理解MATLAB Cell Array,如果您清楚MATLAB Cell Array請忽略這部分內容

1.1 數據的組織形式

由MATLAB讀進去Workspace後,我們得到如下組織結構的數據:

  • detected 5x1 cell which means the bounding boxes are estimated by pedestrian detector
  • labeled 5x1 cell which means the bounding boxes are labeled by human
  • testsets 20x1 cell which contains the testing protocols

先說detected:

這個是個5x1的cell, 這個子cell arrary的組織形式如下:

– 843x10 cell 第一個攝像機組,第一對攝像機(pair1)對於843x10這個cell的元素也是cell.
– 440x10 cell 第二個攝像機組,第二對攝像機(pair2)同上
– 77x10 cell 第三個攝像機組,第三對攝像機(pair3)同上
– 58x10 cell 第四個攝像機組,第四對攝像機(pair4)同上
– 49x10 cell 第五個攝像機組,第五對攝像機(pair5)同上

%以843x10的cell的元素即子cell爲例:
%也就是具體到特定人的特定1/10的具體那張圖像
應該不再是cell,而是一個三維數據.
(比如:W×Hx3(從圖片看是寬乘以高)(還是HxWx3還得確認下)的數據類型爲uint8的不帶着boundingbox但是框好的長方形圖像)

再說labeled

the bounding boxes are labeled by human. 其數據組織形式(格式)同detected.

再說testsets

測試協議。

  1. 測試協議1:single-shot setting

    具體地說,即隨機選出100個行人identity作爲測試集,1160個行人identity作爲訓練集,100個行人identity作爲驗證集(這裏總共1360個行人而不是1467個,這是因爲實驗中沒有用到攝像頭組pair 4和5的數據, pair1+pair2+pair3=843+440+77=1360),重複二十次。這種測試協議是single-shot setting.

  2. 測試協議2:

20 x 1 cells and each contains the identities used for testing. 那麼具體的測試用的identities怎麼組織的還看100x2的格式.

爲了更好的弄明白,到底測試時候的數據是怎麼被使用的?

我創建個簡單的20x1的數據來進行解釋。

c=cell(20,1)

c =

  20×1 cell array

    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}
    {0×0 double}

可見,上面爲20個0x0 double 類型的矩陣組成的。

同理,由 20 個 100 x 2 double 類型矩陣組成 (重複二十次), 無非就是維度與模擬cell的元素的維度不同而已。

而100 x 2 double,100 行代表 100 個測試樣本identity(是specific identity, 具體到哪個相機拍的,哪個人的, 但是具體不到那個人的第幾張圖片),第 1 列爲攝像頭 pair 索引(即1,2,3,4,5),第 2 列爲行人identity索引(即identity的索引,這個索引的範圍還沒確定,不過應該不是1467)

100 x 2 matrix A, where A(i, 1) is the index of camera pair and A(i, 2) is the index of identity.

看看具體都張什麼樣子呢?

%第一個100x2
A=testsets{1,1}
A =

     1   266
     1   818
     1   787
     1   660
     1   833
     1   624
     1   231
     1   423
     1   588
     1   128
     1   416
     1    65
     1   301
     1   294
     1   300
     1   543
     1   401
     1   120
     1   462
     1    18
     1   236
     1     4
     1   336
     1   274
     1   580
     1   473
     1   360
     1    30
     1   741
     1   749
     1   566
     1   192
     1   144
     1   500
     1   709
     1    83
     1   545
     1    61
     1   252
     1   380
     1   630
     1   331
     1   346
     1   839
     1    98
     1   685
     1   105
     1   535
     1   197
     1   418
     1   325
     1   220
     1   254
     1   173
     1   414
     1   313
     1   601
     1   600
     1   752
     1   142
     1   404
     1   757
     2    28
     2    99
     2    93
     2   432
     2   222
     2   407
     2   394
     2   203
     2   410
     2   397
     2    19
     2   334
     2   286
     2    95
     2    45
     2    32
     2   348
     2   387
     2   126
     2   333
     2   439
     2   111
     2   389
     2   270
     2   267
     2   146
     2   110
     2   299
     2   362
     2   211
     2   147
     2    60
     3     2
     3    17
     3    70
     3    13
     3    43
     3    72

然後看看100x2的(1,1)和(1,2):

A(1,1)
ans =

     1  %這個1代表pair1
%
A(1,2)
ans =

   266 %這個266代表index_identity

2. MATLAB cell 介紹

其實就是MATLAB的Cell array. A cell array is a data type with indexed data containers called cells(具有單元格的數據類型), where each cell can contain any type of data(每個單元格中包含的數據類型又可以不一樣). Cell arrays commonly contain either lists of text, combinations of text and numbers, or numeric arrays of different sizes.

Refer to sets of cells by enclosing indices in smooth parentheses, (). Access the contents of cells by indexing with curly braces, {}.

通過將索引括在圓括號()中來引用單元格集合。 通過使用大括號{}進行索引來訪問單元格的內容。

2.1 創建一個MATLAB cell 數組

create the array using the cell array construction operator,{}.

先創建一個最簡單的0×0 empty cell array
C={}
C=
	0x0 empty cell array	

可見,{}就是創建cell array用的語法。

C={1,2,3;
	'text', rand(5,10,2), {11;22;33}}

在弄清這個Cell Array的維度之前,有必要了解下MATLAB裏面semicolon和comma的作用.

x =[1,2,3]  % comma 這樣的話,就和python創建list時候一樣
% creates a 1x3 row vector.
x =

     1     2     3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 而如果是semicolon的情形呢:
x=[1;2;3] %此時創建的列向量而不再是行向量。
% creates a 3x1 column vector
x =

     1
     2
     3

結合上面給出的semicolon和comma的用法

我們知道

  1. 1,2,3; 代表1,2,3佔一行的位置
  2. ‘text’,rand(5,10,2),{11; 22; 33} 佔一行的位置
  3. 再結合兩部分在空間上形成對應,所以確實是2x3 cell array.

因此,得到的2x3 cell array數組如下所示:

C = {1,2,3;
     'text',rand(5,10,2),{11; 22; 33}}
C=2×3 cell array
    {[   1]}    {[          2]}    {[     3]}
    {'text'}    {5x10x2 double}    {3x1 cell}

這是2x3 cell array的情形,但是子cell的元素並不是cell而是11 22 33這種單個的數。

在高維圖像數據中,我們更關注如果子cell裏面的元素還是cell array的情形, 我們假設{3x1 cell}的每個元素又是個2x1的cell array, 所以新的代碼應該爲:

C ={1,2,3;
	'text',rand(5,10,2),{{1;2};{1;2};{1;2}}}
% 這樣的話,我們得到:
C =

  2×3 cell array

    {[   1]}    {[          2]}    {[     3]}
    {'text'}    {5×10×2 double}    {3×1 cell}

2.2 訪問一個MATLAB cell 數組中的元素

但如果我們通過cell array的index來取出這個3x1的cell單獨研究的話,我們會得到如下:

  • 我們先看Content Indexing with Curly Braces, {}的Case: 用花括號{}進行內容索引的情形
% For example, to access the contents of the last cell of C, use curly braces.
last = C{2,3}

last =

  3×1 cell array

    {2×1 cell}
    {2×1 cell}
    {2×1 cell}

3. 跑程序時的打印結果:

Pycharm結果

然後,經過DEBUG我們看到,dataset裏面的

num_train_pids=767

綜上,我們知道,這就是train會用到的number of identities. 所以,在data_manager.py裏面的pid指的就是train裏面第幾個identities.

  • train是一組identities很正常
  • query也是一組identities而不是一個identity.
  • gallery是一組identities這很自然啊。

參考文獻

  1. hyk_1996的CSDN博客
  2. gmHappy的CSDN博客
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章