nyoka AttributeError: The layer has never been called and thus has no defined input shape

nyoka AttributeError: The layer has never been called and thus has no defined input shape

我正在尝试使用 nyoka 包将经过训练的 Tensorflow 2.0 模型输出到 PMML。当我这样做时,它会出错。问题好像和里的不一样, 即使错误是一样的,因为我的模型没有复杂的创建功能,而且实际上确实进行了适当的训练和适当的转换。

def create_and_train(x_training,y_training,n_cols_in,modelparams):
    layers = [tf.keras.layers.Dense(n_cols_in,activation="relu"),
    tf.keras.layers.Dropout(.5)]
    for param in modelparams:
        layers.extend([tf.keras.layers.Dense(param,activation="sigmoid"),tf.keras.layers.Dropout(.5)])
    layers.append(tf.keras.layers.Dense(1,activation="sigmoid"))
    model = tf.keras.models.Sequential(layers)
    model.compile(optimizer='adam', loss='binary_crossentropy', metrics=[tf.keras.metrics.AUC()])

    model.fit(x_training, y_training, epochs = epochs)
    with open("NN"+"_".join([str(m) for m in modelparams])+".pmml","w") as pmml_file:
        pmml = KerasToPmml(model)
        pmml.export(pmml_file)

我得到的不是 PMML 文件,而是

AttributeError: The layer has never been called and thus has no defined input shape.

这是Tensorflow的错误。如果您可以打印 input_shape 和 output_shape 或每一层的权重,那么您也可以使用 Nyoka 将其导出。