Intelligent Projects Using Python
上QQ阅读APP看书,第一时间看更新

The ResNet50 transfer learning network

The ResNet50 model for transfer learning can be defined similarly to the VGG16 and InceptionV3 networks, as follows:

def resnet_pseudo(dim=224,freeze_layers=10,full_freeze='N'):
# model_save_dest = {}
model = ResNet50(weights='imagenet',include_top=False)
x = model.output
x = GlobalAveragePooling2D()(x)
x = Dense(512, activation='relu')(x)
x = Dropout(0.5)(x)
x = Dense(512, activation='relu')(x)
x = Dropout(0.5)(x)
out = Dense(5,activation='softmax')(x)
model_final = Model(input = model.input,outputs=out)
if full_freeze != 'N':
for layer in model.layers[0:freeze_layers]:
layer.trainable = False
return model_final