Spaces:
Runtime error
Runtime error
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()
|