我在从
TransformerDecoder
保存 keras_nlp
模型时遇到问题。您能告诉我如何解决这个问题吗?
这是我的代码:
from keras_nlp.layers import TransformerDecoder
from tensorflow.keras import Model
from tensorflow.keras.layers import Dense, Embedding, GlobalAveragePooling1D, Input
decoder_input = Input(shape=(128,), name="decoder_input")
embedding = Embedding(input_dim=10000, output_dim=32, name="embedding")(decoder_input)
decoder = TransformerDecoder(intermediate_dim=64, num_heads=2, name="decoder")(embedding)
pooled = GlobalAveragePooling1D(name="pooling")(decoder)
output = Dense(token_size, activation="softmax", name="output_dense")(pooled)
model = Model(inputs=decoder_input, outputs=output)
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])
model.save("model.keras")
我收到错误:
TypeError: Layer tf.__operators__.add was passed non-JSON-serializable arguments.
Arguments had types: {'y': <class 'keras.src.backend.tensorflow.core.Variable'>, 'name': <class 'NoneType'>}.
They cannot be serialized out when saving the model.
软件包版本:
print(tensorflow.__version__)
print(keras_nlp.__version__)
# 2.17.0
# 0.14.1