vincentb25 commited on
Commit
16477d5
·
1 Parent(s): d595dfc

Changed from plot output to img ?

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -139,7 +139,12 @@ def inference(query, labels, n_supp=10,
139
 
140
  probs = output.softmax(dim=-1).detach().cpu().numpy()
141
 
142
- return {k: float(v) for k, v in zip(labels, probs[0, 0])}, fig
 
 
 
 
 
143
 
144
 
145
  # DEBUG
 
139
 
140
  probs = output.softmax(dim=-1).detach().cpu().numpy()
141
 
142
+ # it used to be a matplotlib figure, turning it into a PIL image
143
+ fig.canvas.draw()
144
+ w, h = fig.canvas.get_width_height()
145
+ img = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8).reshape(h, w, 3)
146
+ return {k: float(v) for k, v in zip(labels, probs[0, 0])}, Image.fromarray(img)
147
+ #return {k: float(v) for k, v in zip(labels, probs[0, 0])}, fig
148
 
149
 
150
  # DEBUG