Skip to content

arcface demo - #6386

Merged
nihui merged 22 commits into
Tencent:masterfrom
heabeounMKTO:arcface-example
Nov 26, 2025
Merged

arcface demo#6386
nihui merged 22 commits into
Tencent:masterfrom
heabeounMKTO:arcface-example

Conversation

@heabeounMKTO

@heabeounMKTO heabeounMKTO commented Nov 1, 2025

Copy link
Copy Markdown
Contributor
  • added arcface embedding extraction demo using yolov8-face to extract face keypoints and extract embedding from detected face
  • added calib3d to cmake for cv::estimateAffinePartial2D
  • added optional comparison function for comparing embeddings

@tencent-adm

tencent-adm commented Nov 1, 2025

Copy link
Copy Markdown
Member

CLA assistant check
All committers have signed the CLA.

@github-actions

github-actions Bot commented Nov 1, 2025

Copy link
Copy Markdown

The binary size change of libncnn.so (bytes)

architecture base size pr size difference
x86_64 15307488 15208240 -99248 😘
armhf 6225824 6210540 -15284 😘
aarch64 9527072 9523592 -3480 😘

Comment thread examples/arcface.cpp Outdated
dst[i].x = ARCFACE_DST[i][0] * ratio + diff_x;
dst[i].y = ARCFACE_DST[i][1] * ratio;
}
output = cv::estimateAffinePartial2D(lmk, dst, cv::noArray(), cv::LMEDS, 0.99, 2000, 0.99, 10);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is ncnn::get_affine_transform for this purpose.
so we can remove opencv_calib3d dependency.

Comment thread examples/arcface.cpp Outdated
}


void normalize_arcface(std::array<float, 512> &feature) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

port to std::vector for c++03 compatibility

Comment thread examples/arcface.cpp Outdated
#include <float.h>
#include <stdio.h>
#include <vector>
#include <iostream>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use printf/fprintf for logging and file io
drop the iostream header

Comment thread examples/arcface.cpp Outdated
Comment on lines +40 to +52
const float mean_vals[][3] = {
{0.f, 0.f, 0.f},
{0.f, 0.f, 0.f},
{0.f, 0.f, 0.f},
{0.f, 0.f, 0.f},
};

const float norm_vals[][3] = {
{1 / 255.f, 1 / 255.f, 1 / 255.f},
{1 / 255.f, 1 / 255.f, 1 / 255.f},
{1 / 255.f, 1 / 255.f, 1 / 255.f},
{1 / 255.f, 1 / 255.f, 1 / 255.f},
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare mean_vals and norm_vals as local variable

I see that only the first row is used

Comment thread examples/arcface.cpp Outdated
}

/* you can extract another image and compare using get_similarity()
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ask the user to provide two images and output the similarity

./arcface a.jpg b.jpg
a.jpg face = x y w h
b.jpg face = x y w h
similarity = 0.9555

@heabeounMKTO

Copy link
Copy Markdown
Contributor Author

@nihui ive made changes according to your request that includes:

  • replace cv::calib3d fucntion with an ncnn one
  • replace std::array with std::vector
  • use printf and fprintf
  • local variables for mean , norm and arcface_dst
  • command line args for inputting two images
    please tell me if there is anything you want to change , thanks

@heabeounMKTO
heabeounMKTO requested a review from nihui November 4, 2025 13:06
@nihui

nihui commented Nov 5, 2025

Copy link
Copy Markdown
Member

hello, please enable github action in YOUR FORKED REPO to make code-format workflow work

@heabeounMKTO

Copy link
Copy Markdown
Contributor Author

hello, please enable github action in YOUR FORKED REPO to make code-format workflow work

I already enabled it in my forked repo in
Settings > Actions > General > Actions permissions > Allow all actions and reusable workflows

@nihui

nihui commented Nov 5, 2025

Copy link
Copy Markdown
Member

hello, please enable github action in YOUR FORKED REPO to make code-format workflow work

I already enabled it in my forked repo in Settings > Actions > General > Actions permissions > Allow all actions and reusable workflows

Then you need to commit and push a dummy change (eg. adding an empty line) to trigger your code-format workflow.

@nihui

nihui commented Nov 5, 2025

Copy link
Copy Markdown
Member

goto https://github.com/heabeounMKTO/ncnn/settings/actions

check Allow all actions and reusable workflows in Actions permissions
check Read and write permissions in Workflow permissions

push a dummy commit

@heabeounMKTO

heabeounMKTO commented Nov 5, 2025

Copy link
Copy Markdown
Contributor Author

goto https://github.com/heabeounMKTO/ncnn/settings/actions

check Allow all actions and reusable workflows in Actions permissions check Read and write permissions in Workflow permissions

push a dummy commit

this is my permissions in the earlier commit, still doesnt seem to work?
Screenshot_2025-11-05_18-55-48

@nihui

nihui commented Nov 5, 2025

Copy link
Copy Markdown
Member

https://github.com/heabeounMKTO/ncnn/actions
The enabled workflows can be found there

@heabeounMKTO

Copy link
Copy Markdown
Contributor Author

https://github.com/heabeounMKTO/ncnn/actions The enabled workflows can be found there

ohh thanks, i am not familiar with github actions.

@heabeounMKTO

Copy link
Copy Markdown
Contributor Author

i got an error on code format run
The job was not started because your account is locked due to a billing issue. , do i need to setup billing?

@nihui

nihui commented Nov 7, 2025

Copy link
Copy Markdown
Member

i got an error on code format run The job was not started because your account is locked due to a billing issue. , do i need to setup billing?

You can refer to GitHub's official documentation on creating support tickets for assistance with account and billing issues:
https://docs.github.com/en/support/contacting-github-support/creating-a-support-ticket

Since this is an account-specific issue that's preventing the workflow from running, you'll need to resolve it with GitHub Support before the code format check can complete. The pull request cannot be merged until the code format check passes.

@heabeounMKTO

Copy link
Copy Markdown
Contributor Author

@nihui i've resolved the code formatting issue now, thanks for bearing with me!

@nihui nihui closed this Nov 7, 2025
@nihui nihui reopened this Nov 7, 2025
@nihui
nihui requested a review from Copilot November 7, 2025 05:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new example demonstrating face recognition using YOLOv8-face for face detection and ArcFace for embedding extraction. The example loads two face images, detects faces, extracts embeddings, and computes similarity between them.

  • Implements complete face detection and recognition pipeline with YOLOv8-face and ArcFace models
  • Adds utility classes for bounding box management and non-maximum suppression
  • Integrates the new example into the CMake build system

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 21 comments.

File Description
examples/arcface.cpp New example implementing face detection with YOLOv8-face and embedding extraction with ArcFace, including utilities for bbox operations, NMS, and face alignment
examples/CMakeLists.txt Registers the new arcface example in the build system

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/arcface.cpp Outdated
Comment thread examples/arcface.cpp
Comment thread examples/arcface.cpp
Comment thread examples/arcface.cpp
Comment thread examples/arcface.cpp Outdated
Comment thread examples/arcface.cpp
Comment thread examples/arcface.cpp
Comment thread examples/arcface.cpp Outdated
Comment thread examples/arcface.cpp
Comment thread examples/arcface.cpp
@heabeounMKTO

Copy link
Copy Markdown
Contributor Author

hello @nihui , would you like me to commit the copilot suggested changes?

@nihui

nihui commented Nov 10, 2025

Copy link
Copy Markdown
Member

hello @nihui , would you like me to commit the copilot suggested changes?

Hello, it depends on whether you agree with copilot's suggestions. Sometimes copilot's suggested modifications are reasonable, in which case you should accept and submit the changes. Other times, they are not, in which case you should ignore them and choose to resolve conversation.

heabeounMKTO and others added 8 commits November 10, 2025 10:12
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@heabeounMKTO

Copy link
Copy Markdown
Contributor Author

ive added some suggestions from the bot @nihui , please review and give me some feedback, thanks !

@nihui nihui left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the license header at the beginning.
The rest seems fine to me.
Thank you.

Comment thread examples/arcface.cpp
@heabeounMKTO
heabeounMKTO requested a review from nihui November 26, 2025 03:25
@nihui nihui closed this Nov 26, 2025
@nihui nihui reopened this Nov 26, 2025
@nihui
nihui merged commit 32e7d53 into Tencent:master Nov 26, 2025
22 checks passed
@nihui

nihui commented Nov 26, 2025

Copy link
Copy Markdown
Member

Thanks for your contribution !

@heabeounMKTO
heabeounMKTO deleted the arcface-example branch November 26, 2025 07:09
@heabeounMKTO

Copy link
Copy Markdown
Contributor Author

Thanks for your contribution !

thank you!

@nihui

nihui commented Nov 26, 2025

Copy link
Copy Markdown
Member

Thanks for your contribution !

thank you!

Well, I found a few issues while testing the ArcFace sample, which I fixed.
The parts that might be helpful with you.
fec6338

@heabeounMKTO

Copy link
Copy Markdown
Contributor Author

Well, I found a few issues while testing the ArcFace sample, which I fixed. The parts that might be helpful with you. fec6338

thanks for catching this one i copied another model that was doing conf like so [x, y, w, h, conf, class_scores..., kp1_conf, kp1_x, kp1_y] 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants