TShopping

 找回密碼
 註冊
搜索
查看: 752|回復: 0
打印 上一主題 下一主題

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

[複製鏈接]
跳轉到指定樓層
1#
發表於 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)
複製代碼
錯誤代碼

  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'
複製代碼


代碼
  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}')
複製代碼


就正常了

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


 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-4-28 22:46 , Processed in 0.051496 second(s), 25 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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