Test Facenet
This completes the testing of FaceNet by comparing with the embeddings generated in the TF1 version. N.B : Currently the test does NOT succeed !
Merge request reports
Activity
@lcolbois but tests are passing.
Looks like the Tensorflow-related tests are not executed :
bob.bio.face.test.test_embeddings.test_facenet_sanderberg ... SKIP: Skipping test since `tensorflow` is not available: No module named 'tensorflow.contrib' bob.bio.face.test.test_embeddings.test_idiap_inceptionv1_casia ... SKIP: Skipping test since `tensorflow` is not available: No module named 'tensorflow.contrib' bob.bio.face.test.test_embeddings.test_idiap_inceptionv1_msceleb ... SKIP: Skipping test since `tensorflow` is not available: No module named 'tensorflow.contrib' bob.bio.face.test.test_embeddings.test_idiap_inceptionv2_casia ... SKIP: Skipping test since `tensorflow` is not available: cannot import name 'InceptionResnetv2_Casia_CenterLoss_2018' from 'bob.bio.face.embeddings' (/scratch/builds/bob/bob.bio.face/miniconda/conda-bld/bob.bio.face_1607000812207/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_pla/lib/python3.7/site-packages/bob/bio/face/embeddings/__init__.py) bob.bio.face.test.test_embeddings.test_idiap_inceptionv2_msceleb ... SKIP: Skipping test since `tensorflow` is not available: No module named 'tensorflow.contrib'
Hi, I added an embedding comparison tests for all network. Running the tests shows that Inception-v2 models works correctly, however Inception-v1 models have an embedding discrepancy w.r.t the TF1 version.
If the weights are the same, and the input normalization is the same that would suggest there is a difference in the architecture itself (i.e. the operation). I am not super familiar with the details of the InceptionResnet architecture, but if I brainstorm possible sources of error I can think of that would not impact the weights:
- Wrong non-linear activation somewhere
- Wrong pooling operation somewhere (e.g. mean pooling instead of max pooling)
- Wrong handling of dropout / batch normalization layers at inference time
- Wrong non-linear activation somewhere
- Wrong pooling operation somewhere (e.g. mean pooling instead of max pooling)
- Wrong handling of dropout / batch normalization layers at inference time
That's what I'm inspecting. So far everything matches. This one will be tough
PS: Dropout is not used at inference time. so this we can discard
Edited by Tiago de Freitas PereiraPS: Dropout is not used at inference time. so this we can discard
Yes, I was wondering if by any chance it wrongly remained activated at inference time. But I am pretty sure this should not be the case as we are using Keras' predict_on_batch method
Edited by Laurent COLBOIS
If that can be helpful : looks like the intermediate outputs are the same in both models up to layer 23 ('Mixed_7a') of the Keras implementation (including the output of this layer).
After that the models diverge
Edited by Laurent COLBOISFound a discrepancy ! In the TF1 implementation:
# 5 x Inception-Resnet-C name = "block8_BN" trainable = is_trainable(name, trainable_variables, mode=mode) with slim.arg_scope( [slim.batch_norm], is_training=(mode == tf.estimator.ModeKeys.TRAIN), trainable=trainable): name = "block8" trainable = is_trainable(name, trainable_variables, mode=mode) net = slim.repeat( net, 5, block8, scale=0.20, trainable_variables=trainable) end_points[name] = net
there are 5 block8 with scale 0.2.
In the TF2 implementation:
# 5x block8 (Inception-ResNet-C block): 8 x 8 x 2080 for block_idx in range(1, 5): layers.append( InceptionResnetBlock( n_channels=1792, scale=0.2, block_type="block8", block_idx=block_idx, name=f"block8_{block_idx}", ) ) layers.append( InceptionResnetBlock( n_channels=1792, scale=1.0, activation=None, block_type="block8", block_idx=5, name="block8_5", ) )
there are 4 block8 with scale 0.2 and one with scale 1.0
Edit : Well it looks weirder than that actually, looks like one block8 is missing from the TF2 implementation. But we would see that is the number of weights no ?
Edited by Laurent COLBOISThere you go.
Facenet passes now with your test @lcolbois
mentioned in commit c566524f
bob.bio.face.test.test_embeddings.test_facenet_sanderberg ... bob.pipelines.wrappers@2020-12-05 20:00:39,759 -- DEBUG: Sample|FaceNetSanderberg_20170.transform ok bob.bio.face.test.test_embeddings.test_idiap_inceptionv1_casia ... bob.pipelines.wrappers@2020-12-05 20:01:59,892 -- DEBUG: Sample|InceptionResnetv1_Casia.transform ok bob.bio.face.test.test_embeddings.test_idiap_inceptionv1_msceleb ... bob.pipelines.wrappers@2020-12-05 20:03:12,824 -- DEBUG: Sample|InceptionResnetv1_MsCel.transform ok bob.bio.face.test.test_embeddings.test_idiap_inceptionv2_casia ... bob.pipelines.wrappers@2020-12-05 20:05:50,973 -- DEBUG: Sample|InceptionResnetv2_Casia.transform ok bob.bio.face.test.test_embeddings.test_idiap_inceptionv2_msceleb ... bob.pipelines.wrappers@2020-12-05 20:08:47,854 -- DEBUG: Sample|InceptionResnetv2_MsCel.transform ok bob.bio.face.test.test_embeddings.test_idiap_inceptionv2_msceleb_memory_demanding ... bob.pipelines.wrappers@2020-12-05 20:11:51,421 -- DEBUG: Sample|InceptionResnetv2_MsCel.transform ok
Solved with !81 (merged)