yule-li / CosFace

Tensorflow implementation for paper CosFace: Large Margin Cosine Loss for Deep Face Recognition
284 stars 99 forks source link

There is too many versions. Can anyone tell me which is the best from the model provided until now . #8

Open pyupcgithub opened 5 years ago

pyupcgithub commented 5 years ago

model-20180309-083949.ckpt-60000 ? model-20180626-205832.ckpt-60000 ? and how to choose the parameters ?

pyupcgithub commented 5 years ago

@yule-li

chenyyx commented 5 years ago

if you want to train a new model,please modify these parameters according to the train.sh . if you just want to run the model which author given, the sphere-network ,you should to use 20180309-083949.ckpt.

2.3 测试及文件修改 2.3.1 test.sh 文件修改 文件说明:测试直接执行的 shell 脚本文件,调用 test.py 文件。

需要修改的内容如下:

MODEL_DIR 说明:预训练好的 cosface 的 tf 版本模型(如:model-20180309-08394.ckpt-60000) 更改:改为自己训练得到 或者 作者预训练完成的模型 所存储的路径。 TEST_DATA 说明:测试数据集。(lfw-112X96) 更改:改为自己的测试数据集所存储的路径。(我们使用的 lfw-112X96 数据集的存储路径) EMBEDDING_SIZE 说明:EMBEDDING_SIZE 参数。 更改:设置为之前训练的时候使用的 EMBEDDING_SIZE 参数,保证训练和测试阶段此参数是一致的。否则将会报错。值得注意的一点是,作者给出的训练完成的模型的此参数是 512,而它给出的 训练过程中使用的参数是 1024,一定要记得修改一下。 位于文件最底端的命令部分: 说明:具有 2 个版本 —— gpu 版本 和 cpu 版本,看着自己的情况修改使用。 gpu 版本:CUDA_VISIBLE_DEVICES=1 python test/test.py ${TEST_DATA} ${MODEL_DIR} --lfw_file_ext jpg --network_type sphere_network --embedding_size ${EMBEDDING_SIZE} ${FC_BN} ${PREWHITEN} --image_height ${IMAGE_HEIGHT} --image_width ${IMAGE_WIDTH} cpu 版本: python test/test.py ${TEST_DATA} ${MODEL_DIR} --lfw_file_ext jpg --network_type sphere_network --embedding_size ${EMBEDDING_SIZE} ${FC_BN} ${PREWHITEN} --image_height ${IMAGE_HEIGHT} --image_width ${IMAGE_WIDTH} 文件底端命令参数说明: 其中的 CUDA_VISIBLE_DEVICES=1 的意思是,tf 可用 gpu 为 编号为 1 的 gpu,其他的 gpu 是不可以使用的。 test/test.py 是运行的 test.py 文件 lfw_file_ext jpg 是说,lfw 数据集的图像的扩展名是 jpg network_type sphere_network 这个参数的意思是,我们训练完成的模型使用的 网络结构是 sphere_network embedding_size 就是我们上面提到的 EMBEDDING_SIZE 参数。 image_height 设置的是图像的高 image_width 设置的是图像的宽 2.3.2 test.py 文件修改 文件说明:模型测试文件,加载 训练好的模型,并在 lfw 数据集上进行测试。

文件修改参数如下:

line 72 saver.save(sess,'./tmp_saved_model',global_step=1) 说明:模型临时存储路径。 更改:改不改均可。 line 109 emb_array[start_index:end_index,:] = feats 说明:模型输出向量。 更改:无需更改。 line 129,130 parser.add_argument('--network_type', type=str, help='Network structure.',default='resnet50') 说明:加载预训练模型的网络结构类型。 更改:改为我们预训练模型的类型 sphere_network 。(默认是 resnet50) line 139,140 parser.add_argument('--lfw_batch_size', type=int, help='Number of images to process in a batch in the LFW test set.', default=200) 说明:lfw 数据集的 batch size 。 更改:无需更改。默认即可。 line 151,152 parser.add_argument('--lfw_pairs', type=str, help='The file containing the pairs to use for validation.', default='data/pairs.txt') 说明:lfw 的 pairs 文件。 更改:无需更改。 line 168, 169 parser.add_argument('--model_def', type=str, help='Model definition. Points to a module containing the definition of the inference graph.', default='models.inception_resnet_v1') 说明:模型定义,指向包含推理图定义(the definition of the inference graph)的模块。 更改:将原来默认的 default='models.inception_resnet_v1' 改为: default='models.sphere_network' 2.3.3 其余文件说明 lib/lfw.py 说明: lfw 数据集工具文件,图像加载,pairs 文件加载,模型 evaluate 等。 更改:无更改。 lib/utils.py 说明:工具文件,模型的加载等。 更改:无更改。 networks/sphere_network.py 说明:网络模型结构文件。 更改:无更改。 2.4 开始测试 在更改完成以上修改之后,在终端执行以下命令即可:

shell sh ./test.sh

pyupcgithub commented 5 years ago

@chenyyx thank you for your reply. for the best pretrained model , do i need to do flip and prewhiten ?

chenyyx commented 5 years ago

@pyupcgithub I didn't test like this at the time, you can try it.

pyupcgithub commented 5 years ago

@chenyyx ok, thank u.