相关疑难解决方法(0)

TensorFlow 2.0:保存并加载包含 LSTM 层的模型,但加载失败并显示 ValueError

当我尝试保存和加载包含 LSTM 层的模型时,加载公共失败并显示ValueError: could not find matching function to call loaded from the SavedModel

class RegNet(Model):
    def __init__(self,
             intermediate_dim=50,
             state_dim=9,
             name='RegNet',
             **kwargs):
        super(RegNet, self).__init__()
        self.d1 = Dense(intermediate_dim, activation='relu')
        self.d2 = Dense(state_dim, activation='relu')
        self.h = LSTM(state_dim, activation='sigmoid', return_sequences=True)
        self.o = Dense(state_dim, activation='softmax')

    def call(self, x):
        x = self.d1(x)
        x = self.d2(x)
        x = self.h(x)
        y = self.o(x)
        return y

regNet = RegNet()
...
# Export the model to a SavedModel
regNet.save(regNet_ckpt_dir, save_format='tf')
# Recreate the exact same model
tf.keras.models.load_model(regNet_ckpt_dir) …
Run Code Online (Sandbox Code Playgroud)

tensorflow2.0

3
推荐指数
1
解决办法
4773
查看次数

标签 统计

tensorflow2.0 ×1