from keras.models import Sequential from keras.layers import Dense model = Sequential() model.add(Dense(32, input_dim=784)) model.add(Dense(10, activation='softmax')) num_params = model.count_params() print(num_params)
from keras.models import Sequential from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense model = Sequential() model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1))) model.add(MaxPooling2D((2, 2))) model.add(Conv2D(64, (3, 3), activation='relu')) model.add(MaxPooling2D((2, 2))) model.add(Conv2D(64, (3, 3), activation='relu')) model.add(Flatten()) model.add(Dense(64, activation='relu')) model.add(Dense(10, activation='softmax')) num_params = model.count_params() print(num_params)This example creates a convolutional neural network model with 3 convolutional layers and 2 dense layers. The input images have 28x28 pixels and 1 channel. The model also includes max pooling and flattening layers. The count_params() method is called to calculate the total number of parameters in the model. These examples use the Keras package library, which is a high-level neural networks API developed for Python. It can be used with different backend engines such as TensorFlow, Theano or CNTK.