File size: 1,964 Bytes
bc31a94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import tensorflow as tf
from tensorflow import keras


def create_default_model(img_shape=(224, 224, 3), num_classes=10):
    """

    Create default yoga pose classification model using transfer learning

    

    Args:

        img_shape (tuple): Shape of input images

        num_classes (int): Number of yoga pose classes to predict

    

    Returns:

        model: Compiled tensorflow model

    """
    # Use MobileNetV2 as base model for transfer learning
    base_model = tf.keras.applications.MobileNetV2(
        input_shape=img_shape,
        include_top=False,
        weights='imagenet'
    )
    
    # Freeze the base model layers
    base_model.trainable = False
    
    model = tf.keras.Sequential([
        # Base model
        base_model,
        
        # Global average pooling
        tf.keras.layers.GlobalAveragePooling2D(),
        
        # Dense layers for pose classification
        tf.keras.layers.Dense(512, activation='relu'),
        tf.keras.layers.BatchNormalization(),
        tf.keras.layers.Dropout(0.3),
        
        tf.keras.layers.Dense(256, activation='relu'),
        tf.keras.layers.BatchNormalization(),
        tf.keras.layers.Dropout(0.3),
        
        # Output layer for pose classification
        tf.keras.layers.Dense(num_classes, activation='softmax')
    ])
    
    # Compile model
    model.compile(
        optimizer=tf.keras.optimizers.Adam(learning_rate=0.001),
        loss='categorical_crossentropy',
        metrics=['accuracy']
    )
    
    return model

def save_default_model():
    """

    Create and save default yoga pose classification model

    """
    model = create_default_model()
    
    # Save model
    model.save('yoga_pose_model.h5')
    print("Default yoga pose classification model created and saved successfully!")

# Allow direct execution to create model
if __name__ == "__main__":
    save_default_model()