0

作为 tfx trainer 和 pusher 输出的一部分,已保存的模型/预训练模型已通过以下库在 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 Platform Models 中测试服务模型时,我收到以下错误消息,您能帮我理解它的含义吗?我应该如何转换我的输入数据以被模型接受?

错误:

{
  "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 Platform 模型中的示例输入:

{
  "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
4

1 回答 1

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)
于 2020-12-11T04:25:29.020 回答