Update the Segmentation Tutorial Colab to be compatible with Keras 3 #2300
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've identified a couple of issues that occur under specific conditions when using TensorFlow 2.16 and Keras 3's plotting utilities, along with their respective solutions.
Issue 1: AttributeError with
plot_model
tf.keras.utils.plot_model(model, show_shapes=True)
, users encounter an AttributeError stating that a 'list' object has no attribute 'shape'.plot_model
function call by adding keyword argumentsexpand_nested=True
anddpi=64
. This not only resolves the AttributeError but also improves the visualization output (might be a little verbose but works without needing any changes to the plotting APIs). The adjusted function call looks like this:Issue 2: AttributeError with
SparseCategoricalCrossentropy
This occurs when
label
andprediction
are defined as lists, e.g.,label = [0,0]
andprediction = [[-3., 0], [-3, 0]]
.label
andprediction
objects into numpy arrays resolves the issue. The corrected definitions should be as follows:Summary of Changes:
expand_nested=True
anddpi=64
keyword arguments toplot_model
for enhanced visualization and error prevention.y_true
andy_pred
objects into numpy arrays before passing them toSparseCategoricalCrossentropy
to fix the AttributeError.