def train_top_model():
# Load the bottleneck features and labels
train_features = np.load(open(output_dir+'bottleneck_features_train.npy', 'rb'))
train_labels = np.load(open(output_dir+'bottleneck_labels_train.npy', 'rb'))
validation_features = np.load(open(output_dir+'bottleneck_features_validation.npy', 'rb'))
validation_labels = np.load(open(output_dir+'bottleneck_labels_validation.npy', 'rb'))
# Create the top model for the inception V3 network, a single Dense layer
# with softmax activation.
top_input = Input(shape=train_features.shape[1:])
top_output = Dense(5, activation='softmax')(top_input)
model = Model(top_input, top_output)
# Train the model using the bottleneck features and save the weights.
model.compile(optimizer=SGD(lr=1e-4, momentum=0.9),
loss='categorical_crossentropy',
metrics=['accuracy'])
csv_logger = CSVLogger(output_dir + 'top_model_training.csv')
model.fit(train_features, train_labels,
epochs=top_epochs,
batch_size=batch_size,
validation_data=(validation_features, validation_labels),
callbacks=[csv_logger])
model.save_weights(top_model_weights_path)
inception_flowers_tune.py 文件源码
python
阅读 20
收藏 0
点赞 0
评论 0
评论列表
文章目录