File size: 1,295 Bytes
6e740d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# -*- coding: utf-8 -*-
"""Untitled200.ipynb

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1XlVHPlSeue0mvagDZOzdk_wHjLmNlWM1
"""

#!pip install ultralytics
#!pip install requests
#!pip install pillow

from ultralytics import YOLO

# ๋ชจ๋ธ ๋กœ๋“œ
model = YOLO("ship.pt")  # ํ•™์Šต๋œ ๋ชจ๋ธ ํŒŒ์ผ์„ ๋กœ๋“œ

# ์ด๋ฏธ์ง€ ์ถ”๋ก 
results = model("images.jpeg")  # ์ด๋ฏธ์ง€ ํŒŒ์ผ๋กœ ์ถ”๋ก  ์ˆ˜ํ–‰

# ๊ฒฐ๊ณผ ์‹œ๊ฐํ™”
results[0].show()  # ์ฒซ ๋ฒˆ์งธ ๊ฒฐ๊ณผ๋ฅผ ์‹œ๊ฐ์ ์œผ๋กœ ํ‘œ์‹œ

#!pip install gradio

import gradio as gr
from ultralytics import YOLO

# 1. ๋ชจ๋ธ ์ดˆ๊ธฐํ™”
model = YOLO("ship.pt")

# 2. ์ถ”๋ก  ํ•จ์ˆ˜
def detect_ship(input_image: str):
    results = model(input_image)
    return results[0].plot()[:, :, ::-1]  # BGR to RGB ๋ณ€ํ™˜

# 3. Gradio UI
with gr.Blocks() as demo:
    with gr.Row():
        gr.Markdown("## Ship Detection")

    with gr.Row():
        input_image = gr.Image(label="Input Image", type="filepath")
        output_image = gr.Image(label="Output", type="numpy")

    with gr.Row():
        inference_btn = gr.Button("Inference")

    inference_btn.click(fn=detect_ship, inputs=input_image, outputs=output_image)

# 4. Gradio ์‹คํ–‰
demo.launch(inline=False)

# 5. Gradio ์ข…๋ฃŒ
demo.close()