gpt4 book ai didi

python - Keras,如何使用移除最后一层的模型进行预测

转载 作者:太空宇宙 更新时间:2023-11-04 05:11:41 24 4
gpt4 key购买 nike

假设我有 100k x 400 的数据集。我创建了这个模型:

model = Sequential()
model.add(Dense(200, input_dim = 400, init = init_weights))
model.add(BatchNormalization())
model.add(SReLU())
model.add(Dropout(0.5))
model.add(Dense(200, init = init_weights))
model.add(BatchNormalization())
model.add(SReLU())
model.add(Dropout(0.5))
model.add(Dense(1, activation = 'linear', init = init_weights))

比我打电话

model.compile(loss = ..

model.fit(input_matrix,..

训练后我可以调用 model.predict(.. 进行预测。

我想得到的是没有最后一个线性层的模型的预测矩阵..

所以是这样的:

model.remove_last_layer
pred_matrix = model.predict(input_matrix)

其中输出为 100k x 200 数组,我如何使用 keras 执行此操作?非常感谢

最佳答案

感谢我找到的文档链接

layer_name = 'dropout_2'
intermediate_layer_model = Model(input = model.input, output = model.get_layer(layer_name).output)
intermediate_output = intermediate_layer_model.predict(matrix_test)

关于python - Keras,如何使用移除最后一层的模型进行预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42844119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com