[英]TypeError: ('Keyword argument not understood:', 'input') for CNN with pretrained model from VGG16
大家好,我正在學習 CNN 模型,我正在運行這個筆記本鏈接https://www.kaggle.com/sureshhpba05/final-work
當我運行這組代碼來加載 VGG16 model
def VGG16_MODEL(img_rows=IMG_SIZE, img_cols=IMG_SIZE, color_type=3):
# Remove fully connected layer and replace
# with softmax for classifying 10 classes
model_vgg16_1 = VGG16(weights="imagenet", include_top=False)
# Freeze all layers of the pre-trained model
for layer in model_vgg16_1.layers:
layer.trainable = False
x = model_vgg16_1.output
x = GlobalAveragePooling2D()(x)
x = Dense(1024, activation='relu')(x)
predictions = Dense(CLASSES, activation = 'softmax')(x)
model = Model(input = model_vgg16_1.input, output = predictions)
return model
print("Model 1 network...")
model_vgg16_1 = VGG16_MODEL(img_rows=IMG_SIZE, img_cols=IMG_SIZE)
model_vgg16_1.summary()
model_vgg16_1.compile(loss='categorical_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
我收到了這個錯誤
TypeError: ('Keyword argument not understood:', 'input')
誰能告訴我為什么會出現這個錯誤以及我應該如何糾正這個錯誤?
為了社區的利益,在這里提供完整的工作代碼
import tensorflow as tf
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D
from tensorflow.keras import Model
from tensorflow.keras.applications import VGG16
IMG_SIZE = 224
CLASSES = 10
def VGG16_MODEL(img_rows=IMG_SIZE, img_cols=IMG_SIZE, color_type=3):
# Remove fully connected layer and replace
# with softmax for classifying 10 classes
model_vgg16_1 = VGG16(weights="imagenet", include_top=False)
# Freeze all layers of the pre-trained model
for layer in model_vgg16_1.layers:
layer.trainable = False
x = model_vgg16_1.output
x = GlobalAveragePooling2D()(x)
x = Dense(1024, activation='relu')(x)
predictions = Dense(CLASSES, activation = 'softmax')(x)
model = Model(inputs = model_vgg16_1.input, outputs = predictions)
return model
print("Model 1 network...")
model_vgg16_1 = VGG16_MODEL(img_rows=IMG_SIZE, img_cols=IMG_SIZE)
model_vgg16_1.summary()
model_vgg16_1.compile(loss='categorical_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
Output:
Model 1 network...
Model: "model"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_4 (InputLayer) [(None, None, None, 3)] 0
_________________________________________________________________
block1_conv1 (Conv2D) (None, None, None, 64) 1792
_________________________________________________________________
block1_conv2 (Conv2D) (None, None, None, 64) 36928
_________________________________________________________________
block1_pool (MaxPooling2D) (None, None, None, 64) 0
_________________________________________________________________
block2_conv1 (Conv2D) (None, None, None, 128) 73856
_________________________________________________________________
block2_conv2 (Conv2D) (None, None, None, 128) 147584
_________________________________________________________________
block2_pool (MaxPooling2D) (None, None, None, 128) 0
_________________________________________________________________
block3_conv1 (Conv2D) (None, None, None, 256) 295168
_________________________________________________________________
block3_conv2 (Conv2D) (None, None, None, 256) 590080
_________________________________________________________________
block3_conv3 (Conv2D) (None, None, None, 256) 590080
_________________________________________________________________
block3_pool (MaxPooling2D) (None, None, None, 256) 0
_________________________________________________________________
block4_conv1 (Conv2D) (None, None, None, 512) 1180160
_________________________________________________________________
block4_conv2 (Conv2D) (None, None, None, 512) 2359808
_________________________________________________________________
block4_conv3 (Conv2D) (None, None, None, 512) 2359808
_________________________________________________________________
block4_pool (MaxPooling2D) (None, None, None, 512) 0
_________________________________________________________________
block5_conv1 (Conv2D) (None, None, None, 512) 2359808
_________________________________________________________________
block5_conv2 (Conv2D) (None, None, None, 512) 2359808
_________________________________________________________________
block5_conv3 (Conv2D) (None, None, None, 512) 2359808
_________________________________________________________________
block5_pool (MaxPooling2D) (None, None, None, 512) 0
_________________________________________________________________
global_average_pooling2d_3 ( (None, 512) 0
_________________________________________________________________
dense_5 (Dense) (None, 1024) 525312
_________________________________________________________________
dense_6 (Dense) (None, 10) 10250
=================================================================
Total params: 15,250,250
Trainable params: 15,250,250
Non-trainable params: 0
_________________________________________________________________
(轉述自 Frightera)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.