1 Star 2 Fork 0

lundechen/machine_learning_web_app

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
app.py 978 Bytes
一键复制 编辑 原始数据 按行查看 历史
lundechen 提交于 2024-11-25 15:05 . j
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])
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lundechen/machine_learning_web_app.git
git@gitee.com:lundechen/machine_learning_web_app.git
lundechen
machine_learning_web_app
machine_learning_web_app
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385