def main():
    fnet = SiameseFaceNet()
    fnet.vgg16_include_top = True

    model_dir_path = './models_1'
    image_dir_path = "./data/images"

    database = dict()



    database["aipengfei"] = [fnet.img_to_encoding(image_dir_path + "/aipengfei.png")]
    database["anyaru"] = [fnet.img_to_encoding(image_dir_path + "/anyaru.png")]
    database["baozhiqian"] = [fnet.img_to_encoding(image_dir_path + "/baozhiqian.png")]
    # database["danielle"] = [fnet.img_to_encoding(image_dir_path + "/danielle.png")]
    # database["younes"] = [fnet.img_to_encoding(image_dir_path + "/younes.jpg")]
    # database["tian"] = [fnet.img_to_encoding(image_dir_path + "/tian.jpg")]
    # database["andrew"] = [fnet.img_to_encoding(image_dir_path + "/andrew.jpg")]
    # database["kian"] = [fnet.img_to_encoding(image_dir_path + "/kian.jpg")]
    # database["dan"] = [fnet.img_to_encoding(image_dir_path + "/dan.jpg")]
    # database["sebastiano"] = [fnet.img_to_encoding(image_dir_path + "/sebastiano.jpg")]
    # database["bertrand"] = [fnet.img_to_encoding(image_dir_path + "/bertrand.jpg")]
    # database["kevin"] = [fnet.img_to_encoding(image_dir_path + "/kevin.jpg")]
    # database["felix"] = [fnet.img_to_encoding(image_dir_path + "/felix.jpg")]
    # database["benoit"] = [fnet.img_to_encoding(image_dir_path + "/benoit.jpg")]
    # database["arnaud"] = [fnet.img_to_encoding(image_dir_path + "/arnaud.jpg")]

    fnet.fit(database=database, model_dir_path=model_dir_path)
Exemplo n.º 2
0
 def fileName(self):
     fnet = SiameseFaceNet()
     model_dir_path = './models_1'
     image_dir_path = "./data/images"
     fnet.load_model(model_dir_path)
     database = dict()
     rootdir = 'data/stu'
     list = os.listdir(rootdir)  # 列出文件夹下所有的目录与文件
     for i in range(0, len(list)):
         path = rootdir + "/" + list[i]
         listname = os.listdir(path)
         for i in range(0, len(listname)):
             print(path + '/' + listname[i])
             database[listname[i].split('.')[0]] = [
                 fnet.img_to_encoding(path + '/' + listname[i])
             ]
         #print (path+'/'+listname[i])
     return database
Exemplo n.º 3
0
    def fileName(self):
        fnet = SiameseFaceNet()
        model_dir_path = './models_2'
        fnet.load_model(model_dir_path)
        database = dict()
        rootdir = 'data/stu100'
        list = os.listdir(rootdir)  # 列出文件夹下所有的目录与文件
        for index in range(0, len(list)):
            path = rootdir+"/"+list[index]
            listname = os.listdir(path)
            for i in range(0, len(listname)):
                print(path+'/'+listname[i])
                database[list[index]] = [fnet.img_to_encoding(path+'/'+listname[i])]
            #print (path+'/'+listname[i])
        output = open('myfile.pkl', 'wb')
        pickle.dump(database, output)
        output.close()

        return database
Exemplo n.º 4
0
def main():
    fnet = SiameseFaceNet()

    model_dir_path = './model'
    image_dir_path = "./data/test/align"
    fnet.load_model(model_dir_path)

    database1 = dict()  #dictionary

    #fnet.who_is_it(image_dir_path + "/younes.jpg", database)
    database1["chenaifang"] = [
        fnet.img_to_encoding(image_dir_path + "/bailu1.jpg")
    ]
    fnet.verify(image_dir_path + "/wangtiange1.jpg", "chenaifang", database1)
Exemplo n.º 5
0
 def predict(self, database):
     fnet = SiameseFaceNet()
     model_dir_path = './models_1'
     image_dir_path = "./data/images"
     fnet.load_model(model_dir_path)
     print("-------------------------")
     # fnet.verify(image_dir_path + "/001.png", "aipengfei", database)
     # fnet.verify(image_dir_path + "/002.png", "aipengfei", database)
     # fnet.who_is_it(image_dir_path + "/001.png", database)
     #fnet.who_is_it(image_dir_path + "/002.png", database)
     fnet.who_is_it("data/5test.jpg", database)
Exemplo n.º 6
0
 def predict(self,database):
     fnet = SiameseFaceNet()
     model_dir_path = './models_2'
     fnet.load_model(model_dir_path)
     print("-------------------------")
     # fnet.verify(image_dir_path + "/001.png", "aipengfei", database)
     # fnet.verify(image_dir_path + "/002.png", "aipengfei", database)
     # fnet.who_is_it(image_dir_path + "/001.png", database)
     #fnet.who_is_it(image_dir_path + "/002.png", database)
     fnet.who_is_it("data/test/chencongcong.png", database)
     fnet.who_is_it("data/test/chendandan.png", database)
     # fnet.who_is_it("data/test/chendaocheng.png", database)
     # fnet.who_is_it("data/test/chenfuyuan.png", database)
     # fnet.who_is_it("data/test/chenge.png", database)
     # fnet.who_is_it("data/test/chenguang.png", database)
     # fnet.who_is_it("data/test/chenguangwei.png", database)
     # fnet.who_is_it("data/test/chenguoyan.png", database)
     # fnet.who_is_it("data/test/chenhaiyan.png", database)
     # fnet.who_is_it("data/test/chenhao.png", database)
Exemplo n.º 7
0
def main():
    fnet = SiameseFaceNet()
    '''
    因为VGGNET最后有三个全连接层, 因此,这个选项表示是否需要最上面的三个全连接层. 
    一般网络最后都会有全连接层, 最后一个全连接层更是设定了分类的个数, loss的计算方法, 
    并架设了一个概率转换函数(soft max). 其实soft max的作用就是将输出转换为各类别的概率,并计算loss. 
    可以这么说, 最上面三层是用来进行分类的, 其余层是用来进行特征提取的. 
    因此如果include_top=False,也就表示这个网络只能进行特征提取. 不能在进行新的训练或者在已有权重上fine-tune.
    '''
    #fnet.vgg16_include_top = True #包含最上层的全连接层
    #fnet.threshold=0.7  #阈值,在验证的时候作为是否是同一个人的标准
    model_dir_path = './model'
    #image_dir_path = "./data/dlib-align-images"
    #在测试
    image_dir_path = "./data/dlib-align-images"
    database = dict()
    #单人单张照片时
    '''
    for filename in os.listdir(r"./data/dlib-align-images"):
        list=filename.split(".")
        #print(list[0])
        database[list[0]]=[fnet.img_to_encoding(image_dir_path+"/"+filename)]
    '''
    '''#打算将模型整合起来
    for filename in os.listdir(r"./data/dlib-align-images-test"):
        pic_list = []#key是人名,value是两张图片的名字
        for picname in os.listdir(r"./data/dlib-align-images-test/" + filename):
            pic_list.append(fnet.img_to_encoding(image_dir_path + "/" + filename + "/" + picname))
            #pic_list.append(image_dir_path + "/" + filename + "/" + picname)
        database_name[filename] = pic_list

    fnet.fit(database1=database_name, model_dir_path=model_dir_path)
    '''

    #'''
    #i=0
    #j=0
    for filename in os.listdir(r"./data/dlib-align-images"):
        pic_list = []
        for picname in os.listdir(r"./data/dlib-align-images/" + filename):
            pic_list.append(
                fnet.img_to_encoding(image_dir_path + "/" + filename + "/" +
                                     picname))
        database[filename] = pic_list

    np.save('picture_encoding.npy', database)
    #'''
    read_dictionary = np.load("picture_encoding.npy").item()
    #database=read_dictionary
    #fnet.fit(database=database, model_dir_path=model_dir_path)
    #i=i+1
    #if i is 17:
    #    j = j + 1
    #    np.save('picture_encoding_qqq.npy'+str(j), database)
    #    i = 0
    #    database=dict()
    #将字典保存到文件中
    #'''
    #'''
    #读取文件中的内容,将内容赋给字典
    #read_dictionary1 = np.load("picture_encoding1.npy").item()
    #read_dictionary2 = np.load("picture_encoding2.npy").item()
    #database=read_dictionary1.copy()
    #database.update(read_dictionary2

    #database=dict(read_dictionary1.items()+read_dictionary2.items())
    #print(database)
    #read_dictionary=database
    #random.shuffle(read_dictionary)
    database = read_dictionary

    #database是人名;
    fnet.fit(database=database, model_dir_path=model_dir_path)
Exemplo n.º 8
0
def main():
    fnet = SiameseFaceNet()

    model_dir_path = './models'
    image_dir_path = "./data/images"
    fnet.load_model(model_dir_path)

    database = dict()
    database["danielle"] = [fnet.img_to_encoding(image_dir_path + "/danielle.png")]
    database["younes"] = [fnet.img_to_encoding(image_dir_path + "/younes.jpg")]
    database["tian"] = [fnet.img_to_encoding(image_dir_path + "/tian.jpg")]
    database["andrew"] = [fnet.img_to_encoding(image_dir_path + "/andrew.jpg")]
    database["kian"] = [fnet.img_to_encoding(image_dir_path + "/kian.jpg")]
    database["dan"] = [fnet.img_to_encoding(image_dir_path + "/dan.jpg")]
    database["sebastiano"] = [fnet.img_to_encoding(image_dir_path + "/sebastiano.jpg")]
    database["bertrand"] = [fnet.img_to_encoding(image_dir_path + "/bertrand.jpg")]
    database["kevin"] = [fnet.img_to_encoding(image_dir_path + "/kevin.jpg")]
    database["felix"] = [fnet.img_to_encoding(image_dir_path + "/felix.jpg")]
    database["benoit"] = [fnet.img_to_encoding(image_dir_path + "/benoit.jpg")]
    database["arnaud"] = [fnet.img_to_encoding(image_dir_path + "/arnaud.jpg")]
    database["deepak"] = [fnet.img_to_encoding(image_dir_path + "/deepak.jpg")]
    database["momo"] = [fnet.img_to_encoding(image_dir_path + "/momo.jpg")]

    fnet.verify(image_dir_path + "/camera_0.jpg", "younes", database)
    fnet.verify(image_dir_path + "/camera_2.jpg", "kian", database)
    # fnet.verify(image_dir_path + "/test_deepak_1.jpg", "deepak", database)
    # fnet.verify(image_dir_path + "/test_momo_1.jpg", "momo", database)
    # fnet.verify(image_dir_path + "/test_momo.jpg", "deepak", database)
    fnet.who_is_it(image_dir_path + "/camera_0.jpg", database)
    fnet.who_is_it(image_dir_path + "/younes.jpg", database)
Exemplo n.º 9
0
def main():
    fnet = SiameseFaceNet()
    fnet.vgg16_include_top = True

    model_dir_path = './models'
    image_dir_path = "./data/images"

    database = dict()
    database["danielle"] = [fnet.img_to_encoding(image_dir_path + "/danielle.png")]
    database["younes"] = [fnet.img_to_encoding(image_dir_path + "/younes.jpg")]
    database["tian"] = [fnet.img_to_encoding(image_dir_path + "/tian.jpg")]
    database["andrew"] = [fnet.img_to_encoding(image_dir_path + "/andrew.jpg")]
    database["kian"] = [fnet.img_to_encoding(image_dir_path + "/kian.jpg")]
    database["dan"] = [fnet.img_to_encoding(image_dir_path + "/dan.jpg")]
    database["sebastiano"] = [fnet.img_to_encoding(image_dir_path + "/sebastiano.jpg")]
    database["bertrand"] = [fnet.img_to_encoding(image_dir_path + "/bertrand.jpg")]
    database["kevin"] = [fnet.img_to_encoding(image_dir_path + "/kevin.jpg")]
    database["felix"] = [fnet.img_to_encoding(image_dir_path + "/felix.jpg")]
    database["benoit"] = [fnet.img_to_encoding(image_dir_path + "/benoit.jpg")]
    database["arnaud"] = [fnet.img_to_encoding(image_dir_path + "/arnaud.jpg")]

    fnet.fit(database=database, model_dir_path=model_dir_path)
Exemplo n.º 10
0

def createAug_1():
    rootdir = 'data/stu01'
    list = os.listdir(rootdir)  # 列出文件夹下所有的目录与文件
    count = 0
    for index in range(0, len(list)):
        #print (count)
        count = count + 1
        path = rootdir + "/" + list[index]
        listname = os.listdir(path)
        if len(listname) == 0:
            print(list[index])

        #os.makedirs( 'data/stu01/'+list[index])
        for i in range(0, len(listname)):
            #print(path + '/' + listname[i])
            imgpath = path + '/' + listname[0]
            img = cv2.imread(imgpath)  # 这是一个PIL图像
            #img =cv2.cvtColor( np.array(img), cv2.COLOR_BGR2RGB)
            #cv2.imwrite('data/stu01/' +list[index]+'/'+ listname[0], img)
            break


if __name__ == '__main__':
    #createAug_1()
    fnet = SiameseFaceNet()
    fnet.vgg16_include_top = True
    saveTrainPkl(fnet)
    main(fnet)
    createAug()
Exemplo n.º 11
0
 def predict(self):
     fnet = SiameseFaceNet()
     model_dir_path = './models_1'
     image_dir_path = "./data/images"
     fnet.load_model(model_dir_path)
     database = dict()
     database["aipengfei"] = [fnet.img_to_encoding(image_dir_path + "/aipengfei.png")]
     database["anyaru"] = [fnet.img_to_encoding(image_dir_path + "/anyaru.png")]
     database["baozhiqian"] = [fnet.img_to_encoding(image_dir_path + "/baozhiqian.png")]
     print("-------------------------")
     fnet.verify(image_dir_path + "/001.png", "aipengfei", database)
     fnet.verify(image_dir_path + "/002.png", "aipengfei", database)
     fnet.who_is_it(image_dir_path + "/001.png", database)
     fnet.who_is_it(image_dir_path + "/002.png", database)
     fnet.who_is_it(image_dir_path + "/003.png", database)