如何冻结具有BatchNorm层的Keras图

2024-06-07 12:22:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图加载带有Batchnorm层的冻结Keras图,但得到错误:

Message: TensorFlow.TFException : Input 0 of node
DenseNet/DenseBlock/ConvBlock/dense_0_0_bn/cond/ReadVariableOp/Switch was
passed float from DenseNet/DenseBlock/ConvBlock/dense_0_0_bn/gamma:0
incompatible with expected resource.

通常解决这个问题的方法是:keras.backend.set_learning_phase(0),但是当在另一个API(例如TensorflowSharp/TfLite)中加载图形时,这不是一个选项(据我所知)。在

以下是我当前保存图形的方式:

^{pr2}$

有什么方法可以在保存之前以编程方式删除Batchnorm层,以便在Keras之外的环境中加载模型?在


Tags: 方法图形messageinputtensorflow错误方式keras

热门问题