์ฝ˜ํ…์ธ ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

๋Œ€ํ™”ํ˜• ๋ฌผ์ฒด ๊ฐ์ง€: Gradio & Ultralytics YOLOv8 ๐Ÿš€

๋Œ€ํ™”ํ˜• ๊ฐ์ฒด ๊ฐ์ง€ ์†Œ๊ฐœ

์ด Gradio ์ธํ„ฐํŽ˜์ด์Šค๋Š” ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ์ฒด ๊ฐ์ง€๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฐ„ํŽธํ•œ ๋Œ€ํ™”ํ˜• ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. Ultralytics YOLOv8 ๋ชจ๋ธ. ์‚ฌ์šฉ์ž๋Š” ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ์‹ ๋ขฐ๋„ ์ž„๊ณ„๊ฐ’ ๋ฐ ๊ต์ฐจ์  ๊ฐ„ ๊ฒฐํ•ฉ(IoU) ์ž„๊ณ„๊ฐ’๊ณผ ๊ฐ™์€ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์กฐ์ •ํ•˜์—ฌ ์‹ค์‹œ๊ฐ„ ๊ฐ์ง€ ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ค๋ธŒ์ ํŠธ ๊ฐ์ง€์— Gradio๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?

  • ์‚ฌ์šฉ์ž ์นœํ™”์ ์ธ ์ธํ„ฐํŽ˜์ด์Šค: Gradio๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์ฝ”๋”ฉ ์—†์ด๋„ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ํƒ์ง€ ๊ฒฐ๊ณผ๋ฅผ ์‹œ๊ฐํ™”ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ„๋‹จํ•œ ํ”Œ๋žซํผ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
  • ์‹ค์‹œ๊ฐ„ ์กฐ์ •: ์‹ ๋ขฐ๋„ ๋ฐ IoU ์ž„๊ณ„๊ฐ’๊ณผ ๊ฐ™์€ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ฆ‰์‹œ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ์–ด ํƒ์ง€ ๊ฒฐ๊ณผ์— ๋Œ€ํ•œ ์ฆ‰๊ฐ์ ์ธ ํ”ผ๋“œ๋ฐฑ ๋ฐ ์ตœ์ ํ™”๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
  • ํญ๋„“์€ ์ ‘๊ทผ์„ฑ: Gradio ์›น ์ธํ„ฐํŽ˜์ด์Šค๋Š” ๋ˆ„๊ตฌ๋‚˜ ์•ก์„ธ์Šคํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ๋ฐ๋ชจ, ๊ต์œก ๋ชฉ์  ๋ฐ ๋น ๋ฅธ ์‹คํ—˜์„ ์œ„ํ•œ ํ›Œ๋ฅญํ•œ ๋„๊ตฌ์ž…๋‹ˆ๋‹ค.

๋ผ๋””์˜ค ์˜ˆ์ œ ์Šคํฌ๋ฆฐ์ƒท

๊ทธ๋ผ๋””์˜ค ์„ค์น˜ ๋ฐฉ๋ฒ•

pip install gradio

์ธํ„ฐํŽ˜์ด์Šค ์‚ฌ์šฉ ๋ฐฉ๋ฒ•

  1. ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ: '์ด๋ฏธ์ง€ ์—…๋กœ๋“œ'๋ฅผ ํด๋ฆญํ•˜์—ฌ ๊ฐ์ฒด ๊ฐ์ง€๋ฅผ ์œ„ํ•œ ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.
  2. ๋งค๊ฐœ๋ณ€์ˆ˜ ์กฐ์ •:
    • ์‹ ๋ขฐ๋„ ์ž„๊ณ„๊ฐ’: ๊ฐ์ฒด ๊ฐ์ง€๋ฅผ ์œ„ํ•œ ์ตœ์†Œ ์‹ ๋ขฐ ์ˆ˜์ค€์„ ์„ค์ •ํ•˜๋Š” ์Šฌ๋ผ์ด๋”์ž…๋‹ˆ๋‹ค.
    • IoU ์ž„๊ณ„๊ฐ’: ์—ฌ๋Ÿฌ ๊ฐœ์ฒด๋ฅผ ๊ตฌ๋ถ„ํ•˜๊ธฐ ์œ„ํ•œ IoU ์ž„๊ณ„๊ฐ’์„ ์„ค์ •ํ•˜๋Š” ์Šฌ๋ผ์ด๋”์ž…๋‹ˆ๋‹ค.
  3. ๊ฒฐ๊ณผ ๋ณด๊ธฐ๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค: ๊ฐ์ง€๋œ ๊ฐ์ฒด์™€ ํ•ด๋‹น ๋ ˆ์ด๋ธ”์ด ํฌํ•จ๋œ ์ฒ˜๋ฆฌ๋œ ์ด๋ฏธ์ง€๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

์‚ฌ์šฉ ์‚ฌ๋ก€ ์˜ˆ์‹œ

  • ์ƒ˜ํ”Œ ์ด๋ฏธ์ง€ 1: ๊ธฐ๋ณธ ์ž„๊ณ„๊ฐ’์„ ์‚ฌ์šฉํ•œ ๋ฒ„์Šค ๊ฐ์ง€.
  • ์ƒ˜ํ”Œ ์ด๋ฏธ์ง€ 2: ๊ธฐ๋ณธ ์ž„๊ณ„๊ฐ’์œผ๋กœ ์Šคํฌ์ธ  ์ด๋ฏธ์ง€์—์„œ ๊ฐ์ง€.

์‚ฌ์šฉ ์˜ˆ

์ด ์„น์…˜์—์„œ๋Š” Ultralytics YOLOv8 ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜์—ฌ Gradio ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” Python ์ฝ”๋“œ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๋ถ„๋ฅ˜ ์ž‘์—…, ๊ฐ์ง€ ์ž‘์—…, ์„ธ๋ถ„ํ™” ์ž‘์—… ๋ฐ ํ‚ค ํฌ์ธํŠธ ์ž‘์—…์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

import PIL.Image as Image
import gradio as gr

from ultralytics import ASSETS, YOLO

model = YOLO("yolov8n.pt")


def predict_image(img, conf_threshold, iou_threshold):
    results = model.predict(
        source=img,
        conf=conf_threshold,
        iou=iou_threshold,
        show_labels=True,
        show_conf=True,
        imgsz=640,
    )

    for r in results:
        im_array = r.plot()
        im = Image.fromarray(im_array[..., ::-1])

    return im


iface = gr.Interface(
    fn=predict_image,
    inputs=[
        gr.Image(type="pil", label="Upload Image"),
        gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
        gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold")
    ],
    outputs=gr.Image(type="pil", label="Result"),
    title="Ultralytics Gradio",
    description="Upload images for inference. The Ultralytics YOLOv8n model is used by default.",
    examples=[
        [ASSETS / "bus.jpg", 0.25, 0.45],
        [ASSETS / "zidane.jpg", 0.25, 0.45],
    ]
)

if __name__ == '__main__':
    iface.launch()

๋งค๊ฐœ๋ณ€์ˆ˜ ์„ค๋ช…

๋งค๊ฐœ๋ณ€์ˆ˜ ์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช…
img Image ๊ฐ์ฒด ๊ฐ์ง€๊ฐ€ ์ˆ˜ํ–‰๋  ์ด๋ฏธ์ง€์ž…๋‹ˆ๋‹ค.
conf_threshold float ๊ฐ์ฒด ๊ฐ์ง€๋ฅผ ์œ„ํ•œ ์‹ ๋ขฐ๋„ ์ž„๊ณ„๊ฐ’์ž…๋‹ˆ๋‹ค.
iou_threshold float ์˜ค๋ธŒ์ ํŠธ ๋ถ„๋ฆฌ๋ฅผ ์œ„ํ•œ ๊ต์ฐจ์  ์ดˆ๊ณผ ์œ ๋‹ˆ์˜จ ์ž„๊ณ„๊ฐ’์ž…๋‹ˆ๋‹ค.

๋ผ๋””์˜ค ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ ์š”์†Œ

๊ตฌ์„ฑ ์š”์†Œ ์„ค๋ช…
์ด๋ฏธ์ง€ ์ž…๋ ฅ ๊ฐ์ง€ํ•  ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.
์Šฌ๋ผ์ด๋” ์‹ ๋ขฐ๋„ ๋ฐ IoU ์ž„๊ณ„๊ฐ’์„ ์กฐ์ •ํ•ฉ๋‹ˆ๋‹ค.
์ด๋ฏธ์ง€ ์ถœ๋ ฅ ํƒ์ง€ ๊ฒฐ๊ณผ๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.


์ƒ์„ฑ 2024-02-01, ์—…๋ฐ์ดํŠธ 2024-02-07
์ž‘์„ฑ์ž: chr043416@gmail.com (1), glenn-jocher (1)

๋Œ“๊ธ€