【问题标题】:How to put layers between an input layer and a "Model as layer"?如何在输入层和“模型作为层”之间放置层?
【发布时间】:2020-04-21 22:14:43
【问题描述】:

这行得通:

img = Input(shape=(224,224,3))

efnet = EfficientNetB0(

    weights = 'noisy-student',
    include_top = False,
    pooling = None,
    classes = None

)
for layer in efnet.layers:
    layer.trainable = False

x = efnet(img)
# ... any number of layers ...
x = Dense(1)(x)

model = Model(inputs=img, outputs=x)

这没有(“图表断开”):

img = Input(shape=(224,224,3))
img = Dropout(0.2)(img)
# ^ "Preprocessing" could be anything, Dropout is a simple example

efnet = EfficientNetB0(

    weights = 'noisy-student',
    include_top = False,
    pooling = None,
    classes = None

)
for layer in efnet.layers:
    layer.trainable = False

x = efnet(img)
# ... any number of layers ... 
x = Dense(1)(x)

model = Model(inputs=img, outputs=x)

两者之间的唯一区别是“预处理”。为什么这不起作用,以及如何在输入和“模型即层”之间放置中间层,如上所示?

(在 efnet 声明中指定 input_shape 和/或 input_tensor 无效。事实上,指定 input_tensor 会神秘地导致 efnet 权重无法加载,因为 efnet 显然有 131 层 (???) 而不是预计 130。)

【问题讨论】:

  • 你从哪里得到EfficientNetB0
  • 第二个代码对我来说看起来不错。您确定问题不在其他地方,例如efnetDense 之间的层?
  • @today 我敢肯定。 efnet 和 Dense 之间没有层。 (可能有,但没有。)
  • @thushv89 "$ pip installefficientnet" 和 "从efficientnet.keras import EfficientNetB0"
  • 你在使用tf.keras吗?如果是这样,请改用import efficientnet.tfkeras

标签: python tensorflow keras graph model


【解决方案1】:

我找到了解决该问题的方法,但我不知道为什么该修复会产生任何影响。

这行得通:

img = Input(shape=(224,224,3))
x = Dropout(0.2)(img)
x = efnet(x) 
x = Dense(1)(x)
model = Model(inputs=img, outputs=x)

这不是:

img = Input(shape=(224,224,3))
img = Dropout(0.2)(img)
x = efnet(img) 
x = Dense(1)(x)
model = Model(inputs=img, outputs=x)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 2021-06-18
    • 1970-01-01
    • 1970-01-01
    • 2019-03-21
    • 1970-01-01
    • 2021-11-03
    相关资源
    最近更新 更多