initial
This commit is contained in:
commit
e82b4b5782
maskformer_swin_large_coco
|
@ -0,0 +1,43 @@
|
|||
import gradio as gr
|
||||
from transformers import MaskFormerImageProcessor, MaskFormerForInstanceSegmentation
|
||||
from PIL import Image
|
||||
def inference(img):
|
||||
# load MaskFormer fine-tuned on COCO panoptic segmentation
|
||||
model_path = "maskformer-swin-large-coco"
|
||||
processor = MaskFormerImageProcessor.from_pretrained(model_path)
|
||||
model = MaskFormerForInstanceSegmentation.from_pretrained(model_path)
|
||||
|
||||
inputs = processor(images=img, return_tensors="pt")
|
||||
|
||||
outputs = model(**inputs)
|
||||
# model predicts class_queries_logits of shape `(batch_size, num_queries)`
|
||||
# and masks_queries_logits of shape `(batch_size, num_queries, height, width)`
|
||||
class_queries_logits = outputs.class_queries_logits
|
||||
masks_queries_logits = outputs.masks_queries_logits
|
||||
|
||||
# you can pass them to processor for postprocessing
|
||||
result = processor.post_process_panoptic_segmentation(outputs, target_sizes=[img.size[::-1]])[0]
|
||||
# we refer to the demo notebooks for visualization (see "Resources" section in the MaskFormer docs)
|
||||
predicted_panoptic_map = result["segmentation"]
|
||||
return predicted_panoptic_map
|
||||
|
||||
examples=[['example_cat.jpg']]
|
||||
|
||||
with gr.Blocks() as demo:
|
||||
gr.Markdown(
|
||||
"""
|
||||
# Panorama segmentation:maskformer-swin-large-coco
|
||||
Gradio Demo for maskformer-swin-large-coco. To use it, simply upload your image, or click one of the examples to load them.
|
||||
""")
|
||||
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)
|
||||
|
||||
demo.launch()
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
After ![]() (image error) Size: 169 KiB |
|
@ -0,0 +1 @@
|
|||
Subproject commit 5f009df2186c5841582ecd419409b56041180144
|
Loading…
Reference in New Issue