为什么keras中间层输出张量形状是(?,?)

时间:2018-06-25 09:46:32

标签: python model keras

我加载了一个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。 谁能教我如何获得正确形状的中间层输出?

0 个答案:

没有答案