【发布时间】:2017-04-30 20:31:55
【问题描述】:
我正在尝试为具有不同类的数据集微调 VGG16 模型。在this example之后,我尝试这样做:
from keras.applications.vgg16 import VGG16
from keras.models import Model
from keras.layers import Dense, GlobalAveragePooling2D
from keras import backend as K
pretrained = VGG16(include_top=False, weights='imagenet')
model = pretrained.output
# Add new layers here
model = Model(inputs=pretrained.input, outputs=model)
但是,我在向模型添加新层时遇到了问题。在model = pretrained.output 行之后,我尝试了以下每一行(一次一行):
model = Flatten()(pretrained)
model = MaxPooling2D((2,2), strides=(2,2))(pretrained)
model = Dense(1024, activation='relu')(model)
model = Convolution2D(32, 3, 3)(model)
model = GlobalAveragePooling2D()(x)
对于我尝试的前两行,我得到了错误
AttributeError: 'Model' object has no attribute 'get_shape'
当我尝试最后三行中的每一行时,每次都会遇到与图层大小有关的错误,例如model = Convolution2D(32, 3, 3)(model) 这条线给了我:
Error when checking target: expected conv2d_1 to have 4 dimensions, but got array with shape (38, 100)
如何解决这些错误?更一般地说,我如何知道可以将哪些类型的层附加到卷积模型?
【问题讨论】:
标签: tensorflow keras convolution