簡體   English   中英

如何正確地將 h5 文件轉換為 pb

[英]How do I properly convert a h5 file to pb

So I trained a model using https://teachablemachine.withgoogle.com/ and it gave me a keras_model.h5 file and a labels.txt and I want to use it with OpenCV for some object detection but I've only used OpenCV with .pb文件。 所以我想我必須以某種方式轉換它。 所以我開始環顧四周,我發現了這個。 https://github.com/amir-abdi/keras_to_tensorflow當我嘗試在我的 conda 環境中運行腳本時,它會拋出這個異常。

WARNING:tensorflow:From keras_to_tensorflow.py:23: set_learning_phase (from tensorflow.python.keras.backend) is deprecated and will be removed after 2020-10-11.
Instructions for updating:
Simply pass a True/False value to the `training` argument of the `__call__` method of your layer or model.
2021-01-23 05:58:15.012748: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
I0123 05:58:16.157379  5660 keras_to_tensorflow.py:145] Converted output node names are: ['sequential_3/dense_Dense2/Softmax']
Traceback (most recent call last):
  File "keras_to_tensorflow.py", line 182, in <module>
    app.run(main)
  File "C:\Users\developer\miniconda3\envs\tf1\lib\site-packages\absl\app.py", line 303, in run
    _run_main(main, args)
  File "C:\Users\developer\miniconda3\envs\tf1\lib\site-packages\absl\app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "keras_to_tensorflow.py", line 148, in main
    sess = K.get_session()
AttributeError: module 'keras.backend' has no attribute 'get_session'

為什么會這樣以及如何正確轉換它?

首先加載 keras.h5 model 並保存加載的 model as.pb

import tensorflow as tf
from tensorflow import keras
model = keras.models.load_model(keras_model_path_location)
model.save(model, "save/path/to/location")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM