Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBFace using with Android tflite format #8

Open
Zeleni9 opened this issue Jun 2, 2021 · 3 comments
Open

DBFace using with Android tflite format #8

Zeleni9 opened this issue Jun 2, 2021 · 3 comments

Comments

@Zeleni9
Copy link

Zeleni9 commented Jun 2, 2021

Hello,

I have a question about using the db_keras.tflite model in Android. I am not sure the correct parameters for the face detector when generating anchors. If you can provide info about them that would be amazing. Info that I am lacking are feature sizes & anchor sizes with anchor ratios, here I have added some random data from another object detector:

private static final int[] feature_map_sizes = new int[] {33, 17, 9, 5, 3};

private static final float[][] anchor_sizes = new float[][] {{0.04f, 0.056f}, {0.08f, 0.11f}, {0.16f, 0.22f}, {0.32f, 0.45f}, {0.64f, 0.72f}};

private static final float[] anchor_ratios = new float[] {1.0f, 0.62f, 0.42f};`

If u have pre-processing and post-processing for face detector in Android Java code that would help immensely. Thank you.

@terryky
Copy link
Owner

terryky commented Jun 5, 2021

I don't have any information about the db_keras.tflite you mentioned.
The pre-processing and post-processing depend on the tflite model, so please ask the person who designed that model.

@Zeleni9
Copy link
Author

Zeleni9 commented Jun 6, 2021

It is dbface model from your repository just didnt write full name dbface_keras_480x640_float32_nhwc.tflite DBFace Model

@terryky
Copy link
Owner

terryky commented Jun 6, 2021

This model (dbface_keras_480x640_float32_nhwc.tflite) doesn't require anchors.
The detected region can be obtained directly from the inference output.
please refer the post processing code as below:

decode_bounds (std::list<face_t> &face_list, float score_thresh)
{
face_t face_item;
float *scores_ptr = (float *)s_detect_tensor_hm.ptr;
int score_w = s_detect_tensor_hm.dims[2];
int score_h = s_detect_tensor_hm.dims[1];
for (int y = 0; y < score_h; y ++)
{
for (int x = 0; x < score_w; x ++)
{
int idx = y * score_w + x;
float score = scores_ptr[idx];
if (score < score_thresh)
continue;
float *p = get_bbox_ptr (idx);
float bx = p[0];
float by = p[1];
float bw = p[2];
float bh = p[3];
fvec2 topleft, btmright;
topleft.x = (x - bx) / (float)score_w;
topleft.y = (y - by) / (float)score_h;
btmright.x = (x + bw) / (float)score_w;
btmright.y = (y + bh) / (float)score_h;
face_item.score = score;
face_item.topleft = topleft;
face_item.btmright = btmright;
/* landmark positions (5 keys) */
float *lm = get_landmark_ptr (idx);
for (int j = 0; j < kFaceKeyNum; j ++)
{
float lx = lm[j ] * 4;
float ly = lm[j + 5] * 4;
lx = (_exp (lx) + x) / (float)score_w;
ly = (_exp (ly) + y) / (float)score_h;
face_item.keys[j].x = lx;
face_item.keys[j].y = ly;
}
face_list.push_back (face_item);
}
}
return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants