This commit is contained in:
Mikołaj Pokrywka 2023-01-21 16:22:16 +01:00
parent cd0fe3ffac
commit 10d83849a8
16 changed files with 192 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
venv

View File

@ -1,2 +1,6 @@
# projekt_widzenie
## Run apllication
1. `pip install -r requirements.txt`
2. `streamlit run main.py`
3. On http://localhost:8501/ you should see the app

11
main.py Normal file
View File

@ -0,0 +1,11 @@
import streamlit as st
if __name__ == "__main__":
st.set_page_config(
page_title="Projekt widzenie"
)
st.title("Projekt rozpoznawanie liter z alfabetu znaków migowych z wideo")
st.write('Hello world')

Binary file not shown.

After

Width:  |  Height:  |  Size: 679 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 KiB

View File

23
model_pred/pred.py Normal file
View File

@ -0,0 +1,23 @@
import numpy as np
import tensorflow as tf
from tensorflow import keras
model = keras.models.load_model('sign_car_detection_model')
class_names = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'del', 'nothing', 'space']
def pred_sign_char(path_to_img: str):
pred = []
test_image = tf.keras.utils.load_img(path_to_img, target_size = (256, 256))
test_image = tf.keras.utils.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis = 0)
result = model.predict(test_image)
print(result)
pred.append(class_names[np.argmax(result)])
print(pred)
return pred[0]

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
streamlit
pandas
tensorflow
numpy

View File

@ -0,0 +1,131 @@
# %% [markdown]
# # Import the required libraries
# %%
import pandas as pd
import numpy as np
import tensorflow as tf
# %% [markdown]
# # Preprocessing the image data
# %%
#taking the train validation ratio as 4:1
# %%
batch_size=32
img_height=256
img_width=256
train_ds = tf.keras.utils.image_dataset_from_directory(
"asl_alphabet_train/asl_alphabet_train/",
validation_split=0.2,
subset="training",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
# %%
test_ds = tf.keras.utils.image_dataset_from_directory(
"asl_alphabet_train/asl_alphabet_train/",
validation_split=0.2,
subset="validation",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
# %%
class_names = train_ds.class_names
print("Class names:",class_names)
print("Total classes:",len(class_names))
# %%
#random samples of images from the train data
# %%
import matplotlib.pyplot as plt
plt.figure(figsize=(10, 10))
for images, labels in train_ds.take(1):
for i in range(29):
ax = plt.subplot(6,5 , i + 1)
plt.imshow(images[i].numpy().astype("uint8"))
plt.title(class_names[labels[i]])
plt.axis("off")
# %% [markdown]
# # Modelling and training
# %%
#modelling
from tensorflow.keras import Sequential
from tensorflow.keras import layers
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
model = Sequential([
layers.Rescaling(1./255, input_shape=(img_height, img_width, 3)),
layers.Conv2D(16, 3, padding='same', activation='relu'),
layers.MaxPooling2D(),
layers.Conv2D(32, 3, padding='same', activation='relu'),
layers.MaxPooling2D(),
layers.Conv2D(64, 3, padding='same', activation='relu'),
layers.MaxPooling2D(),
layers.Flatten(),
layers.Dense(128, activation='relu'),
layers.Dense(29,activation='softmax')
])
# %%
model.summary()
# %%
model.compile(loss='sparse_categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
# %%
model.fit(train_ds, batch_size=128,validation_batch_size=128, validation_data=test_ds,epochs=20)
model.save('sign_car_detection_model')
# %% [markdown]
# # Prediction on the test data
# %%
import os
# Get the list of all files and directories
path = "asl_alphabet_test/asl_alphabet_test/"
dir_list = os.listdir(path)
print(dir_list)
# %%
from sklearn.preprocessing import OneHotEncoder, LabelEncoder
tf.keras.utils.load_img
actual=[]
pred=[]
for i in dir_list:
actual.append(i.split('_')[0])
test_image = tf.keras.utils.load_img('asl_alphabet_test/asl_alphabet_test/'+i, target_size = (256, 256))
test_image = tf.keras.utils.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis = 0)
result = model.predict(test_image)
pred.append(class_names[np.argmax(result)])
# %%
from sklearn.metrics import confusion_matrix, classification_report
from sklearn.metrics import accuracy_score
print("Test accuracy=",accuracy_score(pred,actual))
print("Classification report:\n",classification_report(pred,actual))
# %%