diff --git a/.ipynb_checkpoints/FinalPrediction-checkpoint.ipynb b/.ipynb_checkpoints/FinalPrediction-checkpoint.ipynb new file mode 100644 index 0000000..f992148 --- /dev/null +++ b/.ipynb_checkpoints/FinalPrediction-checkpoint.ipynb @@ -0,0 +1,110 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "id": "bcbffb83", + "metadata": {}, + "outputs": [], + "source": [ + "from keras.models import model_from_json\n", + "import operator\n", + "import cv2" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "75d163ed", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loaded model from disk\n" + ] + } + ], + "source": [ + "json_file = open(\"model-bw.json\", \"r\")\n", + "model_json = json_file.read()\n", + "json_file.close()\n", + "loaded_model = model_from_json(model_json)\n", + "loaded_model.load_weights(\"model-bw.h5\")\n", + "print(\"Loaded model from disk\")\n", + "cap = cv2.VideoCapture(0)\n", + "categories = {0: 'ZERO', 1: 'ONE', 2: 'TWO', 3: 'THREE', 4: 'FOUR', 5: 'FIVE'}" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "51692885", + "metadata": {}, + "outputs": [], + "source": [ + "while True:\n", + " _, frame = cap.read()\n", + " frame = cv2.flip(frame, 1)\n", + " x1 = int(0.5*frame.shape[1])\n", + " y1 = 10\n", + " x2 = frame.shape[1]-10\n", + " y2 = int(0.5*frame.shape[1])\n", + " cv2.putText(frame, \"ElricPi - TDoC 2021\", (175, 450), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (225,255,0), 3)\n", + " cv2.rectangle(frame, (x1-1, y1-1), (x2+1, y2+1), (255,255,255) ,3)\n", + " roi = frame[y1:y2, x1:x2]\n", + " roi = cv2.resize(roi, (64, 64))\n", + " roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)\n", + " cv2.putText(frame, \"R.O.I\", (440, 350), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0,225,0), 3)\n", + " _, test_image = cv2.threshold(roi, 120, 255, cv2.THRESH_BINARY)\n", + " cv2.imshow(\"ROI\", test_image)\n", + " result = loaded_model.predict(test_image.reshape(1, 64, 64, 1))\n", + " prediction = {'ZERO': result[0][0],\n", + " 'ONE': result[0][1],\n", + " 'TWO': result[0][2],\n", + " 'THREE': result[0][3],\n", + " 'FOUR': result[0][4],\n", + " 'FIVE': result[0][5]}\n", + " prediction = sorted(prediction.items(), key=operator.itemgetter(1), reverse=True)\n", + " cv2.putText(frame, \"PREDICTION:\", (30, 90), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2)\n", + " cv2.putText(frame, prediction[0][0], (80, 130), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2)\n", + " cv2.imshow(\"Frame\", frame)\n", + " interrupt = cv2.waitKey(10)\n", + " if interrupt & 0xFF == 27:\n", + " break\n", + "cap.release()\n", + "cv2.destroyAllWindows()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "73bcac5d", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/.ipynb_checkpoints/TrainingOI-checkpoint.ipynb b/.ipynb_checkpoints/TrainingOI-checkpoint.ipynb new file mode 100644 index 0000000..6d1ddfe --- /dev/null +++ b/.ipynb_checkpoints/TrainingOI-checkpoint.ipynb @@ -0,0 +1,137 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "faae96f7", + "metadata": {}, + "outputs": [], + "source": [ + "from keras.models import Sequential\n", + "from keras.layers import Convolution2D, MaxPooling2D, Flatten, Dense\n", + "from keras.preprocessing.image import ImageDataGenerator\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "3c6dab91", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found 865 images belonging to 6 classes.\n", + "Found 30 images belonging to 6 classes.\n", + "Epoch 1/24\n", + "145/145 [==============================] - 6s 33ms/step - loss: 1.8881 - accuracy: 0.3503 - val_loss: 2.0199 - val_accuracy: 0.3667\n", + "Epoch 2/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.7299 - accuracy: 0.7555 - val_loss: 1.9466 - val_accuracy: 0.4000\n", + "Epoch 3/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.4640 - accuracy: 0.8614 - val_loss: 1.6799 - val_accuracy: 0.3667\n", + "Epoch 4/24\n", + "145/145 [==============================] - 4s 25ms/step - loss: 0.4190 - accuracy: 0.8388 - val_loss: 2.0598 - val_accuracy: 0.4333\n", + "Epoch 5/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.2567 - accuracy: 0.9080 - val_loss: 2.2239 - val_accuracy: 0.4000\n", + "Epoch 6/24\n", + "145/145 [==============================] - 4s 25ms/step - loss: 0.2608 - accuracy: 0.9103 - val_loss: 2.7712 - val_accuracy: 0.4333\n", + "Epoch 7/24\n", + "145/145 [==============================] - 4s 25ms/step - loss: 0.2445 - accuracy: 0.9337 - val_loss: 2.1731 - val_accuracy: 0.4667\n", + "Epoch 8/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.1987 - accuracy: 0.9225 - val_loss: 1.8919 - val_accuracy: 0.3667\n", + "Epoch 9/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.1457 - accuracy: 0.9532 - val_loss: 2.4349 - val_accuracy: 0.4000\n", + "Epoch 10/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.0940 - accuracy: 0.9771 - val_loss: 2.3527 - val_accuracy: 0.4333\n", + "Epoch 11/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.1143 - accuracy: 0.9605 - val_loss: 2.4939 - val_accuracy: 0.4333\n", + "Epoch 12/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.1251 - accuracy: 0.9553 - val_loss: 3.1054 - val_accuracy: 0.4333\n", + "Epoch 13/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.1081 - accuracy: 0.9637 - val_loss: 2.7446 - val_accuracy: 0.4667\n", + "Epoch 14/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.1183 - accuracy: 0.9587 - val_loss: 3.0388 - val_accuracy: 0.4333\n", + "Epoch 15/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.1070 - accuracy: 0.9617 - val_loss: 3.1897 - val_accuracy: 0.4667\n", + "Epoch 16/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.0689 - accuracy: 0.9797 - val_loss: 2.7554 - val_accuracy: 0.4333\n", + "Epoch 17/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.1332 - accuracy: 0.9504 - val_loss: 3.6933 - val_accuracy: 0.3333\n", + "Epoch 18/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.0743 - accuracy: 0.9757 - val_loss: 2.9300 - val_accuracy: 0.5333\n", + "Epoch 19/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.0304 - accuracy: 0.9944 - val_loss: 2.6740 - val_accuracy: 0.4333\n", + "Epoch 20/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.0336 - accuracy: 0.9927 - val_loss: 3.8067 - val_accuracy: 0.5000\n", + "Epoch 21/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.0506 - accuracy: 0.9823 - val_loss: 3.4033 - val_accuracy: 0.4333\n", + "Epoch 22/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.0354 - accuracy: 0.9879 - val_loss: 2.9072 - val_accuracy: 0.5000\n", + "Epoch 23/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.0413 - accuracy: 0.9833 - val_loss: 3.5864 - val_accuracy: 0.4667\n", + "Epoch 24/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.0105 - accuracy: 0.9997 - val_loss: 3.6084 - val_accuracy: 0.4333\n" + ] + } + ], + "source": [ + "classifier = Sequential()\n", + "classifier.add(Convolution2D(32, (3, 3), input_shape=(64, 64, 1), activation='tanh'))\n", + "classifier.add(MaxPooling2D(pool_size=(2, 2)))\n", + "classifier.add(Convolution2D(32, (3, 3), activation='tanh'))\n", + "classifier.add(MaxPooling2D(pool_size=(2, 2)))\n", + "classifier.add(Flatten())\n", + "classifier.add(Dense(units=128, activation='tanh'))\n", + "classifier.add(Dense(units=6, activation='softmax'))\n", + "classifier.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])\n", + "\n", + "train_datagen = ImageDataGenerator( rescale=1./255, shear_range=0.2, zoom_range=0.2, horizontal_flip=True)\n", + "\n", + "test_datagen = ImageDataGenerator(rescale=1./255)\n", + "\n", + "training_set = train_datagen.flow_from_directory(r\"C:\\Users\\TISYAGUPTA PYNE\\tdoc21\\data\\train\", target_size=(64, 64), batch_size=6, color_mode='grayscale', class_mode='categorical')\n", + "\n", + "test_set = test_datagen.flow_from_directory(r\"C:\\Users\\TISYAGUPTA PYNE\\tdoc21\\data\\test\", target_size=(64, 64), batch_size=6, color_mode='grayscale', class_mode='categorical')\n", + "\n", + "\n", + "classifier.fit_generator(training_set, epochs=24, validation_data=test_set)\n", + "\n", + "model_json = classifier.to_json()\n", + "\n", + "with open(\"model-bw.json1\", \"w\") as json_file:\n", + " json_file.write(model_json)\n", + "classifier.save_weights('model-bw1.h5')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1ec4a6ae", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/FinalPrediction.ipynb b/FinalPrediction.ipynb new file mode 100644 index 0000000..8705282 --- /dev/null +++ b/FinalPrediction.ipynb @@ -0,0 +1,110 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "id": "bcbffb83", + "metadata": {}, + "outputs": [], + "source": [ + "from keras.models import model_from_json\n", + "import operator\n", + "import cv2" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "75d163ed", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loaded model from disk\n" + ] + } + ], + "source": [ + "json_file = open(\"model-bw1.json\", \"r\")\n", + "model_json = json_file.read()\n", + "json_file.close()\n", + "loaded_model = model_from_json(model_json)\n", + "loaded_model.load_weights(\"model-bw1.h5\")\n", + "print(\"Loaded model from disk\")\n", + "cap = cv2.VideoCapture(0)\n", + "categories = {0: 'ZERO', 1: 'ONE', 2: 'TWO', 3: 'THREE', 4: 'FOUR', 5: 'FIVE'}" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "51692885", + "metadata": {}, + "outputs": [], + "source": [ + "while True:\n", + " _, frame = cap.read()\n", + " frame = cv2.flip(frame, 1)\n", + " x1 = int(0.5*frame.shape[1])\n", + " y1 = 10\n", + " x2 = frame.shape[1]-10\n", + " y2 = int(0.5*frame.shape[1])\n", + " cv2.putText(frame, \"ElricPi - TDoC 2021\", (175, 450), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (225,255,0), 3)\n", + " cv2.rectangle(frame, (x1-1, y1-1), (x2+1, y2+1), (255,255,255) ,3)\n", + " roi = frame[y1:y2, x1:x2]\n", + " roi = cv2.resize(roi, (64, 64))\n", + " roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)\n", + " cv2.putText(frame, \"R.O.I\", (440, 350), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0,225,0), 3)\n", + " _, test_image = cv2.threshold(roi, 120, 255, cv2.THRESH_BINARY)\n", + " cv2.imshow(\"ROI\", test_image)\n", + " result = loaded_model.predict(test_image.reshape(1, 64, 64, 1))\n", + " prediction = {'ZERO': result[0][0],\n", + " 'ONE': result[0][1],\n", + " 'TWO': result[0][2],\n", + " 'THREE': result[0][3],\n", + " 'FOUR': result[0][4],\n", + " 'FIVE': result[0][5]}\n", + " prediction = sorted(prediction.items(), key=operator.itemgetter(1), reverse=True)\n", + " cv2.putText(frame, \"PREDICTION:\", (30, 90), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2)\n", + " cv2.putText(frame, prediction[0][0], (80, 130), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2)\n", + " cv2.imshow(\"Frame\", frame)\n", + " interrupt = cv2.waitKey(10)\n", + " if interrupt & 0xFF == 27:\n", + " break\n", + "cap.release()\n", + "cv2.destroyAllWindows()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "73bcac5d", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Training.ipynb b/Training.ipynb new file mode 100644 index 0000000..bf50fa0 --- /dev/null +++ b/Training.ipynb @@ -0,0 +1,133 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "id": "faae96f7", + "metadata": {}, + "outputs": [], + "source": [ + "from keras.models import Sequential\n", + "from keras.layers import Convolution2D, MaxPooling2D, Flatten, Dense\n", + "from keras.preprocessing.image import ImageDataGenerator\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "3c6dab91", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found 865 images belonging to 6 classes.\n", + "Found 30 images belonging to 6 classes.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\TISYAGUPTA PYNE\\AppData\\Roaming\\Python\\Python38\\site-packages\\keras\\engine\\training.py:1915: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.\n", + " warnings.warn('`Model.fit_generator` is deprecated and '\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Epoch 1/15\n", + "173/173 [==============================] - 46s 99ms/step - loss: 1.5426 - accuracy: 0.3937 - val_loss: 2.6288 - val_accuracy: 0.3667\n", + "Epoch 2/15\n", + "173/173 [==============================] - 4s 23ms/step - loss: 0.6237 - accuracy: 0.7594 - val_loss: 3.2433 - val_accuracy: 0.4333\n", + "Epoch 3/15\n", + "173/173 [==============================] - 4s 23ms/step - loss: 0.3984 - accuracy: 0.8690 - val_loss: 2.6421 - val_accuracy: 0.4333\n", + "Epoch 4/15\n", + "173/173 [==============================] - 4s 22ms/step - loss: 0.2331 - accuracy: 0.9072 - val_loss: 2.8185 - val_accuracy: 0.4000\n", + "Epoch 5/15\n", + "173/173 [==============================] - 4s 22ms/step - loss: 0.1822 - accuracy: 0.9445 - val_loss: 2.6229 - val_accuracy: 0.4667\n", + "Epoch 6/15\n", + "173/173 [==============================] - 4s 22ms/step - loss: 0.1883 - accuracy: 0.9412 - val_loss: 3.8111 - val_accuracy: 0.4333\n", + "Epoch 7/15\n", + "173/173 [==============================] - 4s 22ms/step - loss: 0.1409 - accuracy: 0.9487 - val_loss: 3.9537 - val_accuracy: 0.4000\n", + "Epoch 8/15\n", + "173/173 [==============================] - 4s 22ms/step - loss: 0.0981 - accuracy: 0.9581 - val_loss: 3.5851 - val_accuracy: 0.4667\n", + "Epoch 9/15\n", + "173/173 [==============================] - 4s 25ms/step - loss: 0.0971 - accuracy: 0.9628 - val_loss: 5.1339 - val_accuracy: 0.4333\n", + "Epoch 10/15\n", + "173/173 [==============================] - 873s 5s/step - loss: 0.0483 - accuracy: 0.9832 - val_loss: 4.8346 - val_accuracy: 0.4000\n", + "Epoch 11/15\n", + "173/173 [==============================] - 4s 25ms/step - loss: 0.0962 - accuracy: 0.9754 - val_loss: 3.8186 - val_accuracy: 0.4667\n", + "Epoch 12/15\n", + "173/173 [==============================] - 5s 27ms/step - loss: 0.0616 - accuracy: 0.9820 - val_loss: 7.2040 - val_accuracy: 0.3667\n", + "Epoch 13/15\n", + "173/173 [==============================] - 5s 29ms/step - loss: 0.0353 - accuracy: 0.9867 - val_loss: 8.5210 - val_accuracy: 0.3333\n", + "Epoch 14/15\n", + "173/173 [==============================] - 4s 25ms/step - loss: 0.0627 - accuracy: 0.9833 - val_loss: 5.6981 - val_accuracy: 0.4333\n", + "Epoch 15/15\n", + "173/173 [==============================] - 4s 21ms/step - loss: 0.0612 - accuracy: 0.9791 - val_loss: 6.4923 - val_accuracy: 0.4667\n" + ] + } + ], + "source": [ + "classifier = Sequential()\n", + "classifier.add(Convolution2D(32, (3, 3), input_shape=(64, 64, 1), activation='relu'))\n", + "classifier.add(MaxPooling2D(pool_size=(2, 2)))\n", + "classifier.add(Convolution2D(32, (3, 3), activation='relu'))\n", + "classifier.add(MaxPooling2D(pool_size=(2, 2)))\n", + "classifier.add(Flatten())\n", + "classifier.add(Dense(units=128, activation='relu'))\n", + "classifier.add(Dense(units=6, activation='softmax'))\n", + "classifier.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])\n", + "\n", + "train_datagen = ImageDataGenerator( rescale=1./255, shear_range=0.2, zoom_range=0.2, horizontal_flip=True)\n", + "\n", + "test_datagen = ImageDataGenerator(rescale=1./255)\n", + "\n", + "training_set = train_datagen.flow_from_directory('data/train', target_size=(64, 64), batch_size=5, color_mode='grayscale', class_mode='categorical')\n", + "\n", + "test_set = test_datagen.flow_from_directory('data/test', target_size=(64, 64), batch_size=5, color_mode='grayscale', class_mode='categorical')\n", + "\n", + "\n", + "classifier.fit_generator(training_set, epochs=15, validation_data=test_set)\n", + "\n", + "model_json = classifier.to_json()\n", + "\n", + "with open(\"model-bw.json\", \"w\") as json_file:\n", + " json_file.write(model_json)\n", + "classifier.save_weights('model-bw.h5')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "00da6f2a", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/TrainingOI.ipynb b/TrainingOI.ipynb new file mode 100644 index 0000000..ef1e048 --- /dev/null +++ b/TrainingOI.ipynb @@ -0,0 +1,137 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "faae96f7", + "metadata": {}, + "outputs": [], + "source": [ + "from keras.models import Sequential\n", + "from keras.layers import Convolution2D, MaxPooling2D, Flatten, Dense\n", + "from keras.preprocessing.image import ImageDataGenerator\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "3c6dab91", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found 865 images belonging to 6 classes.\n", + "Found 30 images belonging to 6 classes.\n", + "Epoch 1/24\n", + "145/145 [==============================] - 6s 33ms/step - loss: 1.8881 - accuracy: 0.3503 - val_loss: 2.0199 - val_accuracy: 0.3667\n", + "Epoch 2/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.7299 - accuracy: 0.7555 - val_loss: 1.9466 - val_accuracy: 0.4000\n", + "Epoch 3/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.4640 - accuracy: 0.8614 - val_loss: 1.6799 - val_accuracy: 0.3667\n", + "Epoch 4/24\n", + "145/145 [==============================] - 4s 25ms/step - loss: 0.4190 - accuracy: 0.8388 - val_loss: 2.0598 - val_accuracy: 0.4333\n", + "Epoch 5/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.2567 - accuracy: 0.9080 - val_loss: 2.2239 - val_accuracy: 0.4000\n", + "Epoch 6/24\n", + "145/145 [==============================] - 4s 25ms/step - loss: 0.2608 - accuracy: 0.9103 - val_loss: 2.7712 - val_accuracy: 0.4333\n", + "Epoch 7/24\n", + "145/145 [==============================] - 4s 25ms/step - loss: 0.2445 - accuracy: 0.9337 - val_loss: 2.1731 - val_accuracy: 0.4667\n", + "Epoch 8/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.1987 - accuracy: 0.9225 - val_loss: 1.8919 - val_accuracy: 0.3667\n", + "Epoch 9/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.1457 - accuracy: 0.9532 - val_loss: 2.4349 - val_accuracy: 0.4000\n", + "Epoch 10/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.0940 - accuracy: 0.9771 - val_loss: 2.3527 - val_accuracy: 0.4333\n", + "Epoch 11/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.1143 - accuracy: 0.9605 - val_loss: 2.4939 - val_accuracy: 0.4333\n", + "Epoch 12/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.1251 - accuracy: 0.9553 - val_loss: 3.1054 - val_accuracy: 0.4333\n", + "Epoch 13/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.1081 - accuracy: 0.9637 - val_loss: 2.7446 - val_accuracy: 0.4667\n", + "Epoch 14/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.1183 - accuracy: 0.9587 - val_loss: 3.0388 - val_accuracy: 0.4333\n", + "Epoch 15/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.1070 - accuracy: 0.9617 - val_loss: 3.1897 - val_accuracy: 0.4667\n", + "Epoch 16/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.0689 - accuracy: 0.9797 - val_loss: 2.7554 - val_accuracy: 0.4333\n", + "Epoch 17/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.1332 - accuracy: 0.9504 - val_loss: 3.6933 - val_accuracy: 0.3333\n", + "Epoch 18/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.0743 - accuracy: 0.9757 - val_loss: 2.9300 - val_accuracy: 0.5333\n", + "Epoch 19/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.0304 - accuracy: 0.9944 - val_loss: 2.6740 - val_accuracy: 0.4333\n", + "Epoch 20/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.0336 - accuracy: 0.9927 - val_loss: 3.8067 - val_accuracy: 0.5000\n", + "Epoch 21/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.0506 - accuracy: 0.9823 - val_loss: 3.4033 - val_accuracy: 0.4333\n", + "Epoch 22/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.0354 - accuracy: 0.9879 - val_loss: 2.9072 - val_accuracy: 0.5000\n", + "Epoch 23/24\n", + "145/145 [==============================] - 4s 26ms/step - loss: 0.0413 - accuracy: 0.9833 - val_loss: 3.5864 - val_accuracy: 0.4667\n", + "Epoch 24/24\n", + "145/145 [==============================] - 4s 27ms/step - loss: 0.0105 - accuracy: 0.9997 - val_loss: 3.6084 - val_accuracy: 0.4333\n" + ] + } + ], + "source": [ + "classifier = Sequential()\n", + "classifier.add(Convolution2D(32, (3, 3), input_shape=(64, 64, 1), activation='tanh'))\n", + "classifier.add(MaxPooling2D(pool_size=(2, 2)))\n", + "classifier.add(Convolution2D(32, (3, 3), activation='tanh'))\n", + "classifier.add(MaxPooling2D(pool_size=(2, 2)))\n", + "classifier.add(Flatten())\n", + "classifier.add(Dense(units=128, activation='tanh'))\n", + "classifier.add(Dense(units=6, activation='softmax'))\n", + "classifier.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])\n", + "\n", + "train_datagen = ImageDataGenerator( rescale=1./255, shear_range=0.2, zoom_range=0.2, horizontal_flip=True)\n", + "\n", + "test_datagen = ImageDataGenerator(rescale=1./255)\n", + "\n", + "training_set = train_datagen.flow_from_directory(r\"C:\\Users\\TISYAGUPTA PYNE\\tdoc21\\data\\train\", target_size=(64, 64), batch_size=6, color_mode='grayscale', class_mode='categorical')\n", + "\n", + "test_set = test_datagen.flow_from_directory(r\"C:\\Users\\TISYAGUPTA PYNE\\tdoc21\\data\\test\", target_size=(64, 64), batch_size=6, color_mode='grayscale', class_mode='categorical')\n", + "\n", + "\n", + "classifier.fit_generator(training_set, epochs=24, validation_data=test_set)\n", + "\n", + "model_json = classifier.to_json()\n", + "\n", + "with open(\"model-bw1.json\", \"w\") as json_file:\n", + " json_file.write(model_json)\n", + "classifier.save_weights('model-bw1.h5')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1ec4a6ae", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/model-bw.h5 b/model-bw.h5 new file mode 100644 index 0000000..2db2413 Binary files /dev/null and b/model-bw.h5 differ diff --git a/model-bw.json b/model-bw.json new file mode 100644 index 0000000..4e3005c --- /dev/null +++ b/model-bw.json @@ -0,0 +1 @@ +{"class_name": "Sequential", "config": {"name": "sequential_1", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": [null, 64, 64, 1], "dtype": "float32", "sparse": false, "ragged": false, "name": "conv2d_2_input"}}, {"class_name": "Conv2D", "config": {"name": "conv2d_2", "trainable": true, "batch_input_shape": [null, 64, 64, 1], "dtype": "float32", "filters": 32, "kernel_size": [3, 3], "strides": [1, 1], "padding": "valid", "data_format": "channels_last", "dilation_rate": [1, 1], "groups": 1, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "MaxPooling2D", "config": {"name": "max_pooling2d_2", "trainable": true, "dtype": "float32", "pool_size": [2, 2], "padding": "valid", "strides": [2, 2], "data_format": "channels_last"}}, {"class_name": "Conv2D", "config": {"name": "conv2d_3", "trainable": true, "dtype": "float32", "filters": 32, "kernel_size": [3, 3], "strides": [1, 1], "padding": "valid", "data_format": "channels_last", "dilation_rate": [1, 1], "groups": 1, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "MaxPooling2D", "config": {"name": "max_pooling2d_3", "trainable": true, "dtype": "float32", "pool_size": [2, 2], "padding": "valid", "strides": [2, 2], "data_format": "channels_last"}}, {"class_name": "Flatten", "config": {"name": "flatten_1", "trainable": true, "dtype": "float32", "data_format": "channels_last"}}, {"class_name": "Dense", "config": {"name": "dense_2", "trainable": true, "dtype": "float32", "units": 128, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dense", "config": {"name": "dense_3", "trainable": true, "dtype": "float32", "units": 6, "activation": "softmax", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}]}, "keras_version": "2.5.0", "backend": "tensorflow"} \ No newline at end of file diff --git a/model-bw.json1 b/model-bw.json1 new file mode 100644 index 0000000..1b5f7db --- /dev/null +++ b/model-bw.json1 @@ -0,0 +1 @@ +{"class_name": "Sequential", "config": {"name": "sequential_2", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": [null, 64, 64, 1], "dtype": "float32", "sparse": false, "ragged": false, "name": "conv2d_4_input"}}, {"class_name": "Conv2D", "config": {"name": "conv2d_4", "trainable": true, "batch_input_shape": [null, 64, 64, 1], "dtype": "float32", "filters": 32, "kernel_size": [3, 3], "strides": [1, 1], "padding": "valid", "data_format": "channels_last", "dilation_rate": [1, 1], "groups": 1, "activation": "tanh", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "MaxPooling2D", "config": {"name": "max_pooling2d_4", "trainable": true, "dtype": "float32", "pool_size": [2, 2], "padding": "valid", "strides": [2, 2], "data_format": "channels_last"}}, {"class_name": "Conv2D", "config": {"name": "conv2d_5", "trainable": true, "dtype": "float32", "filters": 32, "kernel_size": [3, 3], "strides": [1, 1], "padding": "valid", "data_format": "channels_last", "dilation_rate": [1, 1], "groups": 1, "activation": "tanh", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "MaxPooling2D", "config": {"name": "max_pooling2d_5", "trainable": true, "dtype": "float32", "pool_size": [2, 2], "padding": "valid", "strides": [2, 2], "data_format": "channels_last"}}, {"class_name": "Flatten", "config": {"name": "flatten_2", "trainable": true, "dtype": "float32", "data_format": "channels_last"}}, {"class_name": "Dense", "config": {"name": "dense_4", "trainable": true, "dtype": "float32", "units": 128, "activation": "tanh", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dense", "config": {"name": "dense_5", "trainable": true, "dtype": "float32", "units": 6, "activation": "softmax", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}]}, "keras_version": "2.5.0", "backend": "tensorflow"} \ No newline at end of file diff --git a/model-bw1.h5 b/model-bw1.h5 new file mode 100644 index 0000000..aed6b9b Binary files /dev/null and b/model-bw1.h5 differ