I am trying to preprocess the data for the Titanic problem on Kaggle, following this link
train_data = pd.read_csv("/kaggle/input/titanic/train.csv")
train_data = train_data.drop(columns=['Cabin'])
titanic_features = train_data.copy()
titanic_labels = titanic_features.pop('Survived')
inputs = {}
for name, column in titanic_features.items():
dtype = column.dtype
if dtype == object:
dtype = tf.string
else:
dtype = tf.float32
inputs[name] = tf.keras.Input(shape=(1,), name=name, dtype=dtype)
numeric_inputs = {name:input for name,input in inputs.items()
if input.dtype==tf.float32}
x = layers.Concatenate()(list(numeric_inputs.values()))
norm = preprocessing.Normalization()
norm.adapt(np.array(train_data[numeric_inputs.keys()]))
all_numeric_inputs = norm(x)
preprocessed_inputs = [all_numeric_inputs]
for name, inpute in inputs.items():
if inpute.dtype == tf.float32:
continue
lookup = preprocessing.StringLookup(vocabulary=np.unique(titanic_features[name].dropna()))
one_hot = preprocessing.CategoryEncoding(max_tokens=lookup.vocab_size())
x = lookup(input)
x = one_hot(x)
preprocessed_inputs.append(x)
preprocessed_inputs_cat = layers.Concatenate()(preprocessed_inputs)
titanic_preprocessing = tf.keras.Model(inputs, preprocessed_inputs_cat)
I have the following error:
ValueError: Graph disconnected: cannot obtain value for tensor
Tensor("Cabin_17:0", shape=(None, 1), dtype=string) at layer
"string_lookup_214". The following previous layers were accessed
without issue: []
So I removed the 'Cabin' column (as you can see in my code), but the problem is still here. I have checked all other arrays, datas etc. in my code, there is not any trace of 'Cabin'.
I really cannot see what's going wrong here.
Thanks a lot
Aymeric
question from:
https://stackoverflow.com/questions/65872290/graph-disconnected-cannot-obtain-value-for-tensor-tensor 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…