addons
                                
                                 addons copied to clipboard
                                
                                    addons copied to clipboard
                            
                            
                            
                        used MultiOptimizer as optimizer ,after model.fit (),can't saved tensorflow-Addons=0.12.1 with Python=3.8 and Tensorflow=2.3.1
System information
- Ubuntu 18.04
- TensorFlow version : tensorflow-gpu 2.3.1 installed by binary
- TensorFlow-Addons :tensorflow-addons 0.12.1 installed by binary
- Python version:3.8
- Is GPU used? : no
Describe the bug i'm using MultiOptimizer as my model optimizer,but after model.fit() training my own data, then i run model.save() to save the model to local , raise TypeError: ('Not JSON Serializable:'...
Code to reproduce the issue below is the code i copy from the discriminative_layer_training.py,and i just add one line to save the model,also raise the same error.
import tensorflow as tf from tensorflow_addons.optimizers import MultiOptimizer import numpy as np
def get_model(): inputs = tf.keras.Input(shape=(4,)) outputs = tf.keras.layers.Dense(1)(inputs) return tf.keras.Model(inputs, outputs)
model1 = get_model() model2 = get_model() model3 = get_model()
inputs = tf.keras.Input(shape=(4,)) y1 = model1(inputs) y2 = model2(inputs) y3 = model3(inputs) outputs = tf.keras.layers.Average()([y1, y2, y3]) model = tf.keras.Model(inputs, outputs)
optimizers_and_layers = [ (tf.keras.optimizers.SGD(), model1), (tf.keras.optimizers.SGD(learning_rate=0.0), model2), (tf.keras.optimizers.SGD(), model3), ]
model1_weights_before_train = [weight.numpy() for weight in model1.weights] model2_weights_before_train = [weight.numpy() for weight in model2.weights] model3_weights_before_train = [weight.numpy() for weight in model3.weights]
multi_optimizer = MultiOptimizer(optimizers_and_layers)
model.compile(multi_optimizer, loss="mse")
x = np.ones((128, 4)).astype(np.float32) y = np.ones((128, 32)).astype(np.float32) model.fit(x, y) model.save("tf_model")
Provide a reproducible test case that is the bare minimum necessary to generate the problem.
Other info / logs raise TypeError('Not JSON Serializable:', obj) TypeError: ('Not JSON Serializable:', <tf.Tensor 'gradient_tape/functional_7/functional_1/dense/MatMul:0' shape=(4, 1) dtype=float32>)
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.