Skip to content
Snippets Groups Projects

Test Facenet

Merged Laurent COLBOIS requested to merge test-facenet into master
1 unresolved thread

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

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • @lcolbois but tests are passing.

  • Author Maintainer

    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'
  • we need to remove these tensorflow.contrib imports.

  • Thanks, Laurent.

    Weights are exactly the same from TF2 imported model and TF1. I dumped both and compared them one by one

    /[MY_USER]/gitlab/bob/bob.nightlies/TF1.hdf5
    /[MY_USER]/tpereira/gitlab/bob/bob.nightlies/TF2.hdf5
    /[MY_USER]/gitlab/bob/bob.nightlies/compare_tf1_tf2.py
  • Normalization is also the sample.

    I don't know what can be wrong

  • Laurent COLBOIS added 2 commits

    added 2 commits

    • 62986b36 - Added reference embeddings for all TF networks
    • 6cca593f - Added TF1/TF2 embedding comparison tests for all Inception networks. Fixed...

    Compare with previous version

  • Author Maintainer

    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 Pereira
    • Author Maintainer

      PS: 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
    • Please register or sign in to reply
  • It's probably an activation or some residual scaling ....

  • Author Maintainer

    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 COLBOIS
  • Author Maintainer

    Found 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 COLBOIS
  • I love you man.

    That's it.

    I'll push a fix and correct the checkpoints

  • There you go.

    Facenet passes now with your test @lcolbois

  • Tests are passing with all InceptionResnetv1 models :-)

  • mentioned in commit c566524f

  • but the tests are still skipped, what is the issue?

  • 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)

Please register or sign in to reply
Loading