import tensorflow.keras as keras model = keras.Sequential([ keras.layers.Dense(64, activation='relu', input_shape=(784,)), keras.layers.Dense(10, activation='softmax') ])
import tensorflow.keras as keras class CustomModel(keras.Model): def __init__(self): super(CustomModel, self).__init__() self.conv1 = keras.layers.Conv2D(64, (3, 3), activation='relu') self.conv2 = keras.layers.Conv2D(128, (3, 3), activation='relu') self.maxpool = keras.layers.MaxPooling2D((2, 2)) self.flatten = keras.layers.Flatten() self.dense1 = keras.layers.Dense(256, activation='relu') self.dense2 = keras.layers.Dense(10, activation='softmax') def call(self, x): x = self.conv1(x) x = self.conv2(x) x = self.maxpool(x) x = self.flatten(x) x = self.dense1(x) x = self.dense2(x) return xThis example demonstrates how to define a custom model architecture using the tensorflow.keras Model class. In this case, a convolutional neural network called CustomModel is defined with two Convolutional Layers, a MaxPooling layer, a Flatten layer and Two Dense layers. Package Library: The examples provided above use the tensorflow.keras package library. Tensorflow is a popular open source machine learning library developed and maintained by Google, and includes many different functional APIs, including the high-level keras API which is a popular deep learning API used by many data scientists and machine learning practitioners.