找回密碼
 註冊
搜索
查看: 1188|回復: 0

[教學] 上傳圖片(0~9)辨識ImportError: Filepath looks like a hdf5 file but h5py ...

[複製鏈接]
發表於 2023-7-19 23:08:22 | 顯示全部樓層 |閱讀模式
 
Push to Facebook
  1. import streamlit as st
  2. from skimage import io
  3. from skimage.transform import resize

  4. import numpy as np

  5. import tensorflow as tf

  6. model = tf.keras.models.load_model('./mnist_model.h5')
  7. uploaded_file = st.file_uploader("上傳圖片(.png)",type="png")

  8. if uploaded_file is not None:
  9.     image1 = io.imread(uploaded_file, as_gray=True)
  10.     image_resized = resize(image1,(28,28), anti_aliasing=True)
  11.     X1 = image_resized.reshape(1,28,28,1)
  12.     X1 = np.abs(1-X1)

  13.     predictions = model.predict_classes(X1)[0]
  14.     st.write(f'預測結果:{predictions}')
  15.     st.image(image1)
複製代碼
錯誤代碼

python pycharm h5py

python pycharm h5py


  1. ImportError: Filepath looks like a hdf5 file but h5pyis not available
複製代碼
上面敘述加入

  1. import h5py
複製代碼
在Termainal
輸入
  1. streamlit run D:\scrapytest\img-read.py
複製代碼


這時又出現錯誤
  1. 'Sequential' object has no attribute 'predict_classes'
複製代碼

python pycharm h5py

python pycharm h5py


代碼
  1. predictions = model.predict_classes(X1)[0]
  2.     st.write(f'預測結果:{predictions}')
  3.     st.image(image1)
複製代碼



改成
  1. # 預測
  2.     predictions = model.predict(X1)
  3.     classes_x = np.argmax(predictions, axis=1)
  4.     # 顯示預測結果
  5.     st.write(f'預測結果:{classes_x}')
複製代碼


就正常了

python pycharm h5py

python pycharm h5py


參考文章
https://www.cjavapy.com/article/2239/

 
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|小黑屋|TShopping

GMT+8, 2025-4-30 16:42 , Processed in 0.025396 second(s), 24 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回復 返回頂部 返回列表