简体   繁体   English

如何在输入层和“模型作为层”之间放置层?

[英]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.

相关问题 如何在 PyTorch model 中找到中间层的输入层名称? - How to find input layers names for intermediate layer in PyTorch model? 如何在功能性 Keras 模型中将前一层的权重作为输入传递给 custum 层的调用函数? - How to pass the weights of previous layers as input to a call function,of a custum layer, in a functional Keras Model? 如何在输入层和指定的第一个隐藏层之间具有固定对应关系的情况下实现神经网络模型? - How to implement a neural network model, with fixed correspondence between the input layer and the first hidden layer specified? 如何在Keras中将Lambda层作为输入层添加到现有模型中? - How to add a Lambda layer as an input layer to an existing model in Keras? 如何将 output 层连接到另一个神经网络的输入层? - How to connect output layers to the input layer of another neural network? 如何使用Lambda层更改模型的输入形状 - How to change input shape of the model with lambda layer tensorflow层中StringLookup层和嵌入层的区别 - Difference between StringLookup layer and embedding layer in tensorflow layers tf.feature_column.input_layer和tf.layers.Input有什么区别 - What's the difference between tf.feature_column.input_layer and tf.layers.Input TensorFlow - tf.keras.layers.Layer 与 tf.keras.Model 之间的区别 - TensorFlow - Difference between tf.keras.layers.Layer vs tf.keras.Model 输入 0 与层 model_2 不兼容 - Input 0 is incompatible with layer model_2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM