DOsinga / deep_learning_cookbook

Deep Learning Cookbox
Apache License 2.0
689 stars 338 forks source link

16.2 Prepare Keras model for Tensorflow Serving - TensorFlow 2.0 Compatibility Issue #81

Open mikechen66 opened 4 years ago

mikechen66 commented 4 years ago

1. TypeError:

Issue:

TypeError: compile() missing 1 required positional argument: 'optimizer'

Solution:

In [2]: change the following line of code

new_model.compile()

to the line of code as follows.

new_model.compile(optimizer='rmsprop',loss='mse')

2. AttributeError

Issue

AttributeError: module 'tensorflow' has no attribute 'Session'

Solution:

change the line of code

In[2]

sess = tf.Session()

to the following code

sess = tf.compat.v1.Session()

3. RuntimeError

Issue:

RuntimeError: set_session is not available when using TensorFlow 2.0.

Solution:

delete the following code:

In [2]

K.set_session(sess)

3. AttributeError:

AttributeError: module 'tensorflow_core._api.v2.saved_model' has no attribute 'utils'

In [6]

input_info = tf.saved_model.utils.build_tensor_info(new_model.inputs[0])

The error is hard to be corrected. It has many dependencies. Now I have no solution to the AttributeError.

AttributeError: module 'tensorflow_core._api.v2.saved_model' has no attribute 'utils'

In[7]

classification_inputs = tf.saved_model.utils.build_tensor_info(serialized_tf_example)
classification_outputs_classes = tf.saved_model.utils.build_tensor_info(prediction_classes)
classification_outputs_scores = tf.saved_model.utils.build_tensor_info(values)