Introduction
It's generally possible to do almost anything in Keras without writing code per se: whether you're implementing a new type of GAN or the latest convnet architecture for image segmentation, you can usually stick to calling built-in methods. Because all built-in methods do extensive input validation checks, you will have little to no debugging to do. A Functional API model made entirely of built-in layers will work on first try -- if you can compile it, it will run.
However, sometimes, you will need to dive deeper and write your own code. Here are some common examples:
Creating a new Layer subclass.
Creating a custom Metric subclass.
Implementing a custom train_step on a Model.
This document provides a few simple tips to help you navigate debugging in these situations.
Tip 1: test each part before you test the whole
Tip 2: use model.summary() and plot_model() to check layer output shapes
Tip 3: to debug what happens during fit(), use run_eagerly=True
Tip 4: if your code is slow, run the TensorFlow profiler
链接地址:https://keras.io/examples/keras_recipes/debugging_tips/