【发布时间】:2020-10-02 04:23:21
【问题描述】:
我正在尝试在我的模型中使用 dropout 层在推理时间来衡量模型的不确定性 如the method outlined by Yurin Gal中所述
这篇文章描述了一个解决方案:
How to calculate prediction uncertainty using Keras?,定义了一个新的 Keras 函数
self.f = K.function([self.graph.layers[0].input, K.learning_phase()], [self.graph.layers[-1].output])
但是,如果使用的模型具有批量标准化层,则此方法不适用。因为这将使模型不使用在训练期间学习的均值和方差,而是根据当前批次设置新的。
因此,我正在寻找一种方法将批处理层训练参数设置为 false,但将 dropout 层保持在训练模式?
我使用 KerasefficientNet B0 作为模型,使用自定义数据训练 keras_efficientNet
我已经尝试自己更改图层设置
`
for layer in self.graph.layers[4].layers:
if 'batch_norm' in layer.name:
layer._trainable = False
layer._inbound_nodes[0].output_tensors[0]._uses_learning_phase = False
layer._inbound_nodes[0].input_tensors[0]._uses_learning_phase = False
if 'dropout' in layer.name:
layer._inbound_nodes[0].output_tensors[0]._uses_learning_phase = True
for weight in self.graph.layers[4].weights:
if 'batch_norm' in weight.name:
weight._trainable = False`
然而,这些都不起作用。
【问题讨论】:
标签: keras deep-learning uncertainty