gpt4 book ai didi

python - keras - 图断开连接 : cannot obtain value for tensor KerasTensor

转载 作者:行者123 更新时间:2023-12-05 03:39:51 28 4
gpt4 key购买 nike

我一直在尝试使用 Keras 函数式 API 创建 7 列(特征)模型并将其映射到 6 类输出。

import tensorflow as tf
from tensorflow.keras import Model
from tensorflow.keras.layers import Input, Dense, Concatenate

input_message = Input(shape=(128,))
x = Dense(64, activation="relu")(input_message)
x = Dense(32, activation="relu")(x)
x = Dense(4, activation="relu")(x)
model_message = Model(inputs=input_message, outputs=x)

input_description = Input(shape=(128,))
x = Dense(64, activation="relu")(input_description)
x = Dense(32, activation="relu")(x)
x = Dense(4, activation="relu")(x)
model_description = Model(inputs=input_description, outputs=x)

input_errors = Input(shape=(2,))
x = Dense(1, activation="relu")(input_errors)
model_errors = Model(inputs=input_errors, outputs=x)

input_panics = Input(shape=(2,))
x = Dense(1, activation="relu")(input_panics)
model_panics = Model(inputs=input_panics, outputs=x)

input_images = Input(shape=(2,))
x = Dense(1, activation="relu")(input_images)
model_images = Model(inputs=input_images, outputs=x)

input_committer = Input(shape=(16,))
x = Dense(4, activation="relu")(input_description)
model_committer = Model(inputs=input_committer, outputs=x)

input_reporter = Input(shape=(6,))
x = Dense(1, activation="relu")(input_reporter)
model_reporter = Model(inputs=input_reporter, outputs=x)

combined = Concatenate()([model_message.output, model_description.output, model_errors.output,
model_panics.output, model_images.output, model_committer.output, model_reporter.output])

z = Dense(6, activation='softmax')(combined)
model = Model(inputs=[model_message.input, model_description.input, model_errors.input,
model_panics.input, model_images.input, model_committer.input, model_reporter.input],
outputs=z)

遗憾的是,它导致了以下错误:

ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor(type_spec=TensorSpec(shape=(None, 128), dtype=tf.float32, name='input_23'), name='input_23', description="created by layer 'input_23'") at layer "dense_74". The following previous layers were accessed without issue: []

我的功能列表如下:

  1. 消息 - 文本
  2. 描述 - 文字
  3. has_errors - int 表示一个 bool 值
  4. has_panics - int 表示一个 bool 值
  5. has_images - int 表示一个 bool 值
  6. 提交者组 - 分类输入
  7. 报告者组 - 分类输入 - 总共 6 个可能的值

我一直在尝试点击以下链接: https://www.pyimagesearch.com/2019/02/04/keras-multiple-inputs-and-mixed-data/

所以 2 个问题:

  1. 是什么导致了上述错误?
  2. 我不应该为文本应用某种嵌入吗?

提前致谢

最佳答案

您可能想查看您拥有的变量名称。通常 GraphDisconnected 错误是由于程序中有覆盖名称引起的。

关于python - keras - 图断开连接 : cannot obtain value for tensor KerasTensor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68432386/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com