Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chapter 9. Conversion of h5 model to pb. #175

Open
zoldaten opened this issue Apr 11, 2023 · 0 comments
Open

chapter 9. Conversion of h5 model to pb. #175

zoldaten opened this issue Apr 11, 2023 · 0 comments

Comments

@zoldaten
Copy link

signature = tf.saved_model.signature_def_utils.predict_signature_def(
    inputs={'image_bytes': model.input}, outputs={'scores': model.output})

builder = tf.saved_model.builder.SavedModelBuilder('model.pb')
builder.add_meta_graph_and_variables(
    sess=K.get_session(),
    tags=[tf.saved_model.tag_constants.SERVING],
    signature_def_map={
        tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
        signature
    })
builder.save()

gives error:

AttributeError                            Traceback (most recent call last)
Cell In[10], line 1
----> 1 signature = tf.saved_model.signature_def_utils.predict_signature_def(
      2     inputs={'image_bytes': model.input}, outputs={'scores': model.output})
      4 builder = tf.saved_model.builder.SavedModelBuilder('model.pb')
      5 builder.add_meta_graph_and_variables(
      6     sess=K.get_session(),
      7     tags=[tf.saved_model.tag_constants.SERVING],
   (...)
     10         signature
     11     })

AttributeError: module 'tensorflow._api.v2.saved_model' has no attribute 'signature_def_utils'

i tried to covert as follows:

pre_model = tf.keras.models.load_model("model.h5")
pre_model.save("saved_model.pb")

it works but i dont think it is correct as i see:

2023-04-11 12:53:29.259069: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'inputs' with dtype float and shape [?,64]
	 [[{{node inputs}}]]
2023-04-11 12:53:30.286215: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'inputs' with dtype float and shape [?,64]
	 [[{{node inputs}}]]
WARNING:absl:Found untraced functions such as _update_step_xla, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op while saving (showing 5 of 28). These functions will not be directly callable after loading.
manavrmoorthy pushed a commit to manavrmoorthy/Practical-Deep-Learning-Book that referenced this issue Sep 23, 2023
- formatted the code
- tested the flask scripts, they work fine locally
- CustomObjectScope - import resolved (Keras has updated documentation in v2)
- PracticalDL#175 - fixed, updated the code to export models to pb format - https://saturncloud.io/blog/how-to-export-keras-h5-to-tensorflow-pb-a-comprehensive-guide/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant