Categorize an image
1from lynx import LYNX2 3model = LYNX("lynx-basic")4results = model.classify("frame.jpg")5 6# Top-1: "is this a cat or a dog?"7class_id, confidence = results.probs.top1()8print(results.names[class_id], f"{confidence:.2%}")9 10# Top-K: ranked list when one answer isn't enough11indices, scores = results.probs.top_k(5)12for i, s in zip(indices, scores):13 print(results.names[i], f"{s:.2%}")Reach for classify() when you don't care where a thing is in the frame — you just want a category. Scene classification ("indoor vs outdoor"), content moderation, cascading pipelines that classify first and only run an expensive detector on relevant classes, anything where a single label per frame is the right answer.
Every LYNX model exposes a classification head, even ones trained primarily for detection — classify() always works, returning the model's best class-probability estimate. Detection-trained models will give you a less calibrated distribution than a model trained specifically for classification, but you'll still get a usable answer rather than an exception.
top_k(1) is the safest call when you want a single confident answer with the option to fall back ("if top1 score < 0.6, mark uncertain"). The position in probs.data IS the class ID, so results.names[i] is always the right way to resolve the human-readable name.