Spaces:
Sleeping
Sleeping
Download train_model.py from prashantscripts/gesture: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/prashantscripts/gesture/resolve/main/train_model.py
- Command line
-
hf download hf://spaces/prashantscripts/gesture/train_model.py
-
curl -L -o train_model.py https://huggingface.co/spaces/prashantscripts/gesture/resolve/main/train_model.py
1.18 kB
| import pandas as pd | |
| import numpy as np | |
| import tensorflow as tf | |
| from sklearn.model_selection import train_test_split | |
| from tensorflow.keras.models import Sequential | |
| from tensorflow.keras.layers import Dense | |
| # Load the dataset | |
| data = pd.read_csv("gesture_data.csv") | |
| # Split features (X) and labels (y) | |
| X = data.iloc[:, :-1].values # Hand landmark positions | |
| y = data.iloc[:, -1] # Gesture labels | |
| # Convert labels to numbers | |
| from sklearn.preprocessing import LabelEncoder | |
| encoder = LabelEncoder() | |
| y = encoder.fit_transform(y) | |
| # Split data into training and testing sets | |
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) | |
| # Build the model | |
| model = Sequential([ | |
| Dense(128, activation='relu', input_shape=(X.shape[1],)), | |
| Dense(64, activation='relu'), | |
| Dense(len(set(y)), activation='softmax') # Number of gesture classes | |
| ]) | |
| # Compile the model | |
| model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) | |
| # Train the model | |
| model.fit(X_train, y_train, epochs=20, validation_data=(X_test, y_test)) | |
| # Save the trained model | |
| model.save("asl_model.h5") | |