以下鏈接是個人關於insightFace所有見解,如有錯誤歡迎大家指出,我會第一時間糾正,如有興趣可以加QQ:944284742相互討論技術。
insightFace目錄:https://blog.csdn.net/weixin_43013761/article/details/99646731:
數據製作
爲了簡單,已經還是拿LWF數據來做講解,製作bin文件之前,我們需要一個pairs.txt文件,那麼這個文件給幹嘛的?爲什麼需要一個這樣的文件?首先我們來看看,該文件的內容格式:
Jane_Pauley 0002 0001
Andre_Agassi 0017 0007
Blythe_Hartley 0001 0002
Natalie_Cole 0003 0002
......
......
Mary_Catherine_Correll 0001 Hilda_Fortune 0001
Ronnie_Jagday 0001 Christopher_Conyers 0001
Bob_Stoops 0001 Steve_Coterill 0001
Gillian_Anderson 0001 Mike_Flanagan 0001
可以看到該文件主要有兩種格式,第一種爲每行3個內容(相同圖片),第二種爲每行4個內容(不相同圖片)主要解釋如下:
Jane_Pauley 0002 0001
#在Jane_Pauley目錄下的Jane_Pauley_0002.jpg與Jane_Pauley_0001.jpg爲相同的一個人
Ronnie_Jagday 0001 Christopher_Conyers 0001
#在Ronnie_Jagday目錄下的Ronnie_Jagday_0001.jpg
#與Christopher_Conyers_0001目錄下Christopher_Conyers_0001.jpg不是相同的一個人
在源碼中沒有生成pairs.txt文件的腳本,在這裏爲大家提供一分,負責粘貼即可,insightface-master\script\generate_pairs_txt.py:
# coding:utf-8
import sys
import os
import random
import time
import itertools
import pdb
src = 'D:/03.work/02.development/04.PaidOn/1.FaceRecognition/2.Dataset/1.OfficialData/2.testdata/lfw/lfw_112x112'
dst = open('D:/03.work/02.development/04.PaidOn/1.FaceRecognition/2.Dataset/1.OfficialData/2.testdata/lfw/lfw_valid/pairs.txt', 'a')
cnt = 0
same_list = []
diff_list = []
list1 = []
list2 = []
folders_1 = os.listdir(src)
# 產生相同的圖像對
conut = 0
print(len(folders_1))
for folder in folders_1:
if os.path.isfile(folder):
continue
conut += 1
print(conut)
sublist = []
imgs = os.listdir(os.path.join(src, folder))
for img in imgs:
img_root_path = os.path.join(src, folder, img)
sublist.append(img_root_path)
list1.append(img_root_path)
# 組合
#print(sublist)
for item in itertools.combinations(sublist, 2):
for name in item:
same_list.append(name)
#print(len(same_list))
if len(same_list) is 0:
continue
for j in range(0, len(list1)-1, 2):
dst.writelines(same_list[j] + ' ' + same_list[j+1] + '\n')
list2 = list1.copy()
# 產生不同的圖像對
diff = 0
# 如果不同的圖像對遠遠小於相同的圖像對,則繼續重複產生,直到兩者相差很小
while True:
random.seed(time.time() * 100000 % 10000)
random.shuffle(list2)
for p in range(0, len(list2), 2):
if list2[p] != list2[p + 1]:
dst.writelines(list2[p] + ' ' + list2[p + 1] + '\n')
diff += 1
print(diff,same_list)
if diff < len(same_list):
continue
else:
break
運行時,只需要設定src以及dst即可,就能生成pairs.txt文件,然後運行insightface-master\src\data\lfw2pack.py文件(指定輸入以及輸出目錄即可)就能生成.bin文件。bin文件的測試可以參考之前的鏈接:
每月深度2-1:insightFace-模型復現-史上最全:(https://blog.csdn.net/weixin_43013761/article/details/99647292
在測試之前,我們需要配置insightface-master\recognition\config.py文件,
dataset.retina.val_targets = ['lfw', 'cfp_fp', 'agedb_30']
dataset.emore.val_targets = ['lfw', 'cfp_fp', 'agedb_30']
只需要在其中添加你自己的.bin文件,訓練時,會以其爲目標進行測試。現在對於源碼的操作流程基本弄明白了,接下來開始分析源碼的每一個細節。如果大家覺得不錯,希望可以給個贊,你的贊時我的動力。