|
- import streamlit as st
- from skimage import io
- from skimage.transform import resize
- import numpy as np
- import tensorflow as tf
- model = tf.keras.models.load_model('./mnist_model.h5')
- uploaded_file = st.file_uploader("上傳圖片(.png)",type="png")
- if uploaded_file is not None:
- image1 = io.imread(uploaded_file, as_gray=True)
- image_resized = resize(image1,(28,28), anti_aliasing=True)
- X1 = image_resized.reshape(1,28,28,1)
- X1 = np.abs(1-X1)
- predictions = model.predict_classes(X1)[0]
- st.write(f'預測結果:{predictions}')
- st.image(image1)
複製代碼 錯誤代碼
python pycharm h5py
- ImportError: Filepath looks like a hdf5 file but h5pyis not available
複製代碼 上面敘述加入
在Termainal
輸入
- streamlit run D:\scrapytest\img-read.py
複製代碼
這時又出現錯誤
- 'Sequential' object has no attribute 'predict_classes'
複製代碼
python pycharm h5py
代碼
- predictions = model.predict_classes(X1)[0]
- st.write(f'預測結果:{predictions}')
- st.image(image1)
複製代碼
改成
- # 預測
- predictions = model.predict(X1)
- classes_x = np.argmax(predictions, axis=1)
- # 顯示預測結果
- st.write(f'預測結果:{classes_x}')
複製代碼
就正常了
python pycharm h5py
參考文章
https://www.cjavapy.com/article/2239/
|
|