我加载了一个keras模型并使用其中间输出,如下所示:
pretrain_model = load_model(path)
model = Model(inputs=pretrain_model.input, outputs=pretrain_model.layers[-2].output)
当我跑步时:
>>model.output
<tf.Tensor 'pretrain_variable/dropout_2/cond/Merge:0' shape=(?, ?) dtype=float32>
>>model.output_shape
(None, 2000)
这会影响我的下一步:
input = tf.placeholder(tf.float32,shape=(None,X_all.shape[1],X_all.shape[2]),name='X')
pretrain_output = pretrain_model(input) # pretrain_output shape should be none*2000, however it is none*none
output_y = Dense(units=y.shape[1])(pretrain_output) # this works
output_y = tf.keras.layers.Dense(units=y.shape[1])(pretrain_output) # won't work, cause pretrain_output shape is (none,none)
由于Dimension不等于,我无法直接使用tf.keras.layers.Dense。 谁能教我如何获得正确形状的中间层输出?