从模型获取张量时发生错误:变量batch_normalization_1_3 / moving_mean / biased已存在,不允许

时间:2018-08-09 16:21:03

标签: tensorflow keras

Keras,TF后端。我已经加载了预训练的模型,并且需要从一个中间行业中获取一个Tensor,以进一步使用Deep Explain软件包

model = load_model(path_to_model)
input_tensor = model.layers[0].input
fModel = Model(inputs=input_tensor, outputs=model.layers[-2].output)
target_tensor = fModel(input_tensor)

我在最后一行有错误

Variable batch_normalization_1_3/moving_mean/biased already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at:

此问题仅在jupyter笔记本电脑中或在使用GPU时出现。

1 个答案:

答案 0 :(得分:0)

在注释的基础上,发生错误是因为您在最后一行第二次调用fModel上的input_tensor。因此,它尝试从input_tensor开始构建模型。但是等等,您已经在上一行中做到了。

如果要在NumPy阵列上运行运行网络,可以致电fModel.predict。但是最后一行毫无用处。