Python Keras,如何使用移除最后一层的模型进行预测
假设我有数据集100k x 400。我创建了这个模型:Python Keras,如何使用移除最后一层的模型进行预测,python,matrix,tensorflow,keras,layer,Python,Matrix,Tensorflow,Keras,Layer,假设我有数据集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(BatchNormaliz
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.predict(…进行预测
我想得到的是从没有最后一个线性层的模型中得到的预测矩阵
比如:
model.remove_last_layer
pred_matrix = model.predict(input_matrix)
如果输出为100k x 200阵列,我如何使用keras实现这一点?thx很多thx到我找到的文档链接
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)
您的模型经过培训了吗?是的,我接受了培训您的
后端是什么
,您可以打印model.summary()
?检查文档,这可能会帮助您:对于链接TF2,model()
的参数是输入
和输出
,如果有帮助的话。
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)