来自tf.keras中已加载模型的Mote-Carlo辍学

问题描述

我正在使用tf.keras(不是Keras本身,而是keras的tensorflow实现)。 我想像在Monte-Carlo Dropout Tutorial中那样在预测过程中使用dropout,但是要使用已加载的神经网络,即已经训练好了,例如,假设一个在imagenet上预先训练的tf.keras模型,如下所示示例(仅修改了我的二进制分类任务的最后一层):

import tensorflow as tf
from tensorflow import keras

model  = tf.keras.applications.DenseNet121(input_shape=(266,266,3),weights="imagenet",include_top=False,pooling="max")

final_layer = keras.layers.Dense( 1,activation=keras.activations.sigmoid )( model.output )

final_model = keras.Model( inputs=[model.input],outputs=[final_layer] )

然后,使用final_model和相同的图像,我总是得到相同的精确预测(这是正常的)。如何将所有辍学层设置为“训练模式”,从而在每次进行预测时都有不同的预测?

我尝试了类似的操作(来自this github issue),但由于它会引发错误,因此无法正常工作。

import tensorflow.keras.backend as K

f = K.function( [final_model.layers[0].input,K.learning_phase()],[final_model.layers[-1].output] )

然后在这种情况下如何执行蒙特卡洛辍学?非常感谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...