Hi everyone!
I’m new with Tensorflow and i need help
x_np_func = tf.keras.backend.function([], [x])
# Call the function to get the NumPy array `x_np`
x_np = x_np_func()[0]
tf.config.run_functions_eagerly(True)
foldn=0
log_list=[]
np.random.seed(2016)
kf = KFold(5, shuffle=True)
for train, test in kf.split(x):
model = train_model()
foldn += 1
print('number {} fold of {} folds cross validation'.format(foldn, n_splits))
print('Split into training and validation set', len(X_train[train]), len(X_train[test]))
weights_path = os.path.join('cache', 'weights_' + str(foldn) + '.h5')
callbacks = [
EarlyStopping(monitor='val_loss', patience=10, verbose=0),
ModelCheckpoint(weights_path, monitor='val_loss', save_best_only=True, verbose=1, mode='auto'),
]
log=model.fit(X_train[train], y_train[train], batch_size=32, epochs=40,
shuffle=True, verbose=1, validation_data=(X_train[test],y_train[test]),
callbacks=callbacks)
@Mohamed_Traore,
Welcome to the Tensorflow Forum,
Could you please share complete standalone code to debug your issue?
Thank you!
This is
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/var/folders/_t/s9_kytcd1lqbv1tyz6v8l8pr0000gn/T/ipykernel_3077/3420907820.py in <module>
----> 1 x_np_func = tf.keras.backend.function([], [x])
2
3 # Call the function to get the NumPy array `x_np`
4 x_np = x_np_func()[0]
5 tf.config.run_functions_eagerly(True)
/opt/anaconda3/lib/python3.9/site-packages/keras/src/backend.py in function(inputs, outputs, updates, name, **kwargs)
4654 from keras.src import models
4655
-> 4656 model = models.Model(inputs=inputs, outputs=outputs)
4657
4658 wrap_outputs = isinstance(outputs, list) and len(outputs) == 1
/opt/anaconda3/lib/python3.9/site-packages/tensorflow/python/trackable/base.py in _method_wrapper(self, *args, **kwargs)
202 self._self_setattr_tracking = False # pylint: disable=protected-access
203 try:
--> 204 result = method(self, *args, **kwargs)
205 finally:
206 self._self_setattr_tracking = previous_value # pylint: disable=protected-access
/opt/anaconda3/lib/python3.9/site-packages/keras/src/engine/functional.py in __init__(self, inputs, outputs, name, trainable, **kwargs)
165 inputs, outputs
166 )
--> 167 self._init_graph_network(inputs, outputs)
168
169 @tf.__internal__.tracking.no_automatic_dependency_tracking
/opt/anaconda3/lib/python3.9/site-packages/tensorflow/python/trackable/base.py in _method_wrapper(self, *args, **kwargs)
202 self._self_setattr_tracking = False # pylint: disable=protected-access
203 try:
--> 204 result = method(self, *args, **kwargs)
205 finally:
206 self._self_setattr_tracking = previous_value # pylint: disable=protected-access
/opt/anaconda3/lib/python3.9/site-packages/keras/src/engine/functional.py in _init_graph_network(self, inputs, outputs)
264
265 # Keep track of the network's nodes and layers.
--> 266 nodes, nodes_by_depth, layers, _ = _map_graph_network(
267 self.inputs, self.outputs
268 )
/opt/anaconda3/lib/python3.9/site-packages/keras/src/engine/functional.py in _map_graph_network(inputs, outputs)
1140 for x in tf.nest.flatten(node.keras_inputs):
1141 if id(x) not in computable_tensors:
-> 1142 raise ValueError(
1143 "Graph disconnected: cannot obtain value for "
1144 f'tensor {x} at layer "{layer.name}". '
ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor(type_spec=TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name='image_input'), name='image_input', description="created by layer 'image_input'") at layer "resnet50". The following previous layers were accessed without issue: []
@Mohamed_Traore,
ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor(type_spec=TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name=‘image_input’), name=‘image_input’, description=“created by layer ‘image_input’”) at layer “resnet50”. The following previous layers were accessed without issue:
Generally this error occurs when there is an issue with the input and output tensors or when the layers are not correctly connected.
Please make sure, the input shape matches the expected shape for the resnet50
and all the layers in your model are properly connected.
Thank you!