首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >TF模型在Google平台上的模型错误:“预期序列化为标量或向量,得到形状:[1,12]”

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

Stack Overflow用户
提问于 2020-05-29 03:53:17
回答 1查看 323关注 0票数 0

作为tfx培训师和pusher输出的一部分,已通过以下库在Google平台作业和模型中执行保存的模型/预培训模型。

代码语言:javascript
运行
复制
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平台上测试服务模型时,我收到了以下错误消息,请您帮助我理解它的含义吗?我应该如何转换输入数据以被模型接受?

错误:

代码语言:javascript
运行
复制
{
  "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平台模型中的示例输入:

代码语言:javascript
运行
复制
{
  "instances": [
["A", "B", "C", "D","E", "F", "G", "H", "I", "J", "K", "L"]
  ]
}

,这是训练师的代码.

代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

发布于 2020-12-11 04:25:29

LLTeng,不确定您对该模型的意图是什么,但基于实例,这将起作用:

代码语言:javascript
运行
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62078419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档