代码拉取完成,页面将自动刷新
import streamlit as st
from streamlit_drawable_canvas import st_canvas
import tensorflow as tf
import cv2
import numpy as np
model_new = tf.keras.models.load_model('mnist.hdf5', compile=False)
st.title("MNIST Digit Recognizer with Simple Forward Neural Network")
SIZE = 192
canvas_result = st_canvas(
fill_color="#ffffff",
stroke_width=10,
stroke_color='#ffffff',
background_color="#000000",
height=150,
width=150,
drawing_mode='freedraw',
key="canvas",
)
if canvas_result.image_data is not None:
img_color = cv2.resize(canvas_result.image_data.astype('uint8'), (28, 28))
img_rescaling = cv2.resize(img_color, (SIZE, SIZE), interpolation=cv2.INTER_NEAREST)
st.write('Input Image')
st.image(img_rescaling)
if st.button('Predict'):
img_grey = cv2.cvtColor(img_color, cv2.COLOR_BGR2GRAY)
pred = model_new.predict(img_grey.reshape(1, 28, 28, 1))
st.write(f'result: {np.argmax(pred[0])}')
st.bar_chart(pred[0])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。