Python – keras – graph disconnect: cannot obtain value for tensor KerasTensor

keras – graph disconnect: cannot obtain value for tensor KerasTensor… here is a solution to the problem.

keras – graph disconnect: cannot obtain value for tensor KerasTensor

I’ve been trying to create a 7-column (feature) model using the Keras functional API and map it to a 6-class output.

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)

Unfortunately, it results in the following error:

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: []

My list of features is as follows:

  1. Message – Text
  2. Description – Text
  3. has_errors – int represents a bool value
  4. has_panics – int represents a bool value
  5. has_images – int represents a bool value
  6. Submitter Group – Categorize input
  7. Reporter Group – Categorical Input – Total 6 possible values

I’ve been trying to click on the following link:
https://www.pyimagesearch.com/2019/02/04/keras-multiple-inputs-and-mixed-data/

So 2 questions:

  1. What causes the above error?
  2. Shouldn’t I apply some kind of embedding to text?

Thanks in advance

Solution

You may want to see the names of variables you own. GraphDisconnected Usually the error is caused by an overriding name in the program.

Related Problems and Solutions