Skip to content
qgonDEV DOCSSDK 0.3.31
ENKR

qgon.serve

In the appDeploy › Playground

Helpers and output shapes for your own inference code (predict.py), output schema version 1.

from qgon import serve
def load(model_dir): # once. model_dir = /model (read-only)
return torch.load(serve.model_file(model_dir), map_location="cpu", weights_only=True)
def predict(model, inp): # per request. inp.image (PIL, EXIF orientation applied) · inp.image_bytes · inp.table · inp.params
return serve.labels(["cat", "dog"], [0.9, 0.1])
def describe(model): # (optional) web app form and legend
return serve.describe(input="image", labels=["cat", "dog"])

Output shapes. Coordinates are input-image pixels after EXIF orientation, and bbox is COCO [x, y, w, h].

serve.labels(labels, scores, top_k=5) classification {"type":"labels","labels":[{"label","score"}]}
serve.boxes([{bbox, label, score, rotation?}], xyxy=False) detection {"type":"boxes","boxes":[…]}
serve.masks([{mask | polygon | rle, label, score}]) segmentation {"type":"masks","masks":[{label, score, bbox, area, rle|polygon}]}
serve.values({"quality": 5.6}) values (tabular regression) {"type":"values","values":[{"name","value"}]} / names and rows for several rows
serve.keypoints([{keypoints, label, score}], names="coco17") keypoints {"type":"keypoints","names","skeleton","instances":[…]}
serve.image(picture, format="png") result image {"type":"image","image":{mime, width, height, bytes, data(base64)}}
serve.text("…") text {"type":"text","text":"…"}
serve.combine(serve.boxes(…), serve.image(…)) several results {"type":"multi","parts":[…]}

This module uses only the standard library (NumPy and Pillow, when present, give faster paths) and imports no other qgon module. The device's serving runner keeps an identical copy, so the same helpers also work in environments with an older SDK.

import qgon.serve

OutputError

exception

Raised when the value predict() returns has the wrong shape; the message (in Korean) says where.

OutputError()

In the app · Deploy › Playground

Input

class

The inp argument of predict(model, inp), carrying image, image_bytes, table, params, width and height.

Input(
image=None,
image_bytes=None,
table=None,
params=None,
width=None,
height=None,
)
Full description (Korean original)
image
PIL.Image (RGB, EXIF 방향 적용), 이미지 입력이 아니거나 환경에 Pillow 가 없으면 None
image_bytes
올라온 원본 바이트 (이미지 입력일 때)
table
표 입력, dict(열 이름: 값) · 값 목록 · dict 목록 (표 입력일 때)
params
요청의 params (dict, 없으면 {})
width·height
이미지 크기 (EXIF 적용 뒤, 모르면 None)

In the app · Deploy › Playground

labels

function

Classification output from labels(["cat","dog"], [0.9, 0.1]) or labels([("cat", 0.9), ("dog", 0.1)]), keeping the top_k entries by descending score.

labels(names, scores=None, top_k=5)

In the app · Deploy › Playground

boxes

function

Detection output from boxes([{"bbox": [x, y, w, h], "label": "car", "score": 0.8, "rotation": 0}]); with xyxy=True, boxes given as [x1, y1, x2, y2] are converted.

boxes(items, xyxy=False)

In the app · Deploy › Playground

masks

function

Segmentation output from masks([{"mask": H×W boolean array | "polygon": [[x1,y1,…]] | "rle": {size, counts}, "label", "score"}]); arrays become COCO compressed RLE (column-major, the same characters as pycocotools) and bbox and area are filled in.

masks(items)
Full description (Korean original)

배열은 COCO 압축 RLE(열 우선, pycocotools 와 같은 글자)로 바꾸고 bbox·area 를 채운다.

In the app · Deploy › Playground

values

function

Value output (tabular regression and the like): values({"quality": 5.62}) for one row, values({"quality": [5.6, 6.1]}) or values([{"quality": 5.6}, …]) for several rows.

values(v)

In the app · Deploy › Playground

keypoints

function

Keypoint output from keypoints([{"keypoints": [[x, y, v], …] or [x1, y1, v1, …], "label": "person", "score": 0.9, "bbox"?: [x, y, w, h], "kp_scores"?: [one 0 to 1 score per point]}], names="coco17").

keypoints(items, names=None, skeleton=None)
Full description (Korean original)

점 하나 = COCO 와 같이 (x, y, v): v = 0 표시 안 함 · 1 가려짐 · 2 보임. [x, y] 두 값이면 v = 2.
names = 점 이름 목록 또는 이름 있는 뼈대("coco17", 사람 17점, 뼈대 포함). skeleton = [[i, j], …] (COCO 처럼 1부터 센 점 번호).
torchvision keypointrcnn 이면 keypoints=out["keypoints"][i](K×3), kp_scores 는 0~1 로 바꿔서(예: sigmoid) 넣는다.

In the app · Deploy › Playground

image

function

A result image your code drew, shown next to the input image; img is a PIL.Image, an H×W or H×W×3/4 uint8 array (NumPy or torch, channels last) or PNG/JPEG bytes, and format is png or jpeg, up to 4096 px on the long side, 4096×4096 pixels in total and 4 MB (larger images must be shrunk or saved as JPEG).

image(img, format='png', quality=90)
Full description (Korean original)

img = PIL.Image · H×W 또는 H×W×3/4 uint8 배열(numpy·torch, 채널이 마지막) · PNG/JPEG 바이트. format = png | jpeg.
상한: 긴 변 4096 · 1677만 화소 · 4MB (넘으면 줄이거나 JPEG 로).

In the app · Deploy › Playground

text

function

Text output (OCR, captions and the like), shown as plain text without HTML or Markdown rendering, up to 100,000 characters.

text(s)

In the app · Deploy › Playground

combine

function

Bundles several outputs, as in combine(serve.boxes(…), serve.masks(…), serve.image(…)); up to 8 parts, at most 2 of them result images, and no bundle inside a bundle.

combine(*parts)

In the app · Deploy › Playground

describe

function

Declares the input kind (image or table) and the class list for the web app's form and legend; features describes table input fields and outputs names the outputs.

describe(
input='image',
labels=None,
features=None,
outputs=None,
**extra,
)
Full description (Korean original)

features = [{"name": "alcohol", "type": "float"}] (표 입력 폼), outputs = ["quality"].

In the app · Deploy › Playground

model_file

function

Returns the model file path in a model folder: the file named in .qgon-model.json, else the only non-hidden file, else the single *.pt file.

model_file(model_dir='/model')

In the app · Deploy › Playground

rle_encode

function

Encodes an H×W boolean array (NumPy, torch or nested lists) as {"size": [H, W], "counts": "<COCO compressed RLE>"}, column-major.

rle_encode(mask)

In the app · Deploy › Playground