File size: 2,523 Bytes
1f4e4ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
68
69
70
71
import streamlit as st
import cv2
import numpy as np
import os
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense, Dropout
from tensorflow.keras.callbacks import ModelCheckpoint, TensorBoard
import mediapipe as mp
from utils.data_utils import process_video, extract_landmarks
from utils.model_utils import create_model, convert_to_tflite

def main():
    st.title("Sign Language Model Training Platform")
    
    # Sidebar for training configuration
    st.sidebar.header("Training Configuration")
    
    # Model parameters
    num_classes = st.sidebar.number_input("Number of Sign Classes", min_value=2, value=10)
    epochs = st.sidebar.number_input("Training Epochs", min_value=1, value=50)
    batch_size = st.sidebar.number_input("Batch Size", min_value=1, value=32)
    
    # Dataset upload
    st.header("Dataset Upload")
    dataset_path = st.file_uploader("Upload Dataset (ZIP file containing video folders)", type=['zip'])
    
    if dataset_path:
        # Create progress bar
        progress_bar = st.progress(0)
        status_text = st.empty()
        
        # Extract dataset
        status_text.text("Extracting dataset...")
        # TODO: Add dataset extraction logic
        
        # Process videos and extract landmarks
        status_text.text("Processing videos and extracting landmarks...")
        X_train, y_train = [], []
        # TODO: Add video processing logic using MediaPipe
        
        # Create and train model
        if st.button("Start Training"):
            status_text.text("Creating model...")
            model = create_model(num_classes)
            
            status_text.text("Training model...")
            history = model.fit(
                X_train, y_train,
                epochs=epochs,
                batch_size=batch_size,
                validation_split=0.2,
                callbacks=[
                    ModelCheckpoint('models/best_model.h5', save_best_only=True),
                    TensorBoard(log_dir='logs')
                ]
            )
            
            # Convert to TFLite
            status_text.text("Converting model to TFLite...")
            convert_to_tflite(model, 'models/model.tflite')
            
            st.success("Training completed! Model saved as 'model.tflite'")
            
            # Display training metrics
            st.header("Training Results")
            st.line_chart(history.history)

if __name__ == "__main__":
    main()