콘텐츠로 이동
ENKR

qgon.serve

화면에서 보기Deploy › Playground (모델 시험)

qgon.serve: 사용자 추론 코드(predict.py) 도우미와 출력 모양 (스키마 판 1, 2차 모양 추가).

Playground '내 추론 코드'로 띄운 서빙이 요청마다 predict() 를 부르고, 반환값을 아래 모양으로 검증·정규화해 화면이 이미지 위에 그린다.

from qgon import serve
def load(model_dir): # 한 번. model_dir = /model (읽기 전용)
return torch.load(serve.model_file(model_dir), map_location="cpu", weights_only=True)
def predict(model, inp): # 요청마다. inp.image(PIL, EXIF 방향 적용) · inp.image_bytes · inp.table · inp.params
return serve.labels(["cat", "dog"], [0.9, 0.1])
def describe(model): # (선택) 화면 폼·범례
return serve.describe(input="image", labels=["cat", "dog"])

출력 (좌표 = 입력 이미지 픽셀, EXIF 방향 적용 뒤 · bbox = COCO [x, y, w, h])

serve.labels(labels, scores, top_k=5) 분류 {"type":"labels","labels":[{"label","score"}]}
serve.boxes([{bbox, label, score, rotation?}], xyxy=False) 검출 {"type":"boxes","boxes":[…]}
serve.masks([{mask | polygon | rle, label, score}]) 분할 {"type":"masks","masks":[{label, score, bbox, area, rle|polygon}]}
serve.values({"quality": 5.6}) 값(표 회귀) {"type":"values","values":[{"name","value"}]} / 여러 행이면 names·rows
serve.keypoints([{keypoints, label, score}], names="coco17") 키포인트 (2차) {"type":"keypoints","names","skeleton","instances":[…]}
serve.image(그림, format="png") 결과 이미지 (2차) {"type":"image","image":{mime, width, height, bytes, data(base64)}}
serve.text("…") 텍스트 (2차) {"type":"text","text":"…"}
serve.combine(serve.boxes(…), serve.image(…)) 여러 결과 묶기 (2차) {"type":"multi","parts":[…]}

이 파일은 표준 라이브러리만 쓴다(numpy·Pillow 는 있으면 빠른 길). 장비의 서빙 러너가 이 파일의 사본을 들고 있어 옛 SDK 환경에도 끼워 넣는다. qgon 의 다른 모듈을 import 하지 않는다.

import qgon.serve

predict() 반환 모양이 틀렸다. 메시지에 어디가 틀렸는지 (한국어).

OutputError()

화면에서 보기 · Deploy › Playground (모델 시험)

Input

클래스

predict(model, inp) 의 inp.

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

화면에서 보기 · Deploy › Playground (모델 시험)

labels

함수

분류: labels(["cat","dog"], [0.9, 0.1]) 또는 labels([("cat", 0.9), ("dog", 0.1)]). 점수 내림차순 top_k 개.

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

화면에서 보기 · Deploy › Playground (모델 시험)

boxes

함수

검출: boxes([{"bbox": [x, y, w, h], "label": "car", "score": 0.8, "rotation": 0}]). xyxy=True 면 [x1, y1, x2, y2] 로 받아 바꾼다.

boxes(items, xyxy=False)

화면에서 보기 · Deploy › Playground (모델 시험)

masks

함수

분할: masks([{"mask": H×W 참거짓 배열 | "polygon": [[x1,y1,…]] | "rle": {size, counts}, "label", "score"}]).

masks(items)

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

화면에서 보기 · Deploy › Playground (모델 시험)

values

함수

값(표 회귀 등): values({"quality": 5.62}) 한 행, values({"quality": [5.6, 6.1]}) 여러 행, values([{"quality": 5.6}, …]) 행 목록.

values(v)

화면에서 보기 · Deploy › Playground (모델 시험)

keypoints

함수

키포인트 (2차): keypoints([{"keypoints": [[x, y, v], …] 또는 [x1, y1, v1, …], "label": "person", "score": 0.9, "bbox"?: [x, y, w, h], "kp_scores"?: [점마다 0~1]}], names="coco17").

keypoints(items, names=None, skeleton=None)

점 하나 = 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) 넣는다.

화면에서 보기 · Deploy › Playground (모델 시험)

image

함수

결과 이미지 (2차): 사용자 코드가 그린 그림을 돌려준다(화면이 입력 이미지 옆에 보여 준다).

image(img, format='png', quality=90)

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

화면에서 보기 · Deploy › Playground (모델 시험)

text

함수

텍스트 (2차): 글자 결과 (OCR·설명 등). 화면은 글자 그대로 보여 준다(HTML·마크다운으로 그리지 않음). 최대 10만 자.

text(s)

화면에서 보기 · Deploy › Playground (모델 시험)

combine

함수

여러 결과 묶기 (2차): combine(serve.boxes(…), serve.masks(…), serve.image(…)). 최대 8개(결과 이미지는 2개까지), 묶음 안에 묶음은 안 됨.

combine(*parts)

화면에서 보기 · Deploy › Playground (모델 시험)

describe

함수

입력 종류·클래스 목록: 화면 폼·범례용. input = image | table.

describe(
input='image',
labels=None,
features=None,
outputs=None,
**extra,
)

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

화면에서 보기 · Deploy › Playground (모델 시험)

모델 폴더에서 모델 파일 경로: .qgon-model.json 의 file → 없으면 숨김 아닌 파일이 하나뿐이면 그것 → *.pt 하나.

model_file(model_dir='/model')

화면에서 보기 · Deploy › Playground (모델 시험)

H×W 참거짓 배열(numpy·torch·중첩 목록) → {"size": [H, W], "counts": "<COCO 압축 RLE>"} (열 우선).

rle_encode(mask)

화면에서 보기 · Deploy › Playground (모델 시험)