JumaRubea's picture
five digit hand sign classifier
b44d0c7 verified
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_layer = Input(shape=input_shape)
# 1st Convolutional Layer
x = Conv2D(32, (3, 3), activation='relu')(input_layer)
x = MaxPooling2D(pool_size=(2, 2))(x)
# 2nd Convolutional Layer
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)
# Flatten layer to convert 2D feature maps into 1D feature vectors
x = Flatten()(x)
# Fully Connected Dense Layer
x = Dense(128, activation='relu')(x)
# Output Layer with softmax activation for classification
output_layer = Dense(num_classes, activation='softmax')(x)
# Define the model
model = Model(inputs=input_layer, outputs=output_layer)
return model