|
|
|
try: |
|
import detectron2 |
|
except: |
|
import os |
|
os.system('pip install git+https://github.com/facebookresearch/detectron2.git') |
|
|
|
import glob |
|
import gradio as gr |
|
from os.path import basename |
|
from predictor import Predictor |
|
|
|
|
|
predictor = Predictor() |
|
|
|
def predict(model: str, img_path: str, score_min: int): |
|
if not model: |
|
raise ValueError('モデルが指定されていません') |
|
if not img_path: |
|
return ValueError('画像が指定されていません') |
|
return predictor.predict(model, img_path, score_min) |
|
|
|
models = [basename(path) for path in glob.glob("models/*")] |
|
images = glob.glob("test/*.jpg") |
|
|
|
demo = gr.Interface( |
|
predict, |
|
inputs=[ |
|
gr.Dropdown(models, label="モデル", value=models[0]), |
|
gr.Image(images[0], type='filepath', label="画像", interactive=True), |
|
gr.Slider(0, 100, 80, label="確信度下限(%)", info='指定した確信度以上のオブジェクトのみ検出します。'), |
|
], |
|
outputs=[ |
|
gr.Image(label='結果'), |
|
gr.Text(label='パイプの数'), |
|
], |
|
title="パイプ検出デモ", |
|
examples=[[models[0], path, 80] for path in images], |
|
allow_flagging='never', |
|
) |
|
|
|
demo.launch() |
|
|