Spaces:
Runtime error
Runtime error
File size: 926 Bytes
4c9c630 |
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 |
import gluoncv
import matplotlib.image as mpimg
import mxnet as mx
from gluoncv.data.transforms.presets.segmentation import test_transform
from gluoncv.utils.viz import get_color_pallete
from matplotlib import pyplot as plt
from mxnet import image
import gradio as gr
import numpy as np
# using cpu
ctx = mx.cpu(0)
FILE_NAME = "result.png"
model = gluoncv.model_zoo.get_model("psp_resnet101_ade", pretrained=True)
def segmentation(img):
output = model.predict(img)
predict = mx.nd.squeeze(mx.nd.argmax(output, 1)).asnumpy()
mask = get_color_pallete(predict, "ade20k")
# mask.save("result.png")
# mmask = mpimg.imread("result.png")
# plt.imshow(mmask)
# plt.savefig("result.png")
return mask
image_in = gr.Image()
image_out = gr.components.Image()
Iface = gr.Interface(
fn=segmentation,
inputs=image_in,
outputs=image_out,
title="Sementic Segmentation - MXNet",
).launch() |