...

/

Model Subclassing (Part 2)

Model Subclassing (Part 2)

Learn to create DL models using model subclassing in Keras.

Model subclassing uses the superclass Model that’s part of the Keras library. We can follow the steps given below to perform model subclassing. Let’s implement model subclassing in Keras.

Step 1: Define a subclass

To perform model subclassing, we define a subclass and inherit the methods and attributes of the superclass Model.

Press + to interact
# Importing Model to perform model subclassing
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import Model
# To perform subclassing from the superclass Model, we create a subclass
class my_model_class(Model):
# __init__ constructor
def __init__(self):
super(my_model_class, self).__init__()
  • Line 7: This creates my_model_class, which is a subclass of Model ...