title: cnn section: cnn
The cnn library connects to an external CXNNAIO vision-inference server
configured by an admin in System Settings > AI Integration > CNN
Inference (endpoint, optional bearer token, request timeout). Every
function reads its input image from a virtual file path (the calling user
must have read access); the returned object is the server's own response
envelope (object, model, created, image, timing_ms, data, ...),
so it matches the CXNNAIO API documentation field-for-field.
cnn.classify(file, options) → objectImage classification (default model mobilenet-v2).
requirelib("cnn");
var r = cnn.classify("user:/Photos/cat.jpg", { top_k: 3 });
sendJSONResp(r.data); // [{ label, index, score }, ...]
cnn.detect(file, options) → objectObject detection (default model yolo11n).
requirelib("cnn");
var r = cnn.detect("user:/Photos/street.jpg", { score_threshold: 0.3, render: true });
sendJSONResp(r.data); // [{ label, class_id, score, box:{x1,y1,x2,y2} }, ...]
// r.rendered_image is a data URI PNG when render:true was set
cnn.segment(file, options) → objectInstance segmentation (yolo11n-seg). Each item carries a per-instance,
box-cropped mask (mask.data is a base64 PNG).
cnn.pose(file, options) → objectPose estimation (yolo11n-pose), 17 COCO keypoints per detected person.
cnn.oriented(file, options) → objectOriented/rotated-box detection (yolo11n-obb), intended for aerial/top-down imagery.
cnn.faceDetect(file, options) → objectFace detection (default model ultraface-rfb-320).
cnn.faceLandmarks(file, options) → object98-point facial landmarks (pfld). Set options.cropped = true to treat the
whole input image as one face crop instead of detecting faces first.
cnn.faceEmbedding(file, options) → objectL2-normalized 128-d face embedding vector(s) (mbv2facenet).
cnn.faceAttributes(file, options) → objectGender attributes per face (gender-mbv2-0.35). Calls the server's
/v1/faces/gender route (the upstream API doc names this endpoint
/v1/faces/attributes, but the deployed server registers it as gender;
the response object field reads "face.gender").
cnn.faceCompare(fileA, fileB, options) → objectCompares two face photos/crops and returns their cosine similarity. Does not
support options.async (the server has no async variant for this endpoint).
requirelib("cnn");
var r = cnn.faceCompare("user:/a.jpg", "user:/b.jpg", { threshold: 0.5 });
sendResp(r.similarity + " - " + (r.same ? "same person" : "different"));
cnn.analyze(file, tasks, options) → objectRuns several tasks over one image in a single round trip. tasks is an
array ("classify", "detect", "segment", "pose", "oriented",
"faces", "landmarks", "attributes"); options carries an optional
top-level render/async plus per-task parameter blocks keyed by task name.
requirelib("cnn");
var r = cnn.analyze("user:/group.jpg", ["detect", "faces"], {
render: true,
detect: { score_threshold: 0.3 }
});
sendJSONResp(r.results.detect.data);
document_rendered = r.rendered_image; // data URI PNG
cnn.job(id) → objectPolls an async job (see Async below). Returns
{ id, object, status, created, result, error } where status is one of
"queued", "running", "succeeded" or "failed".
cnn.models() → objectLive model registry from the configured server: { object, data: [{ id, object, task, classes, input }, ...] }.
cnn.health() → objectLive server health: { status, version, models_loaded, sessions, uptime_s }.
Every single-image function (classify, detect, segment, pose,
oriented, faceDetect, faceLandmarks, faceEmbedding,
faceAttributes, analyze) accepts options.async = true. When set, the
function returns immediately with a job object instead of blocking:
requirelib("cnn");
var job = cnn.detect("user:/big.jpg", { async: true });
while (job.status === "queued" || job.status === "running") {
delay(500);
job = cnn.job(job.id);
}
sendJSONResp(job.status === "succeeded" ? job.result : job.error);
All single-image functions accept the same options fields, using the
server's own field names so they match the CXNNAIO API documentation
directly (all optional):
| Field | Type | Description |
|---|---|---|
model |
string | Override the server's default model for this task |
score_threshold |
number | Minimum confidence to keep (detect/seg/pose/oriented/faces) |
nms_threshold |
number | IoU suppression threshold (detect/seg/pose/oriented/faces) |
top_k |
number | Number of ranked results (classification) |
max_results |
number | Cap on returned items |
render |
bool | Also return an annotated PNG in rendered_image |
cropped |
bool | Treat the whole input image as one face crop (face endpoints) |
async |
bool | Submit as an async job instead of blocking (see Async jobs) |
cnn.faceCompare uses its own options shape instead: model, threshold,
a_cropped, b_cropped.