Facenet: "sess.run" the certain layer based on the pre-trained model (aim at feature extraction)

Created on 7 May 2017  ·  11Comments  ·  Source: davidsandberg/facenet

Thanks a lot for your excellent work and code!

I've success running the code and I can extract a 128-dim feature via some code like this

embeddings = tf.get_default_graph().get_tensor_by_name("embeddings:0")
emb = sess.run(embeddings, feed_dict=feed_dict)

NOW, I would like to get a feature whose dim is bigger than 128 , however, I can not get the detailed info about network structure and the certain layer's name, could you help me with it?

Best wishes!

Most helpful comment

In validate_on_lfw.py there is such a line:
tf.get_default_graph().get_tensor_by_name("embeddings:0")
which gives You the output layer
When You replace it with:
tf.get_default_graph().get_tensor_by_name('InceptionResnetV1/Logits/Dropout/cond/Merge:0')
You get the last hidden layer, which is 1792-dim

All 11 comments

Hi,
I'm not sure which layer you are referring to. To get a larger feature vector that makes sense you would probably have to retrain the feature extraction model. The feature vectors for the old models have 1792 dimensions, so maybe that could be something. But the models with 128d feature vectors seems to perform equally well so I don't know why you need a longer feature vector.

thanks a lot for your reply,
That's because I'm working on some different tasks(not face recognizing but also about face, while the 128-dim feature which focuses on maximizing the feature's distance from different people and minimizing the distance from the same persons is a little 'special'. So I would like to get the earlier layer feature, my question is in which file could I find the definition of the network structure ?(I've been looking for it for so long but still could not find it)

在 2017年5月8日,00:49,David Sandberg notifications@github.com 写道:

Hi,
I'm not sure which layer you are referring to. To get a larger feature vector that makes sense you would probably have to retrain the feature extraction model. The feature vectors for the old models have 1792 dimensions, so maybe that could be something. But the models with 128d feature vectors seems to perform equally well so I don't know why you need a longer feature vector.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

In validate_on_lfw.py there is such a line:
tf.get_default_graph().get_tensor_by_name("embeddings:0")
which gives You the output layer
When You replace it with:
tf.get_default_graph().get_tensor_by_name('InceptionResnetV1/Logits/Dropout/cond/Merge:0')
You get the last hidden layer, which is 1792-dim

Thanks @g-glowacki!!
@AlbertDu, the model definition used for the pretrained models can be found in models.inception_resnet_v1.py.

@g-glowacki @davidsandberg Thanks a lot!I'm so impressed by the community of facenet!

I'm still a bit confused because I could not find the tensor name like "InceptionResnetV1/Logits/Dropout/cond/Merge:0",
would you like to tell me how to get that?

@g-glowacki

Would you mind telling me the way to get the the name

InceptionResnetV1/Logits/Dropout/cond/Merge:0

?

Thanks a lot

What model Are You using? You can use tensorboard to visualise your model and see all layers.

inception v1,I tried the tensorboard, but the log-output is very hard to understand, like this,

graph

在 2017年5月11日,21:07,g-glowacki notifications@github.com 写道:

What model Are You using? You can use tensorboard to visualise your model and see all layers.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/davidsandberg/facenet/issues/266#issuecomment-300783457, or mute the thread https://github.com/notifications/unsubscribe-auth/ANHFjkSiIYj69r3mwNwN257QPMkjmKRqks5r4wgdgaJpZM4NTNH2.

You should expand import:Inception:logits:dropout:cond. Then You should see Merge operation.
graph-run

@g-glowacki Thanks a lot!!!

@g-glowacki Thanks a lot!!!

in the png file you uploaded, I didn't see the "import:Inception:logits:dropout:cond", could you please tell where is it? Thanks.

Was this page helpful?
0 / 5 - 0 ratings