semantic_segmentation/clipseg_rd64_refined/app.py

34 lines
1.0 KiB
Python
Raw Normal View History

2023-03-31 05:26:18 +00:00
import gradio as gr
from transformers import AutoProcessor, CLIPSegForImageSegmentation
2023-03-31 07:40:51 +00:00
2023-03-31 05:26:18 +00:00
def inference(img):
model_path = "clipseg-rd64-refined"
processor = AutoProcessor.from_pretrained(model_path)
model = CLIPSegForImageSegmentation.from_pretrained(model_path)
texts = ["a cat", "a remote", "a blanket"]
inputs = processor(text=texts, images=[img] * len(texts), padding=True, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
print(logits.shape)
return logits.shape
examples=[['example_cat.jpg']]
with gr.Blocks() as demo:
gr.Markdown(
"""
# Semantic segmentation:clipseg-rd64-refined
2023-04-06 09:36:57 +00:00
这是clipseg-rd64-refined的Gradio Demo用于语义分割
2023-03-31 05:26:18 +00:00
""")
with gr.Row():
image_input = gr.Image(type="pil")
text_output = gr.Textbox()
image_button = gr.Button("上传")
image_button.click(inference, inputs=image_input, outputs=text_output)
gr.Examples(examples,inputs=image_input)
2023-04-06 09:36:57 +00:00
demo.launch(server_name="0.0.0.0")