davidsandberg / facenet

Face recognition using Tensorflow
MIT License
13.74k stars 4.8k forks source link

Issue with Tensor Names in DeepSORT Integration with FaceNET Model #1243

Open droczy opened 11 months ago

droczy commented 11 months ago

My primary objective is to anonymize faces in videos. Initially, I employed CenterFace for face detection. However, I noticed that especially in side profiles or under poor lighting conditions, the bounding boxes tend to jitter or shift abruptly. This observation led me to consider implementing face tracking to achieve more consistent results. I moved towards DeepSORT because of its resilience, especially when bounding boxes disappear or fluctuate rapidly. While DeepSORT is traditionally designed for individual tracking using the Mars model, my focus is on tracking faces. I've chosen the FaceNET model for face tracking.

I've encountered a challenge: DeepSORT requires the specification of input and output tensor names. I'm utilizing the pre-trained model (20180402-114759) available in the repository. However, when I attempt to visualize the model using Tensorboard or retrieve the list of tensors, I'm unable to identify the correct tensor names. TensorFlow often automatically names the input tensor as 'input:0', but this tensor appears to be missing from the model.

Could anyone assist me in identifying the correct tensor names?

System Specifications:

OS: Ubuntu 22.04.3 LTS
TensorFlow Version: 2.14.0
DeepSORT Version: Updated for TensorFlow 2.x (utilizing tf.compat.v1)

Relevant Code from DeepSORT (generate_detections.py): `class ImageEncoder(object):

def __init__(self, checkpoint_filename, input_name="images",
             output_name="features"):
    self.session = tf.compat.v1.Session()
    with tf.compat.v1.gfile.GFile(checkpoint_filename, "rb") as file_handle:
        graph_def = tf.compat.v1.GraphDef()
        graph_def.ParseFromString(file_handle.read())
    tf.compat.v1.import_graph_def(graph_def, name="net")
    self.input_var = tf.compat.v1.get_default_graph().get_tensor_by_name("input:0")
    self.output_var = tf.compat.v1.get_default_graph().get_tensor_by_name("embeddings:0")`

Error Log: File ".../deep_sort/tools/generate_detections.py", line 98, in create_box_encoder image_encoder = ImageEncoder(model_filename, input_name, output_name) File ".../deep_sort/tools/generate_detections.py", line 80, in __init__ self.input_var = tf.compat.v1.get_default_graph().get_tensor_by_name("input:0")

If you need further code snippets or have any questions/suggestions, please don't hesitate to reach out.