[英]How Can I apply Dense layer after keras ResNet?
在 ResNet50 之后如何應用 Dense 層? 這是我的代碼
def build_model():
x = tf.keras.applications.ResNet50(input_shape=(IMG_WIDTH, IMG_HEIGHT, 3), weights=None,
include_top=False, pooling='avg')
model = tf.keras.layers.Dense(196)(x)
model.summary()
return model
但我收到了這個錯誤:
TypeError: Inputs to a layer should be tensors.
You can access the output of the model with the property output
of the model, if you are willing to recreate a model using the functional API. 在這種情況下,使用 Sequential API 可能會更容易:
new_model = tf.keras.Sequential(
[
tf.keras.applications.ResNet50(input_shape=(IMG_WIDTH, IMG_HEIGHT, 3), weights=None, include_top=False, pooling='avg'),
tf.keras.layers.Dense(196)
]
)
new_model.summary()
resnet = tf.keras.applications.ResNet50(input_shape=(IMG_WIDTH, IMG_HEIGHT, 3), weights=None, include_top=False, pooling='avg')
out = tf.keras.layers.Dense(196)(resnet.output)
new_model = tf.keras.models.Model(inputs=resnet.input, outputs=out)
new_model.summary()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.