diff --git a/Hindi_Letter_Classification/Dataset/README.md b/Hindi_Letter_Classification/Dataset/README.md new file mode 100644 index 00000000..21fd552d --- /dev/null +++ b/Hindi_Letter_Classification/Dataset/README.md @@ -0,0 +1,36 @@ +# Hindi Letter Classification + +## Introduction + +This is a hindi letter classification web application created using python and utilizes Convolutional Neural Networks, it utilizes +LENET-5 architecture. This architecture was created in 1998. We can also use other architectures like ALEXNET, GoogleNET, RESNET, VGGNET etc. + +![Alt text](https://indiatyping.com/images/Hindi_Alphabets.webp "Hindi letters") + +## Web Application + +The web app is created using streamlit framework. It contains a heading, small introduction and then a image uploader. After the user uploads image, the image goes to backend and respected class is predicted by the CNN model and then the uploaded image along with prediction is showed. We can play with prediciton time and accuracy by changing batch_size, number of epochs and using a different CNN architecture. + +## Libraries used + +1. Numpy +2. Keras +3. Tensorflow +4. Streamlit + +# How to run locally + +Install the necessary libraries using pip then +open the project folder and +run following command : + +```python + +streamlit run file_name.py + +``` + +# Snapshots + +![Alt text](https://i.postimg.cc/nVyGVndx/Screenshot-2024-05-13-111142.png "Snapshot 1") +![Alt text](https://i.postimg.cc/sgkrwQm8/Screenshot-2024-05-13-111154.png "Snapshot 2") diff --git a/Hindi_Letter_Classification/Dataset/Test/character_10_jha.png b/Hindi_Letter_Classification/Dataset/Test/character_10_jha.png new file mode 100644 index 00000000..7966470e Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/character_10_jha.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/character_1_ka.png b/Hindi_Letter_Classification/Dataset/Test/character_1_ka.png new file mode 100644 index 00000000..0b824fa7 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/character_1_ka.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/character_2_kha.png b/Hindi_Letter_Classification/Dataset/Test/character_2_kha.png new file mode 100644 index 00000000..5d84819f Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/character_2_kha.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/character_3_ga.png b/Hindi_Letter_Classification/Dataset/Test/character_3_ga.png new file mode 100644 index 00000000..3fdf0a7c Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/character_3_ga.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/character_4_gha.png b/Hindi_Letter_Classification/Dataset/Test/character_4_gha.png new file mode 100644 index 00000000..05e1d8d2 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/character_4_gha.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/character_5_da.png b/Hindi_Letter_Classification/Dataset/Test/character_5_da.png new file mode 100644 index 00000000..0b288b41 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/character_5_da.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/character_6_dha.png b/Hindi_Letter_Classification/Dataset/Test/character_6_dha.png new file mode 100644 index 00000000..376cd3d4 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/character_6_dha.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/character_7_chha.png b/Hindi_Letter_Classification/Dataset/Test/character_7_chha.png new file mode 100644 index 00000000..caa7d70c Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/character_7_chha.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/character_8_cha.png b/Hindi_Letter_Classification/Dataset/Test/character_8_cha.png new file mode 100644 index 00000000..7366725f Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/character_8_cha.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/character_9_ja.png b/Hindi_Letter_Classification/Dataset/Test/character_9_ja.png new file mode 100644 index 00000000..75859a7b Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/character_9_ja.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/digit_0.png b/Hindi_Letter_Classification/Dataset/Test/digit_0.png new file mode 100644 index 00000000..26326c18 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/digit_0.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/digit_1.png b/Hindi_Letter_Classification/Dataset/Test/digit_1.png new file mode 100644 index 00000000..582d1c2b Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/digit_1.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/digit_3.png b/Hindi_Letter_Classification/Dataset/Test/digit_3.png new file mode 100644 index 00000000..22ac2b48 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/digit_3.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/digit_4.png b/Hindi_Letter_Classification/Dataset/Test/digit_4.png new file mode 100644 index 00000000..a6366d0c Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/digit_4.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/digit_5.png b/Hindi_Letter_Classification/Dataset/Test/digit_5.png new file mode 100644 index 00000000..9adf47ed Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/digit_5.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/digit_6.png b/Hindi_Letter_Classification/Dataset/Test/digit_6.png new file mode 100644 index 00000000..071ea85f Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/digit_6.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/digit_7.png b/Hindi_Letter_Classification/Dataset/Test/digit_7.png new file mode 100644 index 00000000..1a4c966d Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/digit_7.png differ diff --git a/Hindi_Letter_Classification/Dataset/Test/digit_9.png b/Hindi_Letter_Classification/Dataset/Test/digit_9.png new file mode 100644 index 00000000..f312ab08 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Test/digit_9.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/character_10_jha.png b/Hindi_Letter_Classification/Dataset/Train/character_10_jha.png new file mode 100644 index 00000000..7966470e Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/character_10_jha.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/character_1_ka.png b/Hindi_Letter_Classification/Dataset/Train/character_1_ka.png new file mode 100644 index 00000000..0b824fa7 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/character_1_ka.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/character_2_kha.png b/Hindi_Letter_Classification/Dataset/Train/character_2_kha.png new file mode 100644 index 00000000..5d84819f Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/character_2_kha.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/character_3_ga.png b/Hindi_Letter_Classification/Dataset/Train/character_3_ga.png new file mode 100644 index 00000000..3fdf0a7c Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/character_3_ga.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/character_4_gha.png b/Hindi_Letter_Classification/Dataset/Train/character_4_gha.png new file mode 100644 index 00000000..05e1d8d2 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/character_4_gha.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/character_5_da.png b/Hindi_Letter_Classification/Dataset/Train/character_5_da.png new file mode 100644 index 00000000..0b288b41 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/character_5_da.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/character_6_dha.png b/Hindi_Letter_Classification/Dataset/Train/character_6_dha.png new file mode 100644 index 00000000..376cd3d4 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/character_6_dha.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/character_7_chha.png b/Hindi_Letter_Classification/Dataset/Train/character_7_chha.png new file mode 100644 index 00000000..caa7d70c Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/character_7_chha.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/character_8_cha.png b/Hindi_Letter_Classification/Dataset/Train/character_8_cha.png new file mode 100644 index 00000000..7366725f Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/character_8_cha.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/character_9_ja.png b/Hindi_Letter_Classification/Dataset/Train/character_9_ja.png new file mode 100644 index 00000000..75859a7b Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/character_9_ja.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/digit_0.png b/Hindi_Letter_Classification/Dataset/Train/digit_0.png new file mode 100644 index 00000000..26326c18 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/digit_0.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/digit_1.png b/Hindi_Letter_Classification/Dataset/Train/digit_1.png new file mode 100644 index 00000000..582d1c2b Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/digit_1.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/digit_3.png b/Hindi_Letter_Classification/Dataset/Train/digit_3.png new file mode 100644 index 00000000..22ac2b48 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/digit_3.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/digit_4.png b/Hindi_Letter_Classification/Dataset/Train/digit_4.png new file mode 100644 index 00000000..a6366d0c Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/digit_4.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/digit_5.png b/Hindi_Letter_Classification/Dataset/Train/digit_5.png new file mode 100644 index 00000000..9adf47ed Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/digit_5.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/digit_6.png b/Hindi_Letter_Classification/Dataset/Train/digit_6.png new file mode 100644 index 00000000..071ea85f Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/digit_6.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/digit_7.png b/Hindi_Letter_Classification/Dataset/Train/digit_7.png new file mode 100644 index 00000000..1a4c966d Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/digit_7.png differ diff --git a/Hindi_Letter_Classification/Dataset/Train/digit_9.png b/Hindi_Letter_Classification/Dataset/Train/digit_9.png new file mode 100644 index 00000000..f312ab08 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/Train/digit_9.png differ diff --git a/Hindi_Letter_Classification/Dataset/Web_app.ipynb b/Hindi_Letter_Classification/Dataset/Web_app.ipynb new file mode 100644 index 00000000..e2286675 --- /dev/null +++ b/Hindi_Letter_Classification/Dataset/Web_app.ipynb @@ -0,0 +1,179 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Importing Streamlit" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import streamlit as st" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Creating Web App" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "st.title(\"Hindi Letter classification 🕉️\") #Title of page\n", + "st.divider() #A divider line\n", + "st.image(\"https://i.pinimg.com/474x/ce/79/6c/ce796ceb0d16147fd7853f1a3fdd0210.jpg\") # adds a image\n", + "st.subheader(\"Introduction\") # adds a subheader\n", + "st.write('''\n", + "The web app is created using streamlit framework. It contains a heading, small introduction and then a image uploader.\n", + " After the user uploads image, the image goes to backend and respected class is predicted by the CNN model and then\n", + " the uploaded image along with prediction is showed. We can play with prediciton time and accuracy by changing batch_size,\n", + " number of epochs and using a different CNN architecture.\n", + "\n", + "''') # adds a piece of text\n", + "st.divider()\n", + "uploaded_file = st.file_uploader(\"Enter image to Predict\", type=['png', 'jpg']) # adds a file uploader widget\n", + "submit = st.button(\"Submit\") #submit button\n", + "st.write(\"It may take 2-3 minutes to predict the image\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# After clicking submit button" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Creating training data and then making training and test set" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "if submit:\n", + " if uploaded_file is not None:\n", + "\n", + " import tensorflow as tf\n", + " from keras.preprocessing.image import ImageDataGenerator \n", + " train_datagen = ImageDataGenerator(rescale = 1./255, # applying modifications to training set\n", + " shear_range = 0.2,\n", + " zoom_range = 0.2,\n", + " horizontal_flip = True)\n", + " training_set = train_datagen.flow_from_directory('Dataset/dataset/train', # creating trainig set of batch size 30\n", + " target_size = (64, 64),\n", + " batch_size = 30,\n", + " class_mode = 'categorical')\n", + " test_datagen = ImageDataGenerator(rescale = 1./255) # applying modification to test set\n", + " test_set = test_datagen.flow_from_directory('Dataset/dataset/test', # creating test set of batch size 30\n", + " target_size = (64, 64),\n", + " batch_size = 30,\n", + " class_mode = 'categorical')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Creating LENET-5 architecture" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + " # LeNet-5 architecture\n", + " lenet = tf.keras.models.Sequential()\n", + "\n", + " # Layer 1: Convolutional layer with 6 filters, kernel size 5x5, and ReLU activation\n", + " lenet.add(tf.keras.layers.Conv2D(filters=6, kernel_size=5, activation='relu', input_shape=[64, 64, 3]))\n", + "\n", + " # Layer 2: Average pooling layer with pool size 2x2 and strides 2\n", + " lenet.add(tf.keras.layers.AveragePooling2D(pool_size=2, strides=2))\n", + "\n", + " # Layer 3: Convolutional layer with 16 filters, kernel size 5x5, and ReLU activation\n", + " lenet.add(tf.keras.layers.Conv2D(filters=16, kernel_size=5, activation='relu'))\n", + "\n", + " # Layer 4: Average pooling layer with pool size 2x2 and strides 2\n", + " lenet.add(tf.keras.layers.AveragePooling2D(pool_size=2, strides=2))\n", + "\n", + " # Layer 5: Flatten layer\n", + " lenet.add(tf.keras.layers.Flatten())\n", + "\n", + " # Layer 6: Fully connected layer with 120 units and ReLU activation\n", + " lenet.add(tf.keras.layers.Dense(units=120, activation='relu'))\n", + "\n", + " # Layer 7: Fully connected layer with 84 units and ReLU activation\n", + " lenet.add(tf.keras.layers.Dense(units=84, activation='relu'))\n", + "\n", + " # Layer 8: Output layer with 46 units (assuming it's the number of classes) and softmax activation\n", + " lenet.add(tf.keras.layers.Dense(units=46, activation='softmax'))\n", + "\n", + " # Compile the model with Adam optimizer and categorical crossentropy loss\n", + " lenet.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])\n", + "\n", + " lenet.fit(x = training_set, validation_data = test_set, epochs = 15)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Predicting the class of uploaded file" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + " from keras.preprocessing import image\n", + " if uploaded_file is not None: # if user has uploaded any file\n", + " try:\n", + " class_indices = training_set.class_indices\n", + " test_image = image.load_img(uploaded_file, target_size = (64, 64)) # modifying uploaded image to be sent for prediction\n", + " test_image = image.img_to_array(test_image) # converting image to array\n", + " test_image = np.expand_dims(test_image, axis = 0) # changing dimension of image\n", + " result = lenet.predict(test_image) #getting the prediction\n", + " prediction = lenet.predict(test_image)\n", + " predicted_class_index = np.argmax(prediction) # getting the classindex with highest probability\n", + " predicted_class_name = [key for key, value in class_indices.items() if value == predicted_class_index][0] #getting the name corresponding to predicted index\n", + " st.image(uploaded_file) # displaying uploaded image\n", + " st.write(predicted_class_name) # writing the prediction in web app\n", + " print(predicted_class_index)\n", + " except:\n", + " st.write(\"There is error in file provided\")\n", + " \n", + " \n", + " elif uploaded_file is None: # if no file uploaded and submit is clicked, this error comes up\n", + " st.markdown(\":red[Please enter a image]\")" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Hindi_Letter_Classification/Dataset/class_indexes.txt b/Hindi_Letter_Classification/Dataset/class_indexes.txt new file mode 100644 index 00000000..09c6d504 --- /dev/null +++ b/Hindi_Letter_Classification/Dataset/class_indexes.txt @@ -0,0 +1,46 @@ +ka +kha +ga +gha +kna +cha +chha +ja +jha +yna +tamaatar +thaa +daa +dhaa +adna +tabala +tha +da +dha +na +pa +pha +ba +bha +ma +yaw +ra +la +waw +motosaw +petchiryakha +patalosaw +ha +chhya +tra +gya +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 diff --git a/Hindi_Letter_Classification/Dataset/single_prediction/test10.jpg b/Hindi_Letter_Classification/Dataset/single_prediction/test10.jpg new file mode 100644 index 00000000..7d9bcb84 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/single_prediction/test10.jpg differ diff --git a/Hindi_Letter_Classification/Dataset/single_prediction/test11.png b/Hindi_Letter_Classification/Dataset/single_prediction/test11.png new file mode 100644 index 00000000..0058b017 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/single_prediction/test11.png differ diff --git a/Hindi_Letter_Classification/Dataset/single_prediction/test4.png b/Hindi_Letter_Classification/Dataset/single_prediction/test4.png new file mode 100644 index 00000000..048c5721 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/single_prediction/test4.png differ diff --git a/Hindi_Letter_Classification/Dataset/single_prediction/test5.png b/Hindi_Letter_Classification/Dataset/single_prediction/test5.png new file mode 100644 index 00000000..8ee9a98b Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/single_prediction/test5.png differ diff --git a/Hindi_Letter_Classification/Dataset/single_prediction/test6.png b/Hindi_Letter_Classification/Dataset/single_prediction/test6.png new file mode 100644 index 00000000..10037ea0 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/single_prediction/test6.png differ diff --git a/Hindi_Letter_Classification/Dataset/single_prediction/test7.png b/Hindi_Letter_Classification/Dataset/single_prediction/test7.png new file mode 100644 index 00000000..cd97a81f Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/single_prediction/test7.png differ diff --git a/Hindi_Letter_Classification/Dataset/single_prediction/test8.png b/Hindi_Letter_Classification/Dataset/single_prediction/test8.png new file mode 100644 index 00000000..d9e02b2c Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/single_prediction/test8.png differ diff --git a/Hindi_Letter_Classification/Dataset/single_prediction/test9.png b/Hindi_Letter_Classification/Dataset/single_prediction/test9.png new file mode 100644 index 00000000..14838e07 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/single_prediction/test9.png differ diff --git a/Hindi_Letter_Classification/Dataset/single_prediction/tset12.png b/Hindi_Letter_Classification/Dataset/single_prediction/tset12.png new file mode 100644 index 00000000..738b45e3 Binary files /dev/null and b/Hindi_Letter_Classification/Dataset/single_prediction/tset12.png differ