【发布时间】:2020-08-25 04:09:13
【问题描述】:
有没有一种方法,我们可以加载网络架构,然后在 Keras 中从头开始训练它?
【问题讨论】:
标签: keras deep-learning computer-vision transfer-learning efficientnet
有没有一种方法,我们可以加载网络架构,然后在 Keras 中从头开始训练它?
【问题讨论】:
标签: keras deep-learning computer-vision transfer-learning efficientnet
是的,假设您想从头开始使用“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 Documention。 具体EfficientNet,也可以关注这个link
【讨论】: