我正在尝试使用 Keras 及其预构建的 ImageNet CNN 架构来解决一个简单的二元分类问题。
对于 VGG16,我采用了以下方法,
vgg16_model = keras.application.vgg16.VGG16()
'''Rebuild the vgg16 using an empty sequential model'''
model = Sequential()
for layer in vgg16_model.layers:
model.add(layer)
'''Since the problem is binary, I got rid of the output layer and added a more appropriate output layer.'''
model.pop()
'''Freeze other pre-trained weights'''
for layer in model.layers:
layer.trainable = False
'''Add the modified final layer'''
model.add(Dense(2, activation = 'softmax'))
Run Code Online (Sandbox Code Playgroud)
与我定制的 CNN 相比,这非常有效,而且准确度更高。但是训练需要一段时间,我想使用 Xception 和 InceptionV3 采取类似的方法,因为它们是更轻的模型,具有更高的准确性。
xception_model = keras.applicaitons.xception.Xception()
model = Sequential() …
Run Code Online (Sandbox Code Playgroud)