【问题标题】:Keras 1.3: Error in model weights sharing with batch normalizationKeras 1.3:与批量归一化共享模型权重的错误
【发布时间】:2018-03-21 08:39:03
【问题描述】:

我想通过一个模型传递两个输入,然后需要连接两者并通过第二个模型,其中 model1 的权重应为两个输入共享,如下代码所示:

x = Conv2D(64, (3, 3))(input0)
#x = BatchNormalization()(x)
x = MaxPooling2D((2, 2))(x)
out = Flatten()(x)

model1 = Model(input0, out) 
model1 = Model(input0, out)
out_a = model1(input1)
out_b = model1(input2)

concatenated = keras.layers.concatenate([out_a, out_b])
out = Dense(1, activation='sigmoid')(concatenated)
model2 = Model([input1, input2], out)

这在没有上面给出的批量标准化的情况下工作。但是,如果我取消注释 BatchNormalization,代码会出现以下错误:

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

我不知道如何解决此错误。

完整模型图如下:

人们在使用 tensorflow 1.3 的多个 GPU 时收到此错误消息,但是,我的错误消息相同但错误原因不同。

【问题讨论】:

  • 你定义相同的模型两次,只是不要。
  • 这可以在没有批量规范化的情况下工作,但如果我进行批量规范化,则会出错。

标签: tensorflow keras keras-layer


【解决方案1】:

通过将tensorflow 1.3升级到1.4解决了这个问题。

【讨论】:

    猜你喜欢
    • 2019-01-13
    • 2021-06-04
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    • 2019-10-22
    • 2020-01-15
    • 1970-01-01
    • 2021-05-24
    相关资源
    最近更新 更多