wnsdud030415 commited on
Commit
1a98d13
·
1 Parent(s): db12170

version3_44_4

Browse files
Files changed (1) hide show
  1. app.py +6 -0
app.py CHANGED
@@ -14,6 +14,7 @@ model = TFSegformerForSemanticSegmentation.from_pretrained(
14
  "mattmdjaga/segformer_b2_clothes"
15
  )
16
 
 
17
  def ade_palette():
18
  """ADE20K palette that maps each class to RGB values."""
19
  return [
@@ -37,6 +38,7 @@ def ade_palette():
37
  [255, 99, 71]
38
  ]
39
 
 
40
  labels_list = []
41
 
42
  with open(r'../segmentation2/labels.txt', 'r') as fp:
@@ -45,6 +47,7 @@ with open(r'../segmentation2/labels.txt', 'r') as fp:
45
 
46
  colormap = np.asarray(ade_palette())
47
 
 
48
  def label_to_color_image(label):
49
  if label.ndim != 2:
50
  raise ValueError("Expect 2-D input label")
@@ -53,6 +56,7 @@ def label_to_color_image(label):
53
  raise ValueError("label value too large.")
54
  return colormap[label]
55
 
 
56
  def draw_plot(pred_img, seg):
57
  fig = plt.figure(figsize=(20, 15))
58
 
@@ -74,6 +78,7 @@ def draw_plot(pred_img, seg):
74
  ax.tick_params(width=0.0, labelsize=25)
75
  return fig
76
 
 
77
  def sepia(input_img):
78
  input_img = Image.fromarray(input_img)
79
 
@@ -100,6 +105,7 @@ def sepia(input_img):
100
  fig = draw_plot(pred_img, seg)
101
  return fig
102
 
 
103
  demo = gr.Interface(fn=sepia,
104
  inputs=gr.Image(shape=(400, 600)),
105
  outputs=['plot'],
 
14
  "mattmdjaga/segformer_b2_clothes"
15
  )
16
 
17
+
18
  def ade_palette():
19
  """ADE20K palette that maps each class to RGB values."""
20
  return [
 
38
  [255, 99, 71]
39
  ]
40
 
41
+
42
  labels_list = []
43
 
44
  with open(r'../segmentation2/labels.txt', 'r') as fp:
 
47
 
48
  colormap = np.asarray(ade_palette())
49
 
50
+
51
  def label_to_color_image(label):
52
  if label.ndim != 2:
53
  raise ValueError("Expect 2-D input label")
 
56
  raise ValueError("label value too large.")
57
  return colormap[label]
58
 
59
+
60
  def draw_plot(pred_img, seg):
61
  fig = plt.figure(figsize=(20, 15))
62
 
 
78
  ax.tick_params(width=0.0, labelsize=25)
79
  return fig
80
 
81
+
82
  def sepia(input_img):
83
  input_img = Image.fromarray(input_img)
84
 
 
105
  fig = draw_plot(pred_img, seg)
106
  return fig
107
 
108
+
109
  demo = gr.Interface(fn=sepia,
110
  inputs=gr.Image(shape=(400, 600)),
111
  outputs=['plot'],