【问题标题】:ValueError when loading a text classification model in Tensorflow在 Tensorflow 中加载文本分类模型时出现 ValueError
【发布时间】:2021-11-21 13:28:42
【问题描述】:

当我尝试使用 tf.keras.models.load_model() 加载模型时出现错误,并且出现以下错误

ValueError: The mask that was passed in was tf.RaggedTensor(values=Tensor("Placeholder_2:0", shape=(None,), dtype=bool), 
row_splits=Tensor("Placeholder_3:0", shape=(None,), dtype=int64))
and cannot be applied to RaggedTensor inputs. 
Please make sure that there is no mask passed in by upstream layers.

以下是我的模型架构

model = tf.keras.Sequential([
    encoder,
    tf.keras.layers.Embedding(input_dim=len(encoder.get_vocabulary()),output_dim=64,mask_zero=True),
    tf.keras.layers.LSTM(64, return_sequences = True),
    tf.keras.layers.GlobalMaxPool1D(),
    tf.keras.layers.Dense(7)
])

编码层:

encoder = tf.keras.layers.experimental.preprocessing.TextVectorization(
    max_tokens=VOCAB_SIZE)

模型保存为:model.save(PATH)

我正在从其他笔记本加载模型。我能得到一些帮助吗?

【问题讨论】:

    标签: python keras lstm tensorflow2.0 tf.keras


    【解决方案1】:

    好的,我通过从嵌入层中删除 mask_zero=True 属性解决了这个问题,但是,我不确定为什么它有效,以及为什么它不适用于 mask_zero=True。如果有人能告诉我原因会很有帮助。

    【讨论】:

      猜你喜欢
      • 2021-05-08
      • 2022-10-14
      • 1970-01-01
      • 2022-06-21
      • 2021-09-14
      • 2018-09-30
      • 1970-01-01
      • 2019-11-27
      • 1970-01-01
      相关资源
      最近更新 更多