-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.py
29 lines (21 loc) · 799 Bytes
/
input.py
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
import streamlit as st
from PIL import Image
import data
from ODmodel import make_prediction, plot_image_from_output
import numpy as np
import io
def figure_to_array(fig):
fig.canvas.draw()
return np.array(fig.canvas.renderer._renderer)
# select image -> into the model -> return output
def image_input(model, content):
output = make_prediction(model, content, 0.5)
fig, _ax = plot_image_from_output(content[0], output[0])
# fig.canvas.draw()
# byte = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
# byte = byte.reshape(fig.canvas.get_width_height()[::-1] + (3,))
# image_file = Image.fromarray(byte)
# img_io = io.BytesIO()
# image_file.save(img_io, 'PNG', quality = 70)
# img_io.seek(0)
st.image(figure_to_array(fig))