我正在尝试使用nyoka软件包将经过训练的Tensorflow 2.0模型输出到PMML。当我这样做时,它会出错。该问题似乎与this answer中的问题不同, 即使错误是相同的,因为我的模型没有复杂的创建函数,并且实际上进行了适当的训练和适当的变换。
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.
答案 0 :(得分:0)
这是Tensorflow的错误。如果可以为每个图层打印input_shape和output_shape或权重,则也可以使用Nyoka导出它。