|
|
from tensorflow.keras.layers import Input, Conv2D, MaxPooling2D, Flatten, Dense |
|
|
from tensorflow.keras.models import Model |
|
|
|
|
|
def sign_cnn_model(input_shape, num_classes): |
|
|
""" |
|
|
Creates a Convolutional Neural Network (CNN) model. |
|
|
|
|
|
Args: |
|
|
input_shape (tuple): The shape of the input data (height, width, channels). |
|
|
num_classes (int): The number of classes for the classification task. |
|
|
|
|
|
Returns: |
|
|
model (tensorflow.keras.Model): The constructed CNN model. |
|
|
""" |
|
|
|
|
|
input_layer = Input(shape=input_shape) |
|
|
|
|
|
|
|
|
x = Conv2D(32, (3, 3), activation='relu')(input_layer) |
|
|
x = MaxPooling2D(pool_size=(2, 2))(x) |
|
|
|
|
|
|
|
|
x = Conv2D(64, (3, 3), activation='relu')(x) |
|
|
x = MaxPooling2D(pool_size=(2, 2))(x) |
|
|
|
|
|
x = Conv2D(64, (3, 3), activation='relu')(x) |
|
|
x = MaxPooling2D(pool_size=(2, 2))(x) |
|
|
|
|
|
|
|
|
x = Flatten()(x) |
|
|
|
|
|
|
|
|
x = Dense(128, activation='relu')(x) |
|
|
|
|
|
|
|
|
output_layer = Dense(num_classes, activation='softmax')(x) |
|
|
|
|
|
|
|
|
model = Model(inputs=input_layer, outputs=output_layer) |
|
|
|
|
|
return model |
|
|
|