1

有没有一种方法,我们可以加载网络架构,然后在 Keras 中从头开始训练它?

4

1 回答 1

1

的,假设您想从头开始使用“ResNet50v2”为 2 个类和 255x255x3 输入训练一个分类器,您所要做的就是导入没有最后一个 softmax 层的架构,添加您的自定义层并使用“无”初始化权重。

from keras.applications.resnet_v2 import ResNet50V2 
from keras.models import Model
from keras.layers import Dense, GlobalAveragePooling2D

input_shape = (255,255,3)
n_class = 2
base_model = ResNet50V2(weights=None,input_shape=input_shape,include_top=False)

# Add Custom layers
x = base_model.output
x = GlobalAveragePooling2D()(x)
# ADD a fully-connected layer
x = Dense(1024, activation='relu')(x)
# Softmax Layer
predictions = Dense(n_class, activation='softmax')(x)
model = Model(inputs=base_model.input, outputs=predictions)

# Compile Model
model.compile(optimizer='adam', loss='categorical_crossentropy',metrics=['accuracy'])

# Train
model.fit(X_train,y_train,epochs=20,batch_size=50,validation_data=(X_val,y_val))

同样,要使用 EfficienNet 等其他架构,请参考Keras 文档。对于具体的 EfficientNet,您也可以点击此链接

于 2020-05-11T04:34:09.370 回答