ValueError: Graph Disconnected: Cannot Obtain Value For Tensor Tensor...The Following Previous Layers Were Accessed Without Issue: []
Solution 1:
There are few issues with your Keras functional API implementation,
You should use the
Concatenate
layer asConcatenate(axis=-1)([text_encoded, topic_input])
.In the concatenate layer you are trying to combine an
int32
tensor and afloat32
tensor, which is not allowed. What you should do is,from keras.backend import cast
andconcatenated = Concatenate(axis=-1)([text_encoded, cast(topic_input, 'float32')])
.You got variable conflicts, there are two
sentiment
variables, one pointing to ato_categorical
output and the other the output of the finalDense
layer.Your model inputs cannot be intermediate tensors like
text_encoded
. They should come fromInput
layers.
To help with your implementation, here's a working version of your code (I am not sure if this is exactly what you wanted though) in TF 1.13.
from keras.utils import to_categorical
text = np.random.randint(5000, size=(442702, 200), dtype='int32')
topic = np.random.randint(2, size=(442702, 227), dtype='int32')
sentiment1 = to_categorical(np.random.randint(5, size=442702), dtype='int32')
from keras.models import Sequential
from keras.layers import Input, Dense, Activation, Embedding, Flatten, GlobalMaxPool1D, Dropout, Conv1D, Concatenate, Lambda
from keras.callbacks import ReduceLROnPlateau, EarlyStopping, ModelCheckpoint
from keras.losses import binary_crossentropy
from keras.optimizers import Adam
from keras.backend import cast
from keras.models import Model
text_input = Input(shape=(200,), dtype='int32', name='text')
text_encoded = Embedding(input_dim=5000, output_dim=20, input_length=200)(text_input)
text_encoded = Dropout(0.1)(text_encoded)
text_encoded = Conv1D(300, 3, padding='valid', activation='relu', strides=1)(text_encoded)
text_encoded = GlobalMaxPool1D()(text_encoded)
topic_input = Input(shape=(227,), dtype='int32', name='topic')
topic_float = Lambda(lambda x:cast(x, 'float32'), name='Floatconverter')(topic_input)
concatenated = Concatenate(axis=-1)([text_encoded, topic_float])
sentiment = Dense(5, activation='softmax')(concatenated)
model = Model(inputs=[text_input, topic_input], outputs=sentiment)
# summarize layers
print(model.summary())
Hope these help.
Post a Comment for "ValueError: Graph Disconnected: Cannot Obtain Value For Tensor Tensor...The Following Previous Layers Were Accessed Without Issue: []"