![](/img/trans.png)
[英]How to find input layers names for intermediate layer in PyTorch model?
[英]How to put layers between an input layer and a “Model as layer”?
这有效:
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。 )
我找到了解决该问题的方法,但我不知道为什么该修复会产生任何影响。
这有效:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.