[英]How to put layers between an input layer and a “Model as layer”?
This works:这有效:
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)
This does not ("Graph disconnected"):这不会(“图表已断开”):
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)
The only difference between the two is the "preprocessing".两者之间的唯一区别是“预处理”。 Why doesn't this work, and how can I put intermediate layers between an input and a "model as layer" as shown above?
为什么这不起作用,以及如何在输入和“模型作为层”之间放置中间层,如上所示?
(Specifying an input_shape and/or input_tensor in the efnet declaration has no effect. In fact, specifying an input_tensor mysteriously causes the efnet weights to fail to load, because efnet apparently then has 131 layers (???) instead of the expected 130.) (在 efnet 声明中指定 input_shape 和/或 input_tensor 无效。事实上,指定 input_tensor 会神秘地导致 efnet 权重无法加载,因为 efnet 显然有 131 层(???)而不是预期的 130。 )
I found a fix for the problem, though I don't know why the fix makes any difference.我找到了解决该问题的方法,但我不知道为什么该修复会产生任何影响。
This works:这有效:
img = Input(shape=(224,224,3))
x = Dropout(0.2)(img)
x = efnet(x)
x = Dense(1)(x)
model = Model(inputs=img, outputs=x)
This doesn't:这不会:
img = Input(shape=(224,224,3))
img = Dropout(0.2)(img)
x = efnet(img)
x = Dense(1)(x)
model = Model(inputs=img, outputs=x)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.