commit e82b4b5782cd987a2addcc9084c7ecb09854c039 Author: SOULOFCINDER <841135647@qq.com> Date: Fri Mar 31 14:04:49 2023 +0800 initial diff --git a/maskformer_swin_large_coco/app.py b/maskformer_swin_large_coco/app.py new file mode 100644 index 0000000..c0f9da4 --- /dev/null +++ b/maskformer_swin_large_coco/app.py @@ -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() + + + + diff --git a/maskformer_swin_large_coco/example_cat.jpg b/maskformer_swin_large_coco/example_cat.jpg new file mode 100644 index 0000000..e131e8e Binary files /dev/null and b/maskformer_swin_large_coco/example_cat.jpg differ diff --git a/maskformer_swin_large_coco/maskformer-swin-large-coco b/maskformer_swin_large_coco/maskformer-swin-large-coco new file mode 160000 index 0000000..5f009df --- /dev/null +++ b/maskformer_swin_large_coco/maskformer-swin-large-coco @@ -0,0 +1 @@ +Subproject commit 5f009df2186c5841582ecd419409b56041180144