0

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 files. So I'm thinking that I would have to convert it somehow. So I started looking around and I found this. https://github.com/amir-abdi/keras_to_tensorflow and when I try to run the script in my conda environment it throws this exception.

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' 

Why is that and how do I properly convert it?

1 Answer 1

1

First load the keras .h5 model and save loaded 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") 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.