Harshad Bhandwaldar commited on
Commit
f046541
1 Parent(s): d498fcd
Files changed (1) hide show
  1. app.py +5 -13
app.py CHANGED
@@ -9,27 +9,19 @@ from gluoncv.data.transforms.presets.segmentation import test_transform
9
  # using cpu
10
  ctx = mx.cpu(0)
11
 
12
-
13
- FILE_NAME = "result.png"
14
-
15
  model = gluoncv.model_zoo.get_model("psp_resnet101_ade", pretrained=True)
16
 
17
- def segmentation(img):
18
- img = Image.open(img)
19
- # img.load()
20
- # img = np.asarray(img, dtype="int32")
21
  img = mx.ndarray.array(img)
22
- ctx = mx.cpu(0)
23
  img = test_transform(img, ctx)
24
  output = model.predict(img)
25
  predict = mx.nd.squeeze(mx.nd.argmax(output, 1)).asnumpy()
26
  mask = get_color_pallete(predict, "ade20k")
27
- # mask.save("result.png")
28
- # mmask = mpimg.imread("result.png")
29
- # plt.imshow(mmask)
30
- # plt.savefig("result.png")
31
  return mask
32
 
 
33
  image_in = gr.Image()
34
  image_out = gr.components.Image()
35
 
@@ -38,4 +30,4 @@ Iface = gr.Interface(
38
  inputs=image_in,
39
  outputs=image_out,
40
  title="Sementic Segmentation - MXNet",
41
- ).launch()
 
9
  # using cpu
10
  ctx = mx.cpu(0)
11
 
 
 
 
12
  model = gluoncv.model_zoo.get_model("psp_resnet101_ade", pretrained=True)
13
 
14
+
15
+ def segmentation(image):
16
+ img = Image.fromarray(image)
 
17
  img = mx.ndarray.array(img)
 
18
  img = test_transform(img, ctx)
19
  output = model.predict(img)
20
  predict = mx.nd.squeeze(mx.nd.argmax(output, 1)).asnumpy()
21
  mask = get_color_pallete(predict, "ade20k")
 
 
 
 
22
  return mask
23
 
24
+
25
  image_in = gr.Image()
26
  image_out = gr.components.Image()
27
 
 
30
  inputs=image_in,
31
  outputs=image_out,
32
  title="Sementic Segmentation - MXNet",
33
+ ).launch()