Spaces:
Runtime error
Runtime error
Delete sign_language_model.h5
Browse files- sign_language_model.h5 +0 -45
sign_language_model.h5
DELETED
|
@@ -1,45 +0,0 @@
|
|
| 1 |
-
import tensorflow as tf
|
| 2 |
-
from tensorflow.keras import layers, models
|
| 3 |
-
import tensorflow_datasets as tfds
|
| 4 |
-
|
| 5 |
-
# Load the dataset using tensorflow_datasets
|
| 6 |
-
dataset, info = tfds.load('sign_language_mnist', with_info=True, as_supervised=True)
|
| 7 |
-
|
| 8 |
-
# Split the dataset into train and test
|
| 9 |
-
train_data, test_data = dataset['train'], dataset['test']
|
| 10 |
-
|
| 11 |
-
def preprocess_image(image, label):
|
| 12 |
-
image = tf.image.rgb_to_grayscale(image) # Ensure it's grayscale
|
| 13 |
-
image = tf.image.resize(image, (28, 28)) # Resize to 28x28
|
| 14 |
-
image = image / 255.0 # Normalize the image
|
| 15 |
-
return image, label
|
| 16 |
-
|
| 17 |
-
# Preprocess images
|
| 18 |
-
train_data = train_data.map(preprocess_image).batch(32).shuffle(10000)
|
| 19 |
-
test_data = test_data.map(preprocess_image).batch(32)
|
| 20 |
-
|
| 21 |
-
# Build the model
|
| 22 |
-
model = models.Sequential([
|
| 23 |
-
layers.InputLayer(input_shape=(28, 28, 1)),
|
| 24 |
-
layers.Conv2D(32, (3, 3), activation='relu'),
|
| 25 |
-
layers.MaxPooling2D((2, 2)),
|
| 26 |
-
layers.Conv2D(64, (3, 3), activation='relu'),
|
| 27 |
-
layers.MaxPooling2D((2, 2)),
|
| 28 |
-
layers.Conv2D(64, (3, 3), activation='relu'),
|
| 29 |
-
layers.Flatten(),
|
| 30 |
-
layers.Dense(64, activation='relu'),
|
| 31 |
-
layers.Dense(26, activation='softmax') # 26 letters for ASL alphabet
|
| 32 |
-
])
|
| 33 |
-
|
| 34 |
-
# Compile the model
|
| 35 |
-
model.compile(optimizer='adam',
|
| 36 |
-
loss='sparse_categorical_crossentropy',
|
| 37 |
-
metrics=['accuracy'])
|
| 38 |
-
|
| 39 |
-
# Train the model
|
| 40 |
-
model.fit(train_data, epochs=5, validation_data=test_data)
|
| 41 |
-
|
| 42 |
-
# Save the trained model
|
| 43 |
-
model.save('sign_language_model.h5')
|
| 44 |
-
|
| 45 |
-
print("Model trained and saved as 'sign_language_model.h5'")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|