deepinsight / insightface

State-of-the-art 2D and 3D Face Analysis Project
https://insightface.ai
23.3k stars 5.41k forks source link

What does `det_size` actually do? #2512

Closed changchiyou closed 8 months ago

changchiyou commented 9 months ago

What does det_size actually do? I can't find any document talking about it. https://github.com/deepinsight/insightface/blob/01a34cd94f7b0f4a3f6c84ce4b988668ad7be329/python-package/insightface/app/face_analysis.py#L47


I have do some research by myself. My understanding is that the photo will be scaled based on det_size, and this is the sole purpose of det_size. But I am not sure whether det_size is a fixed number for each detection model or not.

https://github.com/deepinsight/insightface/blob/01a34cd94f7b0f4a3f6c84ce4b988668ad7be329/python-package/insightface/model_zoo/retinaface.py#L207-L221

BTW, there are acutally MANY version of det_size:

  1. https://github.com/deepinsight/insightface/blob/01a34cd94f7b0f4a3f6c84ce4b988668ad7be329/examples/in_swapper/inswapper_main.py#L16
  2. https://github.com/deepinsight/insightface/blob/01a34cd94f7b0f4a3f6c84ce4b988668ad7be329/examples/mask_renderer.py#L14
  3. https://github.com/deepinsight/insightface/blob/01a34cd94f7b0f4a3f6c84ce4b988668ad7be329/alignment/synthetics/tools/prepare_synthetics.py#L15
  4. https://github.com/deepinsight/insightface/blob/01a34cd94f7b0f4a3f6c84ce4b988668ad7be329/reconstruction/gaze/test_gaze.py#L64-L65
  5. Face recognition with InsightFace or how CatBoost guessed names
    app = FaceAnalysis(name="buffalo_l",providers=['CUDAExecutionProvider'])
    app.prepare(ctx_id=0, det_size=(256, 256))

This makes me feel confused, and I would be concerned that arbitrary changes to the default values might lead to a decrease in the model's accuracy in judgment.

kormalev commented 9 months ago

Most detectors can work with different input sizes, within a reasonable range. The choice of detector's input size (det_size) is based on some common sense judgement:

changchiyou commented 9 months ago

@kormalev That makes sense. It seems like I need to strike a balance between speed and accuracy, right?

changchiyou commented 9 months ago

https://github.com/deepinsight/insightface/issues/1518