aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-10-21 17:47:57 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-10-21 17:47:57 +0200
commit8b8acffcf5f1e9e9ddb552b8ac125e50f68987ac (patch)
tree9b618133a468585087ff4b014b22029d40b24bc5
parent2ce585cc96a3fffba65f1bafbfbc796c6370308f (diff)
downloadfacedet-8b8acffcf5f1e9e9ddb552b8ac125e50f68987ac.tar.gz
facedet-8b8acffcf5f1e9e9ddb552b8ac125e50f68987ac.zip
Rename to facedetHEADv0.1.0master
-rw-r--r--Makefile18
-rw-r--r--README.md30
-rw-r--r--convert.py6
-rw-r--r--facedet.c (renamed from yunet.c)108
-rw-r--r--facedet.h (renamed from yunet.h)34
-rw-r--r--gemm.c10
-rw-r--r--gemm.h10
-rw-r--r--image.h4
-rw-r--r--main.c22
-rw-r--r--nn.c20
-rw-r--r--nn.h18
-rw-r--r--overlay.c4
-rw-r--r--overlay.h8
13 files changed, 146 insertions, 146 deletions
diff --git a/Makefile b/Makefile
index b9a4b88..5d7036f 100644
--- a/Makefile
+++ b/Makefile
@@ -4,20 +4,20 @@ CFLAGS = -O3 -std=c11 -Wall -Wextra -Wpedantic
LDLIBS = -lm
BUILD = build
-CORE = yunet.c nn.c gemm.c
+CORE = facedet.c nn.c gemm.c
MODEL_HEADER = model_data.h
-MODEL_CPPFLAGS = -DYUNET_MODEL_HEADER='"$(abspath $(MODEL_HEADER))"'
+MODEL_CPPFLAGS = -DFACEDET_MODEL_HEADER='"$(abspath $(MODEL_HEADER))"'
REFINER_HEADER =
ifneq ($(strip $(REFINER_HEADER)),)
-MODEL_CPPFLAGS += -DYUNET_REFINER_HEADER='"$(abspath $(REFINER_HEADER))"'
+MODEL_CPPFLAGS += -DFACEDET_REFINER_HEADER='"$(abspath $(REFINER_HEADER))"'
endif
-HEADERS = yunet.h nn.h gemm.h $(MODEL_HEADER) $(REFINER_HEADER)
-OBJECTS = $(BUILD)/yunet.o $(BUILD)/nn.o $(BUILD)/gemm.o
+HEADERS = facedet.h nn.h gemm.h $(MODEL_HEADER) $(REFINER_HEADER)
+OBJECTS = $(BUILD)/facedet.o $(BUILD)/nn.o $(BUILD)/gemm.o
.PHONY: all model clean
-all: $(BUILD)/yunet $(BUILD)/libyunet.a $(BUILD)/libyunet.so $(BUILD)/libimage.so
+all: $(BUILD)/facedet $(BUILD)/libfacedet.a $(BUILD)/libfacedet.so $(BUILD)/libimage.so
$(BUILD):
mkdir -p $(BUILD)
@@ -25,7 +25,7 @@ $(BUILD):
$(BUILD)/%.o: %.c $(HEADERS) | $(BUILD)
$(CC) $(CPPFLAGS) $(MODEL_CPPFLAGS) $(CFLAGS) -c $< -o $@
-$(BUILD)/libyunet.a: $(OBJECTS)
+$(BUILD)/libfacedet.a: $(OBJECTS)
$(AR) rcs $@ $^
$(BUILD)/main.o $(BUILD)/image.o: image.h
@@ -33,10 +33,10 @@ $(BUILD)/image.o: third_party/stb/stb_image.h
$(BUILD)/main.o $(BUILD)/overlay.o: overlay.h
$(BUILD)/overlay.o $(BUILD)/draw.o: draw.h
-$(BUILD)/yunet: $(BUILD)/main.o $(BUILD)/image.o $(BUILD)/overlay.o $(BUILD)/draw.o $(BUILD)/libyunet.a
+$(BUILD)/facedet: $(BUILD)/main.o $(BUILD)/image.o $(BUILD)/overlay.o $(BUILD)/draw.o $(BUILD)/libfacedet.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
-$(BUILD)/libyunet.so: $(CORE) $(HEADERS) | $(BUILD)
+$(BUILD)/libfacedet.so: $(CORE) $(HEADERS) | $(BUILD)
$(CC) $(CPPFLAGS) $(MODEL_CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared -fPIC -o $@ $(CORE) $(LDLIBS)
$(BUILD)/libimage.so: image.c image.h third_party/stb/stb_image.h | $(BUILD)
diff --git a/README.md b/README.md
index bdc75dc..01942a2 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-# YuNet 2026may
+# facedet
-A CPU-only face detector for `face_detection_yunet_2026may`.
+A CPU-only face detector using the YuNet `face_detection_yunet_2026may` model.
## Build and run
@@ -11,11 +11,11 @@ embedded in the binary.
```sh
make
-./build/yunet photo.jpg
-./build/yunet photo.png 0.6 0.3
-./build/yunet image.ppm
-./build/yunet photo.jpg -o overlay.ppm > faces.json
-./build/yunet --out overlay.ppm photo.png 0.6 0.3
+./build/facedet photo.jpg
+./build/facedet photo.png 0.6 0.3
+./build/facedet image.ppm
+./build/facedet photo.jpg -o overlay.ppm > faces.json
+./build/facedet --out overlay.ppm photo.png 0.6 0.3
```
@@ -26,7 +26,7 @@ Input is JPEG, PNG, or binary PPM (`P6`, RGB, maxval 255), with dimensions from
1 to 4096.
```sh
-./build/yunet photo.jpg > faces.json
+./build/facedet photo.jpg > faces.json
```
Standard output contains one JSON object:
@@ -51,26 +51,26 @@ decoded image with green face boxes, confidence labels, and five landmark dots.
## C API
-Include `yunet.h` and link `build/libyunet.a` with `-lm`.
+Include `facedet.h` and link `build/libfacedet.a` with `-lm`.
-1. Create a context with `yunet_create(padded_width, padded_height)`. Both dimensions
+1. Create a context with `facedet_create(padded_width, padded_height)`. Both dimensions
must be multiples of 32 in the range 32 through 4096. Check for `NULL`.
-2. Fill it with `yunet_set_rgb`, or fill the buffer returned by `yunet_input` with
+2. Fill it with `facedet_set_rgb`, or fill the buffer returned by `facedet_input` with
float32 BGR CHW values in `[0, 255]`.
-3. Call `yunet_run`, then `yunet_decode` with an output array and its capacity.
+3. Call `facedet_run`, then `facedet_decode` with an output array and its capacity.
Negative return values indicate errors. The output capacity limits returned
detections, not the number of candidates considered.
-4. Reuse the context for images with the same padded dimensions. Call `yunet_free`
+4. Reuse the context for images with the same padded dimensions. Call `facedet_free`
when finished. Use separate contexts for concurrent inference.
The command-line implementation in `main.c` demonstrates the complete flow.
-`yunet_map` exposes raw CHW head tensors for numerical checks; classification and
+`facedet_map` exposes raw CHW head tensors for numerical checks; classification and
objectness maps contain logits, so the decoder applies sigmoid before computing
`sqrt(classification * objectness)`.
`nn.c` contains the required convolution, pooling, addition, and resizing
operations. `gemm.c` uses AArch64 NEON or runtime-selected x86-64 AVX2/FMA,
-with a portable C fallback. Define `YUNET_SCALAR` to disable explicit SIMD kernels.
+with a portable C fallback. Define `FACEDET_SCALAR` to disable explicit SIMD kernels.
## Model and regeneration
diff --git a/convert.py b/convert.py
index 429d122..678a6ba 100644
--- a/convert.py
+++ b/convert.py
@@ -153,7 +153,7 @@ def main():
onnx.checker.check_model(model)
heads = head_map(nodes)
plan, weights, shapes, offsets, arena = compile_plan(nodes, init, heads)
- lines = ["#ifndef YUNET_MODEL_DATA_H", "#define YUNET_MODEL_DATA_H", "",
+ lines = ["#ifndef FACEDET_MODEL_DATA_H", "#define FACEDET_MODEL_DATA_H", "",
"static const float model_weight_data[] = {"]
weight_offsets = []
pos = 0
@@ -166,14 +166,14 @@ def main():
pos += len(flat)
lines += ["};", "", "static const float *const model_weights[] = {"]
lines += [f" model_weight_data + {off}," for off in weight_offsets]
- lines += ["};", "", "static const yunet_op model_ops[] = {"]
+ lines += ["};", "", "static const facedet_op model_ops[] = {"]
for p in plan:
fields = [p["op"], p.get("group", 0), p.get("k", 0), p.get("s", 0),
p.get("pad", 0), p.get("relu", 0), p.get("widx", 0),
*p["in_shape"], *p["out_shape"], p["in_off"][0],
p["in_off"][1] if len(p["in_off"]) > 1 else 0, p["out_off"]]
lines.append(" {" + ", ".join(map(str, fields)) + "},")
- lines += ["};", "", "static const yunet_map_info model_maps[] = {"]
+ lines += ["};", "", "static const facedet_map_info model_maps[] = {"]
for name, (tensor, sigmoid) in heads.items():
c, h, w = shapes[tensor]
lines.append(f' {{"{name}", {offsets[tensor]}, {c}, {h}, {w}, {int(sigmoid)}}},')
diff --git a/yunet.c b/facedet.c
index 4e38f71..33f72bd 100644
--- a/yunet.c
+++ b/facedet.c
@@ -1,4 +1,4 @@
-#include "yunet.h"
+#include "facedet.h"
#include "gemm.h"
#include "nn.h"
@@ -14,45 +14,45 @@ typedef struct {
int op, group, k, s, pad, relu, widx;
int cin, ih, iw, cout, oh, ow;
size_t in0_off, in1_off, out_off;
-} yunet_op;
+} facedet_op;
typedef struct {
const char *name;
size_t off;
int c, h, w, sigmoid;
-} yunet_map_info;
+} facedet_map_info;
-#ifndef YUNET_MODEL_HEADER
-#define YUNET_MODEL_HEADER "model_data.h"
+#ifndef FACEDET_MODEL_HEADER
+#define FACEDET_MODEL_HEADER "model_data.h"
#endif
-#include YUNET_MODEL_HEADER
-#ifdef YUNET_REFINER_HEADER
-#include YUNET_REFINER_HEADER
+#include FACEDET_MODEL_HEADER
+#ifdef FACEDET_REFINER_HEADER
+#include FACEDET_REFINER_HEADER
_Static_assert(REFINER_OP_COUNT == MODEL_OP_COUNT, "Refiner operation count mismatch");
_Static_assert(REFINER_MAP_COUNT == MODEL_MAP_COUNT, "Refiner map count mismatch");
_Static_assert(REFINER_ARENA_BYTES == MODEL_ARENA_BYTES, "Refiner arena mismatch");
#endif
-struct yunet {
+struct facedet {
int width, height, has_result;
unsigned char *arena;
- yunet_op ops[MODEL_OP_COUNT];
- yunet_map_info maps[MODEL_MAP_COUNT];
+ facedet_op ops[MODEL_OP_COUNT];
+ facedet_map_info maps[MODEL_MAP_COUNT];
float *packs[MODEL_OP_COUNT];
float *im2col, *bscratch;
const float *const *weights;
int is_refiner;
};
-static yunet *create_model(int width, int height, const yunet_op *ops,
- const yunet_map_info *maps, const float *const *weights) {
+static facedet *create_model(int width, int height, const facedet_op *ops,
+ const facedet_map_info *maps, const float *const *weights) {
if (width < 32 || height < 32 || width > 4096 || height > 4096 ||
width % 32 || height % 32)
return NULL;
size_t area = (size_t)(width / 32) * (height / 32);
if (area > SIZE_MAX / MODEL_ARENA_BYTES)
return NULL;
- yunet *m = calloc(1, sizeof *m);
+ facedet *m = calloc(1, sizeof *m);
if (!m)
return NULL;
m->width = width;
@@ -64,7 +64,7 @@ static yunet *create_model(int width, int height, const yunet_op *ops,
memset(m->arena, 0, (size_t)width * height * 3 * sizeof(float));
size_t max_col = 0, max_k = 0;
for (int i = 0; i < MODEL_OP_COUNT; i++) {
- yunet_op op = ops[i];
+ facedet_op op = ops[i];
/* All spatial dimensions scale from the 32x32 plan. Scaling every
* arena slot by the same area preserves its capacity and lifetime. */
op.ih *= height / 32;
@@ -77,10 +77,10 @@ static yunet *create_model(int width, int height, const yunet_op *ops,
m->ops[i] = op;
if (op.op == OP_CONV && op.group == 1) {
int k = op.cin * op.k * op.k;
- m->packs[i] = malloc(yunet_gemm_pack_a_bytes(op.cout, k));
+ m->packs[i] = malloc(facedet_gemm_pack_a_bytes(op.cout, k));
if (!m->packs[i])
goto fail;
- yunet_gemm_pack_a(weights[op.widx], op.cout, k, m->packs[i]);
+ facedet_gemm_pack_a(weights[op.widx], op.cout, k, m->packs[i]);
if ((size_t)k > max_k)
max_k = (size_t)k;
size_t col = op.k == 3 ? (size_t)k * op.oh * op.ow : 0;
@@ -102,17 +102,17 @@ static yunet *create_model(int width, int height, const yunet_op *ops,
}
return m;
fail:
- yunet_free(m);
+ facedet_free(m);
return NULL;
}
-yunet *yunet_create(int width, int height) {
+facedet *facedet_create(int width, int height) {
return create_model(width, height, model_ops, model_maps, model_weights);
}
-yunet *yunet_create_refiner(void) {
-#ifdef YUNET_REFINER_HEADER
- yunet *m = create_model(160, 160, refiner_ops, refiner_maps, refiner_weights);
+facedet *facedet_create_refiner(void) {
+#ifdef FACEDET_REFINER_HEADER
+ facedet *m = create_model(160, 160, refiner_ops, refiner_maps, refiner_weights);
if (m)
m->is_refiner = 1;
return m;
@@ -121,7 +121,7 @@ yunet *yunet_create_refiner(void) {
#endif
}
-void yunet_free(yunet *m) {
+void facedet_free(facedet *m) {
if (!m)
return;
for (int i = 0; i < MODEL_OP_COUNT; i++)
@@ -132,19 +132,19 @@ void yunet_free(yunet *m) {
free(m);
}
-float *yunet_input(yunet *m) {
+float *facedet_input(facedet *m) {
if (!m)
return NULL;
m->has_result = 0;
return (float *)m->arena;
}
-int yunet_set_rgb(yunet *m, const unsigned char *rgb, int width, int height, size_t row_bytes) {
+int facedet_set_rgb(facedet *m, const unsigned char *rgb, int width, int height, size_t row_bytes) {
if (!m || !rgb || width < 1 || height < 1 || width > m->width || height > m->height ||
row_bytes < (size_t)width * 3 ||
(height > 1 && row_bytes > (SIZE_MAX - (size_t)width * 3) / (size_t)(height - 1)))
return -1;
- float *input = yunet_input(m);
+ float *input = facedet_input(m);
size_t plane = (size_t)m->width * m->height;
memset(input, 0, plane * 3 * sizeof(float));
for (int y = 0; y < height; y++) {
@@ -156,7 +156,7 @@ int yunet_set_rgb(yunet *m, const unsigned char *rgb, int width, int height, siz
return 0;
}
-int yunet_run(yunet *m) {
+int facedet_run(facedet *m) {
if (!m)
return -1;
m->has_result = 0;
@@ -166,7 +166,7 @@ int yunet_run(yunet *m) {
return -1;
unsigned char *a = m->arena;
for (int i = 0; i < MODEL_OP_COUNT; i++) {
- yunet_op op = m->ops[i];
+ facedet_op op = m->ops[i];
const float *in0 = (const float *)(a + op.in0_off);
float *out = (float *)(a + op.out_off);
switch (op.op) {
@@ -174,29 +174,29 @@ int yunet_run(yunet *m) {
size_t n = (size_t)op.oh * op.ow;
const float *bias = m->weights[op.widx + 1];
if (op.group == 1 && op.k == 1 && op.s == 1) {
- yunet_gemm(m->packs[i], op.cout, op.cin, in0, (size_t)op.ih * op.iw, (int)n,
+ facedet_gemm(m->packs[i], op.cout, op.cin, in0, (size_t)op.ih * op.iw, (int)n,
bias, op.relu, out, n, m->bscratch);
} else if (op.group == 1 && op.k == 3) {
- yunet_nn_im2col3(in0, op.cin, op.ih, op.iw, op.s, m->im2col, op.oh, op.ow);
- yunet_gemm(m->packs[i], op.cout, op.cin * 9, m->im2col, n, (int)n,
+ facedet_nn_im2col3(in0, op.cin, op.ih, op.iw, op.s, m->im2col, op.oh, op.ow);
+ facedet_gemm(m->packs[i], op.cout, op.cin * 9, m->im2col, n, (int)n,
bias, op.relu, out, n, m->bscratch);
} else if (op.group == op.cin && op.group == op.cout && op.k == 3 && op.s == 1) {
- yunet_nn_dwconv3(in0, op.cin, op.ih, op.iw, m->weights[op.widx], bias,
+ facedet_nn_dwconv3(in0, op.cin, op.ih, op.iw, m->weights[op.widx], bias,
op.relu, out);
} else {
- yunet_nn_conv2d(in0, op.cin, op.ih, op.iw, m->weights[op.widx], bias,
+ facedet_nn_conv2d(in0, op.cin, op.ih, op.iw, m->weights[op.widx], bias,
op.cout, op.k, op.s, op.pad, op.group, op.relu, out, op.oh, op.ow);
}
break;
}
case OP_MAXPOOL:
- yunet_nn_maxpool2(in0, op.cin, op.ih, op.iw, out);
+ facedet_nn_maxpool2(in0, op.cin, op.ih, op.iw, out);
break;
case OP_RESIZE2X:
- yunet_nn_resize2x(in0, op.cin, op.ih, op.iw, out);
+ facedet_nn_resize2x(in0, op.cin, op.ih, op.iw, out);
break;
case OP_ADD:
- yunet_nn_add(in0, (const float *)(a + op.in1_off), out, (size_t)op.cin * op.ih * op.iw);
+ facedet_nn_add(in0, (const float *)(a + op.in1_off), out, (size_t)op.cin * op.ih * op.iw);
break;
}
}
@@ -204,11 +204,11 @@ int yunet_run(yunet *m) {
return 0;
}
-const float *yunet_map(const yunet *m, const char *name, int *channels, int *height, int *width) {
+const float *facedet_map(const facedet *m, const char *name, int *channels, int *height, int *width) {
if (!m || !name || !m->has_result)
return NULL;
for (int i = 0; i < MODEL_MAP_COUNT; i++) {
- const yunet_map_info *mm = &m->maps[i];
+ const facedet_map_info *mm = &m->maps[i];
if (strcmp(mm->name, name) == 0) {
if (channels) *channels = mm->c;
if (height) *height = mm->h;
@@ -239,8 +239,8 @@ static float sample_rgb(const unsigned char *rgb, int width, int height, size_t
return (float)value;
}
-int yunet_refine(yunet *m, const unsigned char *rgb, int width, int height,
- size_t row_bytes, yunet_detection *faces, int count) {
+int facedet_refine(facedet *m, const unsigned char *rgb, int width, int height,
+ size_t row_bytes, facedet_detection *faces, int count) {
if (!m || !m->is_refiner || !rgb || width < 1 || height < 1 ||
width > 4096 || height > 4096 || count < 0 || (!faces && count) ||
row_bytes < (size_t)width * 3 ||
@@ -254,14 +254,14 @@ int yunet_refine(yunet *m, const unsigned char *rgb, int width, int height,
if (!points)
return -1;
for (int i = 0; i < count; i++) {
- const yunet_detection *face = &faces[i];
+ const facedet_detection *face = &faces[i];
if (!isfinite(face->x) || !isfinite(face->y) || !isfinite(face->w) ||
!isfinite(face->h) || face->w <= 0 || face->h <= 0)
goto fail;
double extent = fmax(face->w, face->h) * 1.3;
double ox = face->x + (double)face->w / 2 - extent / 2;
double oy = face->y + (double)face->h / 2 - extent / 2;
- float *input = yunet_input(m);
+ float *input = facedet_input(m);
for (int y = 0; y < 160; y++)
for (int x = 0; x < 160; x++)
for (int c = 0; c < 3; c++)
@@ -269,11 +269,11 @@ int yunet_refine(yunet *m, const unsigned char *rgb, int width, int height,
sample_rgb(rgb, width, height, row_bytes,
ox + (x + .5) * extent / 160 - .5,
oy + (y + .5) * extent / 160 - .5, 2 - c);
- if (yunet_run(m))
+ if (facedet_run(m))
goto fail;
int channels, h, w;
/* The landmark readout is the fixed center cell, independent of objectness. */
- const float *map = yunet_map(m, "kps_8", &channels, &h, &w);
+ const float *map = facedet_map(m, "kps_8", &channels, &h, &w);
if (!map || channels != 10 || h != 20 || w != 20)
goto fail;
for (int k = 0; k < 5; k++) {
@@ -294,7 +294,7 @@ fail:
return -1;
}
-static float iou_xywh(const yunet_detection *a, const yunet_detection *b) {
+static float iou_xywh(const facedet_detection *a, const facedet_detection *b) {
float x0 = a->x > b->x ? a->x : b->x;
float y0 = a->y > b->y ? a->y : b->y;
float x1 = (a->x + a->w) < (b->x + b->w) ? a->x + a->w : b->x + b->w;
@@ -307,7 +307,7 @@ static float iou_xywh(const yunet_detection *a, const yunet_detection *b) {
}
static int det_cmp(const void *pa, const void *pb) {
- const yunet_detection *a = pa, *b = pb;
+ const facedet_detection *a = pa, *b = pb;
if (a->score != b->score)
return a->score > b->score ? -1 : 1;
if (a->y != b->y)
@@ -315,7 +315,7 @@ static int det_cmp(const void *pa, const void *pb) {
return a->x < b->x ? -1 : a->x > b->x;
}
-int yunet_decode(const yunet *m, float score_thresh, float nms_iou, yunet_detection *out, int cap) {
+int facedet_decode(const facedet *m, float score_thresh, float nms_iou, facedet_detection *out, int cap) {
if (!m || m->is_refiner || !m->has_result || (!out && cap > 0) || cap < 0 ||
!isfinite(score_thresh) || score_thresh < 0.0f || score_thresh > 1.0f ||
!isfinite(nms_iou) || nms_iou < 0.0f || nms_iou > 1.0f)
@@ -331,24 +331,24 @@ int yunet_decode(const yunet *m, float score_thresh, float nms_iou, yunet_detect
size_t count = 0;
for (int lv = 0; lv < 3; lv++)
count += (size_t)(m->height / strides[lv]) * (m->width / strides[lv]);
- yunet_detection *cand = malloc(sizeof(*cand) * count);
+ facedet_detection *cand = malloc(sizeof(*cand) * count);
if (!cand)
return -1;
int n = 0;
for (int lv = 0; lv < 3; lv++) {
int H, W, s = strides[lv];
- const float *cls = yunet_map(m, names[lv][0], NULL, &H, &W);
- const float *obj = yunet_map(m, names[lv][1], NULL, NULL, NULL);
- const float *bbox = yunet_map(m, names[lv][2], NULL, NULL, NULL);
- const float *kps = yunet_map(m, names[lv][3], NULL, NULL, NULL);
+ const float *cls = facedet_map(m, names[lv][0], NULL, &H, &W);
+ const float *obj = facedet_map(m, names[lv][1], NULL, NULL, NULL);
+ const float *bbox = facedet_map(m, names[lv][2], NULL, NULL, NULL);
+ const float *kps = facedet_map(m, names[lv][3], NULL, NULL, NULL);
size_t hw = (size_t)H * W;
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
size_t i = (size_t)y * W + x;
- float sc = sqrtf(yunet_nn_sigmoid(cls[i]) * yunet_nn_sigmoid(obj[i]));
+ float sc = sqrtf(facedet_nn_sigmoid(cls[i]) * facedet_nn_sigmoid(obj[i]));
if (!isfinite(sc) || sc < score_thresh)
continue;
- yunet_detection *d = &cand[n];
+ facedet_detection *d = &cand[n];
float cx = (x + bbox[i]) * s;
float cy = (y + bbox[hw + i]) * s;
d->w = expf(bbox[2 * hw + i]) * s;
diff --git a/yunet.h b/facedet.h
index 44b6131..097e5aa 100644
--- a/yunet.h
+++ b/facedet.h
@@ -1,55 +1,55 @@
-#ifndef YUNET_H
-#define YUNET_H
+#ifndef FACEDET_H
+#define FACEDET_H
#include <stddef.h>
-typedef struct yunet yunet;
+typedef struct facedet facedet;
typedef struct {
float x, y, w, h;
float lmk[5][2];
float score;
-} yunet_detection;
+} facedet_detection;
/* Each dimension must be a multiple of 32 between 32 and 4096.
* A context owns mutable scratch space and is not safe for concurrent calls. */
-yunet *yunet_create(int width, int height);
-void yunet_free(yunet *m);
+facedet *facedet_create(int width, int height);
+void facedet_free(facedet *m);
/* The input is float32 BGR in CHW order, with values in [0, 255].
* The returned buffer belongs to the context. */
-float *yunet_input(yunet *m);
+float *facedet_input(facedet *m);
/* Interleaved RGB8 is converted to BGR CHW without resizing. The right and
* bottom padding are zero. Width and height cannot exceed the context size.
* The RGB buffer must contain at least (height-1)*row_bytes + width*3 bytes. */
-int yunet_set_rgb(yunet *m, const unsigned char *rgb, int width, int height, size_t row_bytes);
-int yunet_run(yunet *m);
+int facedet_set_rgb(facedet *m, const unsigned char *rgb, int width, int height, size_t row_bytes);
+int facedet_run(facedet *m);
/* Names are cls_s, obj_s, bbox_s, kps_s, with s in {8,16,32}.
* Maps use CHW order; cls and obj contain logits, not probabilities.
* The buffer belongs to the context and is valid until the next input change
* or run. NULL means that no result or no matching map is available. */
-const float *yunet_map(const yunet *m, const char *name, int *channels, int *height, int *width);
+const float *facedet_map(const facedet *m, const char *name, int *channels, int *height, int *width);
/* Detector contexts only. Returns the number of detections, or -1 for
* invalid arguments/no result. Results are sorted by score after greedy NMS, in input pixel coordinates,
* without clipping. Landmarks: right eye, left eye, nose, right/left mouth.
* cap limits returned detections, not candidates considered before sorting. */
-int yunet_decode(const yunet *m, float score_threshold, float nms_iou,
- yunet_detection *out, int cap);
+int facedet_decode(const facedet *m, float score_threshold, float nms_iou,
+ facedet_detection *out, int cap);
/* Returns NULL if optional refinement weights are unavailable or allocation
* fails. This context has a fixed 160x160 BGR input for landmark refinement. */
-yunet *yunet_create_refiner(void);
+facedet *facedet_create_refiner(void);
/* Replaces landmarks only; boxes, scores, and ordering remain unchanged.
* Each box defines a centered square crop with side 1.3*max(width,height).
* Bilinear sampling uses pixel centers and zero outside the RGB image.
- * RGB dimensions are 1..4096; buffer/stride requirements match yunet_set_rgb.
+ * RGB dimensions are 1..4096; buffer/stride requirements match facedet_set_rgb.
* Returns 0 on success, -1 on error. All detections remain unchanged on error.
- * m must be a context returned by yunet_create_refiner. */
-int yunet_refine(yunet *m, const unsigned char *rgb, int width, int height,
- size_t row_bytes, yunet_detection *faces, int count);
+ * m must be a context returned by facedet_create_refiner. */
+int facedet_refine(facedet *m, const unsigned char *rgb, int width, int height,
+ size_t row_bytes, facedet_detection *faces, int count);
#endif
diff --git a/gemm.c b/gemm.c
index 2105bc3..90d38ae 100644
--- a/gemm.c
+++ b/gemm.c
@@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>
-void yunet_gemm_pack_a(const float *a, int m, int k, float *pack) {
+void facedet_gemm_pack_a(const float *a, int m, int k, float *pack) {
int mt = (m + 7) / 8;
for (int t = 0; t < mt; t++) {
float *p = pack + (size_t)t * 8 * k;
@@ -15,9 +15,9 @@ void yunet_gemm_pack_a(const float *a, int m, int k, float *pack) {
}
}
-size_t yunet_gemm_pack_a_bytes(int m, int k) { return (size_t)((m + 7) / 8) * 8 * k * sizeof(float); }
+size_t facedet_gemm_pack_a_bytes(int m, int k) { return (size_t)((m + 7) / 8) * 8 * k * sizeof(float); }
-#if defined(__aarch64__) && !defined(YUNET_SCALAR)
+#if defined(__aarch64__) && !defined(FACEDET_SCALAR)
# include <arm_neon.h>
static void kernel_8x12(const float *ap,
@@ -113,7 +113,7 @@ static void kernel_8x12_scalar(const float *ap,
}
}
-# if defined(__x86_64__) && !defined(YUNET_SCALAR)
+# if defined(__x86_64__) && !defined(FACEDET_SCALAR)
# include <immintrin.h>
__attribute__((target("avx2,fma"))) static void kernel_8x12_avx2(const float *ap,
@@ -202,7 +202,7 @@ static void kernel_8x12(const float *ap,
# endif
#endif
-void yunet_gemm(const float *a_pack,
+void facedet_gemm(const float *a_pack,
int m,
int k,
const float *b,
diff --git a/gemm.h b/gemm.h
index b5dce70..dc6aeb4 100644
--- a/gemm.h
+++ b/gemm.h
@@ -1,12 +1,12 @@
-#ifndef YUNET_GEMM_H
-#define YUNET_GEMM_H
+#ifndef FACEDET_GEMM_H
+#define FACEDET_GEMM_H
#include <stddef.h>
-void yunet_gemm_pack_a(const float *a, int m, int k, float *pack);
-size_t yunet_gemm_pack_a_bytes(int m, int k);
+void facedet_gemm_pack_a(const float *a, int m, int k, float *pack);
+size_t facedet_gemm_pack_a_bytes(int m, int k);
-void yunet_gemm(const float *a_pack,
+void facedet_gemm(const float *a_pack,
int m,
int k,
const float *b,
diff --git a/image.h b/image.h
index 8963190..af35684 100644
--- a/image.h
+++ b/image.h
@@ -1,5 +1,5 @@
-#ifndef YUNET_IMAGE_H
-#define YUNET_IMAGE_H
+#ifndef FACEDET_IMAGE_H
+#define FACEDET_IMAGE_H
/* Decodes JPEG or PNG to interleaved RGB8, without alpha, orientation, or
* color-profile transforms. Each dimension is limited to 4096 pixels.
diff --git a/main.c b/main.c
index af311bd..bf56603 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-#include "yunet.h"
+#include "facedet.h"
#include "image.h"
#include "overlay.h"
@@ -168,14 +168,14 @@ int main(int argc, char **argv) {
return 1;
}
int iw = (width + 31) & ~31, ih = (height + 31) & ~31;
- yunet *m = yunet_create(iw, ih);
- int rc = m ? yunet_set_rgb(m, rgb, width, height, (size_t)width * 3) : -1;
+ facedet *m = facedet_create(iw, ih);
+ int rc = m ? facedet_set_rgb(m, rgb, width, height, (size_t)width * 3) : -1;
if (rc == 0)
- rc = yunet_run(m);
+ rc = facedet_run(m);
int cap = 21 * (iw / 32) * (ih / 32);
- yunet_detection *faces = rc == 0 ? malloc((size_t)cap * sizeof(*faces)) : NULL;
- int n = faces ? yunet_decode(m, score, nms, faces, cap) : -1;
- yunet_free(m);
+ facedet_detection *faces = rc == 0 ? malloc((size_t)cap * sizeof(*faces)) : NULL;
+ int n = faces ? facedet_decode(m, score, nms, faces, cap) : -1;
+ facedet_free(m);
if (n < 0) {
fprintf(stderr, "Inference failed; memory allocation or input validation failed.\n");
free(faces);
@@ -183,9 +183,9 @@ int main(int argc, char **argv) {
return 1;
}
if (refine) {
- yunet *refiner = yunet_create_refiner();
- rc = refiner ? yunet_refine(refiner, rgb, width, height, (size_t)width * 3, faces, n) : -1;
- yunet_free(refiner);
+ facedet *refiner = facedet_create_refiner();
+ rc = refiner ? facedet_refine(refiner, rgb, width, height, (size_t)width * 3, faces, n) : -1;
+ facedet_free(refiner);
if (rc) {
fputs("Landmark refinement failed; check embedded weights and available memory.\n", stderr);
free(faces);
@@ -203,7 +203,7 @@ int main(int argc, char **argv) {
printf("{\"width\":%d,\"height\":%d,\"input_width\":%d,\"input_height\":%d,\"faces\":[",
width, height, iw, ih);
for (int i = 0; i < n; i++) {
- const yunet_detection *d = &faces[i];
+ const facedet_detection *d = &faces[i];
printf("%s{\"box\":[%.7g,%.7g,%.7g,%.7g],\"score\":%.7g,\"landmarks\":[",
i ? "," : "", d->x, d->y, d->w, d->h, d->score);
for (int k = 0; k < 5; k++)
diff --git a/nn.c b/nn.c
index aa4638e..373c854 100644
--- a/nn.c
+++ b/nn.c
@@ -4,7 +4,7 @@
#include <math.h>
#include <string.h>
-void yunet_nn_conv2d(const float *x,
+void facedet_nn_conv2d(const float *x,
int cin,
int ih,
int iw,
@@ -53,7 +53,7 @@ void yunet_nn_conv2d(const float *x,
}
}
-void yunet_nn_im2col3(const float *x, int cin, int ih, int iw, int stride, float *col, int oh, int ow) {
+void facedet_nn_im2col3(const float *x, int cin, int ih, int iw, int stride, float *col, int oh, int ow) {
size_t n = (size_t)oh * ow;
for (int ic = 0; ic < cin; ic++) {
const float *xc = x + (size_t)ic * ih * iw;
@@ -93,9 +93,9 @@ void yunet_nn_im2col3(const float *x, int cin, int ih, int iw, int stride, float
}
}
-#if defined(__aarch64__) && !defined(YUNET_SCALAR)
+#if defined(__aarch64__) && !defined(FACEDET_SCALAR)
# include <arm_neon.h>
-void yunet_nn_dwconv3(
+void facedet_nn_dwconv3(
const float *x, int c, int ih, int iw, const float *w, const float *bias, int relu, float *y) {
for (int ch = 0; ch < c; ch++) {
const float *xc = x + (size_t)ch * ih * iw;
@@ -163,13 +163,13 @@ void yunet_nn_dwconv3(
}
}
#else
-void yunet_nn_dwconv3(
+void facedet_nn_dwconv3(
const float *x, int c, int ih, int iw, const float *w, const float *bias, int relu, float *y) {
- yunet_nn_conv2d(x, c, ih, iw, w, bias, c, 3, 1, 1, c, relu, y, ih, iw);
+ facedet_nn_conv2d(x, c, ih, iw, w, bias, c, 3, 1, 1, c, relu, y, ih, iw);
}
#endif
-void yunet_nn_maxpool2(const float *x, int c, int ih, int iw, float *y) {
+void facedet_nn_maxpool2(const float *x, int c, int ih, int iw, float *y) {
int oh = ih / 2, ow = iw / 2;
for (int ch = 0; ch < c; ch++) {
const float *xc = x + (size_t)ch * ih * iw;
@@ -184,7 +184,7 @@ void yunet_nn_maxpool2(const float *x, int c, int ih, int iw, float *y) {
}
}
-void yunet_nn_resize2x(const float *x, int c, int ih, int iw, float *y) {
+void facedet_nn_resize2x(const float *x, int c, int ih, int iw, float *y) {
int oh = ih * 2, ow = iw * 2;
for (int ch = 0; ch < c; ch++) {
const float *xc = x + (size_t)ch * ih * iw;
@@ -198,9 +198,9 @@ void yunet_nn_resize2x(const float *x, int c, int ih, int iw, float *y) {
}
}
-void yunet_nn_add(const float *a, const float *b, float *y, size_t n) {
+void facedet_nn_add(const float *a, const float *b, float *y, size_t n) {
for (size_t i = 0; i < n; i++)
y[i] = a[i] + b[i];
}
-float yunet_nn_sigmoid(float v) { return 1.0f / (1.0f + expf(-v)); }
+float facedet_nn_sigmoid(float v) { return 1.0f / (1.0f + expf(-v)); }
diff --git a/nn.h b/nn.h
index 65aea97..d555d41 100644
--- a/nn.h
+++ b/nn.h
@@ -1,9 +1,9 @@
-#ifndef YUNET_NN_H
-#define YUNET_NN_H
+#ifndef FACEDET_NN_H
+#define FACEDET_NN_H
#include <stddef.h>
-void yunet_nn_conv2d(const float *x,
+void facedet_nn_conv2d(const float *x,
int cin,
int ih,
int iw,
@@ -18,13 +18,13 @@ void yunet_nn_conv2d(const float *x,
float *y,
int oh,
int ow);
-void yunet_nn_im2col3(const float *x, int cin, int ih, int iw, int stride, float *col, int oh, int ow);
+void facedet_nn_im2col3(const float *x, int cin, int ih, int iw, int stride, float *col, int oh, int ow);
-void yunet_nn_dwconv3(
+void facedet_nn_dwconv3(
const float *x, int c, int ih, int iw, const float *w, const float *bias, int relu, float *y);
-void yunet_nn_maxpool2(const float *x, int c, int ih, int iw, float *y);
-void yunet_nn_resize2x(const float *x, int c, int ih, int iw, float *y);
-void yunet_nn_add(const float *a, const float *b, float *y, size_t n);
-float yunet_nn_sigmoid(float v);
+void facedet_nn_maxpool2(const float *x, int c, int ih, int iw, float *y);
+void facedet_nn_resize2x(const float *x, int c, int ih, int iw, float *y);
+void facedet_nn_add(const float *a, const float *b, float *y, size_t n);
+float facedet_nn_sigmoid(float v);
#endif
diff --git a/overlay.c b/overlay.c
index ab3fcf4..4d2013d 100644
--- a/overlay.c
+++ b/overlay.c
@@ -6,7 +6,7 @@
static const vix_rgb GREEN = {80, 220, 80};
-static void draw_face(const vix_canvas *canvas, const yunet_detection *face, int index) {
+static void draw_face(const vix_canvas *canvas, const facedet_detection *face, int index) {
double left = face->x, top = face->y;
double right = left + face->w, bottom = top + face->h;
if (!isfinite(left) || !isfinite(top) || !isfinite(right) || !isfinite(bottom) ||
@@ -37,7 +37,7 @@ static void draw_face(const vix_canvas *canvas, const yunet_detection *face, int
}
int overlay_write_ppm(const char *path, unsigned char *rgb, int width, int height,
- const yunet_detection *faces, int count) {
+ const facedet_detection *faces, int count) {
if (!path || !*path || !rgb || width < 1 || height < 1 || width > 4096 ||
height > 4096 || count < 0 || (count && !faces))
return -1;
diff --git a/overlay.h b/overlay.h
index 180507f..f2ff27e 100644
--- a/overlay.h
+++ b/overlay.h
@@ -1,12 +1,12 @@
-#ifndef YUNET_OVERLAY_H
-#define YUNET_OVERLAY_H
+#ifndef FACEDET_OVERLAY_H
+#define FACEDET_OVERLAY_H
-#include "yunet.h"
+#include "facedet.h"
/* Draws on RGB8 pixels in place and writes a P6 image at the original size.
* Detection coordinates are clipped for drawing without modifying the records.
* Returns 0 on success or -1 on invalid arguments or a file write failure. */
int overlay_write_ppm(const char *path, unsigned char *rgb, int width, int height,
- const yunet_detection *faces, int count);
+ const facedet_detection *faces, int count);
#endif