Google AI平台模型上的TF模型错误:“预期序列化为标量或向量,形状为:[1,12]”

时间:2020-05-29 03:53:17

标签: google-cloud-platform tensorflow2.0 google-cloud-ml tfx

作为tfx训练器和推送器输出的一部分,已保存的模型/预训练模型已通过以下库在Google AI Platform Jobs and Models中执行。

from tfx.extensions.google_cloud_ai_platform.pusher import executor as ai_platform_pusher_executor
from tfx.extensions.google_cloud_ai_platform.trainer import executor as ai_platform_trainer_executor

但是,当我在Google AI平台模型中测试服务式模型时,收到以下错误消息,请您帮我了解它的含义吗?如何转换我的输入数据以供模型接受?

错误:

{
  "error": "Prediction failed: Error during model execution: <_MultiThreadedRendezvous of RPC that terminated with:\n\tstatus = StatusCode.INVALID_ARGUMENT\n\tdetails = \"Expected serialized to be a scalar or vector, got shape: [1,12]\n\t [[{{node ParseExample/ParseExampleV2}}]]\"\n\tdebug_error_string = \"{\"created\":\"@1590723484.491366234\",\"description\":\"Error received from peer ipv4:127.0.0.1:8081\",\"file\":\"src/core/lib/surface/call.cc\",\"file_line\":1056,\"grpc_message\":\"Expected serialized to be a scalar or vector, got shape: [1,12]\\n\\t [[{{node ParseExample/ParseExampleV2}}]]\",\"grpc_status\":3}\"\n>"
}

Google AI平台模型中的示例输入:

{
  "instances": [
["A", "B", "C", "D","E", "F", "G", "H", "I", "J", "K", "L"]
  ]
}

以下是培训人员的代码。

def get_model(show_summary=True):

#one-hot categorical features
num_A = 4
num_B = 3
num_C = 2
num_D = 8
num_E = 12
num_F = 4
num_G = 16
num_H = 26
num_I = 11
num_J = 2
num_K = 11
num_L = 2

input_A = tf.keras.Input(shape=(num_A,), name="A_xf")
input_B = tf.keras.Input(shape=(num_B,), name="B_xf")
input_C = tf.keras.Input(shape=(num_C,), name="C_xf")
input_D = tf.keras.Input(shape=(num_D,), name="D_xf")
input_E = tf.keras.Input(shape=(num_E,), name="E_xf")
input_F = tf.keras.Input(shape=(num_F,), name="F_xf")
input_G = tf.keras.Input(shape=(num_G,), name="G_xf")
input_H = tf.keras.Input(shape=(num_H,), name="H_xf")
input_I = tf.keras.Input(shape=(num_I,), name="I_xf")
input_J = tf.keras.Input(shape=(num_J,), name="J_xf")
input_K = tf.keras.Input(shape=(num_K,), name="K_xf")
input_L = tf.keras.Input(shape=(num_L,), name="L_xf")

inputs_con = tf.keras.layers.concatenate([
input_A,
input_B,
input_C,
input_D,
input_E,
input_F,
input_G,
input_H
input_I,
input_J,
input_K,
input_L])

dense_1 = tf.keras.layers.Dense(50, activation = 'relu')(inputs_con)
dense_2 = tf keras.layers.Dense(25, activation = "rely") (dense_1)
output = tf.keras.laters.Dense(1, activation = "sigmoid") (dense_2)
model = keras.Model(inputs=inputs, outputs=outputs)

_inputs = [
input_A,
input_B,
input_C,
input_D,
input_E,
input_F,
input_G,
input_H,
input_I,
input_J,
input_K,
input_L]

model = tf.keras.models.Model(_inputs, output)

model.compile(optimizer='rmsprop',
          loss='binary_crossentropy',
          metrics=['accuracy'])

if show_summary:
    model.summary()

return model

1 个答案:

答案 0 :(得分:0)

LLTeng,不确定您对模型的意图是什么,但是根据实例,这会起作用:

inputs = tf.keras.Input((12,))
dense_1 = tf.keras.layers.Dense(50, activation = 'relu')(inputs)
dense_2 = tf keras.layers.Dense(25, activation = "rely") (dense_1)
output = tf.keras.laters.Dense(1, activation = "sigmoid") (dense_2)
model = tf.keras.Model(inputs=inputs, outputs=outputs)