noshot 11.0.0__py3-none-any.whl → 13.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. noshot/data/DLE FSD BDA/DLE/DLE 1 (Json)/1. DNN (Image Classification).ipynb +389 -0
  2. noshot/data/DLE FSD BDA/DLE/DLE 1 (Json)/2. DNN vs CNN.ipynb +516 -0
  3. noshot/data/DLE FSD BDA/DLE/DLE 1 (Json)/3. CNN (Object Detecrion).ipynb +259 -0
  4. noshot/data/DLE FSD BDA/DLE/DLE 1 (Json)/4. FCN (Image Segmentaion).ipynb +274 -0
  5. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/1.1 DNN (Pytorch).ipynb +164 -0
  6. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/1.2 DNN (Tensorflow).ipynb +94 -0
  7. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/1.3 DNN (Image Classification).ipynb +134 -0
  8. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/2.1 DNN vs CNN.ipynb +127 -0
  9. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/2.2 DNN vs CNN.ipynb +123 -0
  10. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/4. FCNN (Image Segmentation).ipynb +108 -0
  11. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/Lab Excercise (Training DNN).ipynb +646 -0
  12. noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/Load-Images.ipynb +553 -0
  13. noshot/data/DLE FSD BDA/DLE/DLE 3 (sonic boy)/Ex1.ipynb +216 -0
  14. noshot/data/DLE FSD BDA/DLE/DLE 3 (sonic boy)/Ex2.ipynb +195 -0
  15. noshot/data/DLE FSD BDA/DLE/DLE 3 (sonic boy)/Ex3.ipynb +427 -0
  16. noshot/data/DLE FSD BDA/DLE/DLE 3 (sonic boy)/Ex4.ipynb +186 -0
  17. noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp01/DNN Ex No 1.ipynb +398 -0
  18. noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp01/Ex No 1 Build in dataset.ipynb +171 -0
  19. noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp01/Exp1-Short-DL_ANN_ImageClassification.ipynb +401 -0
  20. noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp01/OR GATE .ipynb +8511 -0
  21. noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp02/Exp2-Short-DL_CNN_ImageClassification.ipynb +737 -0
  22. noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp03/DL-Ex3-RNN.ipynb +591 -0
  23. noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp04/Ex no 4.ipynb +551 -0
  24. noshot/main.py +3 -3
  25. {noshot-11.0.0.dist-info → noshot-13.0.0.dist-info}/METADATA +1 -1
  26. noshot-13.0.0.dist-info/RECORD +32 -0
  27. noshot/data/ML TS XAI/ML/CNN(Image_for_Folders_5).ipynb +0 -201
  28. noshot/data/ML TS XAI/ML/CNN(Image_form_Folder_2).ipynb +0 -201
  29. noshot/data/ML TS XAI/ML/Json Codes/ML LAB CIA 2.ipynb +0 -409
  30. noshot/data/ML TS XAI/ML/ML 1/1. EDA-PCA (Balance Scale Dataset).ipynb +0 -147
  31. noshot/data/ML TS XAI/ML/ML 1/1. EDA-PCA (Rice Dataset).ipynb +0 -181
  32. noshot/data/ML TS XAI/ML/ML 1/10. HMM Veterbi.ipynb +0 -152
  33. noshot/data/ML TS XAI/ML/ML 1/2. KNN (Balance Scale Dataset).ipynb +0 -117
  34. noshot/data/ML TS XAI/ML/ML 1/2. KNN (Iris Dataset).ipynb +0 -156
  35. noshot/data/ML TS XAI/ML/ML 1/2. KNN (Sobar-72 Dataset).ipynb +0 -215
  36. noshot/data/ML TS XAI/ML/ML 1/3. LDA (Balance Scale Dataset).ipynb +0 -78
  37. noshot/data/ML TS XAI/ML/ML 1/3. LDA (NPHA Doctor Visits Dataset).ipynb +0 -114
  38. noshot/data/ML TS XAI/ML/ML 1/4. Linear Regression (Machine Dataset).ipynb +0 -115
  39. noshot/data/ML TS XAI/ML/ML 1/4. Linear Regression (Real Estate Dataset).ipynb +0 -146
  40. noshot/data/ML TS XAI/ML/ML 1/5. Logistic Regression (Magic04 Dataset).ipynb +0 -130
  41. noshot/data/ML TS XAI/ML/ML 1/5. Logistic Regression (Wine Dataset).ipynb +0 -112
  42. noshot/data/ML TS XAI/ML/ML 1/6. Naive Bayes Classifier (Agaricus Lepiota Dataset).ipynb +0 -118
  43. noshot/data/ML TS XAI/ML/ML 1/6. Naive Bayes Classifier (Wine Dataset).ipynb +0 -89
  44. noshot/data/ML TS XAI/ML/ML 1/7. SVM (Rice Dataset).ipynb +0 -120
  45. noshot/data/ML TS XAI/ML/ML 1/8. FeedForward NN (Sobar72 Dataset).ipynb +0 -262
  46. noshot/data/ML TS XAI/ML/ML 1/9. CNN (Cifar10 Dataset).ipynb +0 -156
  47. noshot/data/ML TS XAI/ML/ML 2/1. PCA.ipynb +0 -162
  48. noshot/data/ML TS XAI/ML/ML 2/10. CNN.ipynb +0 -100
  49. noshot/data/ML TS XAI/ML/ML 2/11. HMM.ipynb +0 -336
  50. noshot/data/ML TS XAI/ML/ML 2/2. KNN.ipynb +0 -149
  51. noshot/data/ML TS XAI/ML/ML 2/3. LDA.ipynb +0 -132
  52. noshot/data/ML TS XAI/ML/ML 2/4. Linear Regression.ipynb +0 -86
  53. noshot/data/ML TS XAI/ML/ML 2/5. Logistic Regression.ipynb +0 -115
  54. noshot/data/ML TS XAI/ML/ML 2/6. Naive Bayes (Titanic).ipynb +0 -196
  55. noshot/data/ML TS XAI/ML/ML 2/6. Naive Bayes (Wine).ipynb +0 -98
  56. noshot/data/ML TS XAI/ML/ML 2/7. SVM Linear.ipynb +0 -109
  57. noshot/data/ML TS XAI/ML/ML 2/8. SVM Non-Linear.ipynb +0 -195
  58. noshot/data/ML TS XAI/ML/ML 2/9. FNN With Regularization.ipynb +0 -189
  59. noshot/data/ML TS XAI/ML/ML 2/9. FNN Without Regularization.ipynb +0 -197
  60. noshot/data/ML TS XAI/ML/ML 2/All in One Lab CIA 1 Q.ipynb +0 -1087
  61. noshot/data/ML TS XAI/ML/ML 3 (Latest)/1. PCA EDA.ipynb +0 -274
  62. noshot/data/ML TS XAI/ML/ML 3 (Latest)/10. CNN.ipynb +0 -170
  63. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM 2.ipynb +0 -1087
  64. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM 3.ipynb +0 -178
  65. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM 4.ipynb +0 -185
  66. noshot/data/ML TS XAI/ML/ML 3 (Latest)/11. HMM.ipynb +0 -106
  67. noshot/data/ML TS XAI/ML/ML 3 (Latest)/2. KNN.ipynb +0 -177
  68. noshot/data/ML TS XAI/ML/ML 3 (Latest)/3. LDA.ipynb +0 -195
  69. noshot/data/ML TS XAI/ML/ML 3 (Latest)/4. Linear Regression.ipynb +0 -267
  70. noshot/data/ML TS XAI/ML/ML 3 (Latest)/5. Logistic Regression.ipynb +0 -104
  71. noshot/data/ML TS XAI/ML/ML 3 (Latest)/6. Bayesian Classifier.ipynb +0 -109
  72. noshot/data/ML TS XAI/ML/ML 3 (Latest)/7. SVM.ipynb +0 -220
  73. noshot/data/ML TS XAI/ML/ML 3 (Latest)/8. MLP.ipynb +0 -99
  74. noshot/data/ML TS XAI/ML/ML 3 (Latest)/9. Ridge - Lasso.ipynb +0 -211
  75. noshot/data/ML TS XAI/ML/ML 3 (Latest)/9. Ridge Lasso 2.ipynb +0 -99
  76. noshot/data/ML TS XAI/ML/ML 3 (Latest)/Image Load Example.ipynb +0 -118
  77. noshot/data/ML TS XAI/ML/ML 3 (Latest)/Updated_Untitled.ipynb +0 -603
  78. noshot/data/ML TS XAI/ML/ML Lab AllinOne.ipynb +0 -961
  79. noshot/data/ML TS XAI/ML/ML Lab H Sec/1. Iris Dataset (Softmax vs Sigmoid).ipynb +0 -231
  80. noshot/data/ML TS XAI/ML/ML Lab H Sec/2. Student Dataset (Overfit vs Regularized).ipynb +0 -269
  81. noshot/data/ML TS XAI/ML/ML Lab H Sec/3. Insurance Target Categorical (Overfit vs Regularized).ipynb +0 -274
  82. noshot/data/ML TS XAI/ML/ML Lab H Sec/3. Insurance Target Numerical (Overfit vs Regularized).ipynb +0 -263
  83. noshot/data/ML TS XAI/ML/ML Lab H Sec/4. Smart House System HMM.ipynb +0 -198
  84. noshot/data/ML TS XAI/ML/ML Lab H Sec/5. Fraud Detection System HMM.ipynb +0 -201
  85. noshot/data/ML TS XAI/ML/ML Lab H Sec/insurance.csv +0 -1339
  86. noshot/data/ML TS XAI/ML/ML Lab H Sec/iris1.data +0 -151
  87. noshot/data/ML TS XAI/ML/ML Lab H Sec/student-mat.csv +0 -396
  88. noshot/data/ML TS XAI/ML/ML Lab H Sec/student-por.csv +0 -650
  89. noshot/data/ML TS XAI/ML/Rolls Royce AllinOne.ipynb +0 -691
  90. noshot-11.0.0.dist-info/RECORD +0 -72
  91. {noshot-11.0.0.dist-info → noshot-13.0.0.dist-info}/WHEEL +0 -0
  92. {noshot-11.0.0.dist-info → noshot-13.0.0.dist-info}/licenses/LICENSE.txt +0 -0
  93. {noshot-11.0.0.dist-info → noshot-13.0.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,94 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "272ad344-26ac-46a9-887a-823bc177175e",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import os\n",
11
+ "import numpy as np\n",
12
+ "from sklearn.model_selection import train_test_split\n",
13
+ "from sklearn.metrics import classification_report, confusion_matrix\n",
14
+ "import matplotlib.pyplot as plt\n",
15
+ "import tensorflow as tf\n",
16
+ "from tensorflow.keras.preprocessing.image import load_img, img_to_array\n",
17
+ "from tensorflow.keras.models import Sequential\n",
18
+ "from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense\n",
19
+ "\n",
20
+ "dataset_path = \"<filepath>\"\n",
21
+ "IMG_SIZE = (128, 128)\n",
22
+ "\n",
23
+ "def load_images(folder_path, image_size=IMG_SIZE):\n",
24
+ " images, labels, class_names = [], [], sorted(os.listdir(folder_path))\n",
25
+ " for label, class_name in enumerate(class_names):\n",
26
+ " class_dir = os.path.join(folder_path, class_name)\n",
27
+ " for file in os.listdir(class_dir):\n",
28
+ " img = load_img(os.path.join(class_dir, file), target_size=image_size)\n",
29
+ " images.append(img_to_array(img)/255.0)\n",
30
+ " labels.append(label)\n",
31
+ " return np.array(images), np.array(labels), class_names\n",
32
+ "\n",
33
+ "X, y, class_names = load_images(dataset_path)\n",
34
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
35
+ "\n",
36
+ "model = Sequential([\n",
37
+ " Conv2D(32, (3,3), activation='relu', input_shape=(*IMG_SIZE,3)),\n",
38
+ " MaxPooling2D(2,2),\n",
39
+ " Conv2D(64, (3,3), activation='relu'),\n",
40
+ " MaxPooling2D(2,2),\n",
41
+ " Flatten(),\n",
42
+ " Dense(128, activation='relu'),\n",
43
+ " Dense(len(class_names), activation='softmax')\n",
44
+ "])\n",
45
+ "\n",
46
+ "model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])\n",
47
+ "history = model.fit(X_train, y_train, validation_split=0.2, epochs=10, batch_size=32)\n",
48
+ "\n",
49
+ "test_loss, test_acc = model.evaluate(X_test, y_test)\n",
50
+ "print(f\"Test Accuracy: {test_acc*100:.2f}%\")\n",
51
+ "\n",
52
+ "y_pred = np.argmax(model.predict(X_test), axis=-1)\n",
53
+ "print(\"Classification Report:\")\n",
54
+ "print(classification_report(y_test, y_pred, target_names=class_names))\n",
55
+ "print(\"Confusion Matrix:\")\n",
56
+ "print(confusion_matrix(y_test, y_pred))\n",
57
+ "\n",
58
+ "plt.figure(figsize=(12,4))\n",
59
+ "plt.subplot(1,2,1)\n",
60
+ "plt.plot(history.history['accuracy'], label='Train Accuracy')\n",
61
+ "plt.plot(history.history['val_accuracy'], label='Val Accuracy')\n",
62
+ "plt.title('Accuracy')\n",
63
+ "plt.legend()\n",
64
+ "plt.subplot(1,2,2)\n",
65
+ "plt.plot(history.history['loss'], label='Train Loss')\n",
66
+ "plt.plot(history.history['val_loss'], label='Val Loss')\n",
67
+ "plt.title('Loss')\n",
68
+ "plt.legend()\n",
69
+ "plt.show()"
70
+ ]
71
+ }
72
+ ],
73
+ "metadata": {
74
+ "kernelspec": {
75
+ "display_name": "Python 3 (ipykernel)",
76
+ "language": "python",
77
+ "name": "python3"
78
+ },
79
+ "language_info": {
80
+ "codemirror_mode": {
81
+ "name": "ipython",
82
+ "version": 3
83
+ },
84
+ "file_extension": ".py",
85
+ "mimetype": "text/x-python",
86
+ "name": "python",
87
+ "nbconvert_exporter": "python",
88
+ "pygments_lexer": "ipython3",
89
+ "version": "3.12.4"
90
+ }
91
+ },
92
+ "nbformat": 4,
93
+ "nbformat_minor": 5
94
+ }
@@ -0,0 +1,134 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "8e5e0508-ead9-401c-bb0a-98e48722c959",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import torch\n",
11
+ "import torch.nn as nn\n",
12
+ "import torch.nn.functional as F\n",
13
+ "import torch.optim as optim\n",
14
+ "from torchvision import datasets, transforms\n",
15
+ "from torch.utils.data import DataLoader\n",
16
+ "from sklearn.metrics import confusion_matrix, precision_score, recall_score, f1_score\n",
17
+ "import matplotlib.pyplot as plt\n",
18
+ "import seaborn as sns\n",
19
+ "\n",
20
+ "data_transforms = transforms.Compose([\n",
21
+ " transforms.Resize(256),\n",
22
+ " transforms.CenterCrop(224),\n",
23
+ " transforms.ToTensor(),\n",
24
+ " transforms.Normalize(mean=[0.485, 0.456, 0.406],\n",
25
+ " std=[0.229, 0.224, 0.225])\n",
26
+ "])\n",
27
+ "\n",
28
+ "data_dir = \"dataset\"\n",
29
+ "image_dataset = datasets.ImageFolder(root=data_dir, transform=data_transforms)\n",
30
+ "batch_size = 32\n",
31
+ "dataloader = DataLoader(image_dataset, batch_size=batch_size, shuffle=True)\n",
32
+ "\n",
33
+ "class FeedforwardNet(nn.Module):\n",
34
+ " def __init__(self, input_size, num_classes):\n",
35
+ " super(FeedforwardNet, self).__init__()\n",
36
+ " self.fc1 = nn.Linear(input_size, 512)\n",
37
+ " self.fc2 = nn.Linear(512, 256)\n",
38
+ " self.fc3 = nn.Linear(256, num_classes)\n",
39
+ " self.relu = nn.ReLU()\n",
40
+ "\n",
41
+ " def forward(self, x):\n",
42
+ " x = x.view(x.size(0), -1)\n",
43
+ " x = self.relu(self.fc1(x))\n",
44
+ " x = self.relu(self.fc2(x))\n",
45
+ " x = self.fc3(x)\n",
46
+ " return x\n",
47
+ "\n",
48
+ "input_size = 224 * 224 * 3\n",
49
+ "num_classes = len(image_dataset.classes)\n",
50
+ "model = FeedforwardNet(input_size, num_classes)\n",
51
+ "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
52
+ "model.to(device)\n",
53
+ "criterion = nn.CrossEntropyLoss()\n",
54
+ "optimizer = optim.Adam(model.parameters(), lr=0.001)\n",
55
+ "num_epochs = 10\n",
56
+ "\n",
57
+ "for epoch in range(num_epochs):\n",
58
+ " model.train()\n",
59
+ " running_loss = 0.0\n",
60
+ " for images, labels in dataloader:\n",
61
+ " images, labels = images.to(device), labels.to(device)\n",
62
+ " outputs = model(images)\n",
63
+ " loss = criterion(outputs, labels)\n",
64
+ " optimizer.zero_grad()\n",
65
+ " loss.backward()\n",
66
+ " optimizer.step()\n",
67
+ " running_loss += loss.item() * images.size(0)\n",
68
+ " epoch_loss = running_loss / len(image_dataset)\n",
69
+ " print(f\"Epoch [{epoch+1}/{num_epochs}], Loss: {epoch_loss:.4f}\")\n",
70
+ "\n",
71
+ "model.eval()\n",
72
+ "with torch.no_grad():\n",
73
+ " correct = 0\n",
74
+ " total = 0\n",
75
+ " for images, labels in dataloader:\n",
76
+ " images, labels = images.to(device), labels.to(device)\n",
77
+ " outputs = model(images)\n",
78
+ " _, predicted = torch.max(outputs.data, 1)\n",
79
+ " total += labels.size(0)\n",
80
+ " correct += (predicted == labels).sum().item()\n",
81
+ " accuracy = 100 * correct / total\n",
82
+ "print(f\"Accuracy of the model on {total} images: {accuracy:.2f}%\")\n",
83
+ "\n",
84
+ "true_labels = []\n",
85
+ "predicted_labels = []\n",
86
+ "with torch.no_grad():\n",
87
+ " for images, labels in dataloader:\n",
88
+ " images, labels = images.to(device), labels.to(device)\n",
89
+ " outputs = model(images)\n",
90
+ " _, predicted = torch.max(outputs.data, 1)\n",
91
+ " true_labels.extend(labels.cpu().numpy())\n",
92
+ " predicted_labels.extend(predicted.cpu().numpy())\n",
93
+ "\n",
94
+ "precision = precision_score(true_labels, predicted_labels, average='weighted')\n",
95
+ "recall = recall_score(true_labels, predicted_labels, average='weighted')\n",
96
+ "f1 = f1_score(true_labels, predicted_labels, average='weighted')\n",
97
+ "print(f\"Precision: {precision:.4f}\")\n",
98
+ "print(f\"Recall: {recall:.4f}\")\n",
99
+ "print(f\"F1-score: {f1:.4f}\")\n",
100
+ "\n",
101
+ "cm = confusion_matrix(true_labels, predicted_labels)\n",
102
+ "plt.figure(figsize=(8, 6))\n",
103
+ "sns.heatmap(cm, annot=True, fmt='d', cmap='Blues',\n",
104
+ " xticklabels=image_dataset.classes,\n",
105
+ " yticklabels=image_dataset.classes)\n",
106
+ "plt.xlabel('Predicted Labels')\n",
107
+ "plt.ylabel('True Labels')\n",
108
+ "plt.title('Confusion Matrix')\n",
109
+ "plt.show()"
110
+ ]
111
+ }
112
+ ],
113
+ "metadata": {
114
+ "kernelspec": {
115
+ "display_name": "Python 3 (ipykernel)",
116
+ "language": "python",
117
+ "name": "python3"
118
+ },
119
+ "language_info": {
120
+ "codemirror_mode": {
121
+ "name": "ipython",
122
+ "version": 3
123
+ },
124
+ "file_extension": ".py",
125
+ "mimetype": "text/x-python",
126
+ "name": "python",
127
+ "nbconvert_exporter": "python",
128
+ "pygments_lexer": "ipython3",
129
+ "version": "3.12.4"
130
+ }
131
+ },
132
+ "nbformat": 4,
133
+ "nbformat_minor": 5
134
+ }
@@ -0,0 +1,127 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "335957c2-a530-4a12-8b04-1475513e138f",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import numpy as np\n",
11
+ "import tensorflow as tf\n",
12
+ "from tensorflow.keras.preprocessing.image import ImageDataGenerator\n",
13
+ "from tensorflow.keras.models import Sequential\n",
14
+ "from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D, Dropout\n",
15
+ "from tensorflow.keras.optimizers import Adam\n",
16
+ "import matplotlib.pyplot as plt\n",
17
+ "\n",
18
+ "data_dir = \"Bean_Dataset/Bean_Dataset\"\n",
19
+ "img_height, img_width = 128, 128\n",
20
+ "batch_size = 32\n",
21
+ "\n",
22
+ "datagen = ImageDataGenerator(\n",
23
+ " rescale=1./255,\n",
24
+ " validation_split=0.2,\n",
25
+ " rotation_range=20,\n",
26
+ " width_shift_range=0.2,\n",
27
+ " height_shift_range=0.2,\n",
28
+ " shear_range=0.2,\n",
29
+ " zoom_range=0.2,\n",
30
+ " horizontal_flip=True\n",
31
+ ")\n",
32
+ "\n",
33
+ "train_gen = datagen.flow_from_directory(\n",
34
+ " data_dir, target_size=(img_height, img_width),\n",
35
+ " batch_size=batch_size, class_mode='categorical', subset='training'\n",
36
+ ")\n",
37
+ "\n",
38
+ "val_gen = datagen.flow_from_directory(\n",
39
+ " data_dir, target_size=(img_height, img_width),\n",
40
+ " batch_size=batch_size, class_mode='categorical', subset='validation'\n",
41
+ ")\n",
42
+ "\n",
43
+ "num_classes = len(train_gen.class_indices)\n",
44
+ "\n",
45
+ "def build_dnn():\n",
46
+ " model = Sequential([\n",
47
+ " Flatten(input_shape=(img_height, img_width, 3)),\n",
48
+ " Dense(512, activation='relu'),\n",
49
+ " Dropout(0.5),\n",
50
+ " Dense(256, activation='relu'),\n",
51
+ " Dropout(0.5),\n",
52
+ " Dense(num_classes, activation='softmax')\n",
53
+ " ])\n",
54
+ " model.compile(optimizer=Adam(), loss='categorical_crossentropy', metrics=['accuracy'])\n",
55
+ " return model\n",
56
+ "\n",
57
+ "def build_cnn():\n",
58
+ " model = Sequential([\n",
59
+ " Conv2D(32, (3,3), activation='relu', input_shape=(img_height, img_width, 3)),\n",
60
+ " MaxPooling2D(2,2),\n",
61
+ " Conv2D(64, (3,3), activation='relu'),\n",
62
+ " MaxPooling2D(2,2),\n",
63
+ " Conv2D(128, (3,3), activation='relu'),\n",
64
+ " MaxPooling2D(2,2),\n",
65
+ " Flatten(),\n",
66
+ " Dense(512, activation='relu'),\n",
67
+ " Dropout(0.5),\n",
68
+ " Dense(num_classes, activation='softmax')\n",
69
+ " ])\n",
70
+ " model.compile(optimizer=Adam(), loss='categorical_crossentropy', metrics=['accuracy'])\n",
71
+ " return model\n",
72
+ "\n",
73
+ "dnn_model = build_dnn()\n",
74
+ "dnn_history = dnn_model.fit(train_gen, epochs=20, validation_data=val_gen)\n",
75
+ "\n",
76
+ "cnn_model = build_cnn()\n",
77
+ "cnn_history = cnn_model.fit(train_gen, epochs=20, validation_data=val_gen)\n",
78
+ "\n",
79
+ "plt.figure(figsize=(12,5))\n",
80
+ "plt.subplot(1,2,1)\n",
81
+ "plt.plot(dnn_history.history['accuracy'], label='DNN Train')\n",
82
+ "plt.plot(dnn_history.history['val_accuracy'], label='DNN Val')\n",
83
+ "plt.plot(cnn_history.history['accuracy'], label='CNN Train')\n",
84
+ "plt.plot(cnn_history.history['val_accuracy'], label='CNN Val')\n",
85
+ "plt.title('Accuracy')\n",
86
+ "plt.xlabel('Epoch')\n",
87
+ "plt.ylabel('Accuracy')\n",
88
+ "plt.legend()\n",
89
+ "\n",
90
+ "plt.subplot(1,2,2)\n",
91
+ "plt.plot(dnn_history.history['loss'], label='DNN Train')\n",
92
+ "plt.plot(dnn_history.history['val_loss'], label='DNN Val')\n",
93
+ "plt.plot(cnn_history.history['loss'], label='CNN Train')\n",
94
+ "plt.plot(cnn_history.history['val_loss'], label='CNN Val')\n",
95
+ "plt.title('Loss')\n",
96
+ "plt.xlabel('Epoch')\n",
97
+ "plt.ylabel('Loss')\n",
98
+ "plt.legend()\n",
99
+ "plt.show()\n",
100
+ "\n",
101
+ "print(f\"DNN Train Acc: {dnn_history.history['accuracy'][-1]:.4f}, Val Acc: {dnn_history.history['val_accuracy'][-1]:.4f}\")\n",
102
+ "print(f\"CNN Train Acc: {cnn_history.history['accuracy'][-1]:.4f}, Val Acc: {cnn_history.history['val_accuracy'][-1]:.4f}\")"
103
+ ]
104
+ }
105
+ ],
106
+ "metadata": {
107
+ "kernelspec": {
108
+ "display_name": "Python 3 (ipykernel)",
109
+ "language": "python",
110
+ "name": "python3"
111
+ },
112
+ "language_info": {
113
+ "codemirror_mode": {
114
+ "name": "ipython",
115
+ "version": 3
116
+ },
117
+ "file_extension": ".py",
118
+ "mimetype": "text/x-python",
119
+ "name": "python",
120
+ "nbconvert_exporter": "python",
121
+ "pygments_lexer": "ipython3",
122
+ "version": "3.12.4"
123
+ }
124
+ },
125
+ "nbformat": 4,
126
+ "nbformat_minor": 5
127
+ }
@@ -0,0 +1,123 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "e859c172-a86c-4cdf-93e3-7c24a9dd3292",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import tensorflow as tf\n",
11
+ "from tensorflow.keras.preprocessing.image import ImageDataGenerator\n",
12
+ "from tensorflow.keras.models import Sequential\n",
13
+ "from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D, Dropout\n",
14
+ "from tensorflow.keras.optimizers import Adam\n",
15
+ "import matplotlib.pyplot as plt\n",
16
+ "import pandas as pd\n",
17
+ "\n",
18
+ "data_dir = \"Bean_Dataset/Bean_Dataset\"\n",
19
+ "img_height, img_width = 128, 128\n",
20
+ "batch_size = 32\n",
21
+ "\n",
22
+ "datagen = ImageDataGenerator(rescale=1./255, validation_split=0.2)\n",
23
+ "\n",
24
+ "train_gen = datagen.flow_from_directory(\n",
25
+ " data_dir, target_size=(img_height, img_width),\n",
26
+ " batch_size=batch_size, class_mode='categorical', subset='training'\n",
27
+ ")\n",
28
+ "\n",
29
+ "val_gen = datagen.flow_from_directory(\n",
30
+ " data_dir, target_size=(img_height, img_width),\n",
31
+ " batch_size=batch_size, class_mode='categorical', subset='validation'\n",
32
+ ")\n",
33
+ "\n",
34
+ "num_classes = len(train_gen.class_indices)\n",
35
+ "\n",
36
+ "dnn_model = Sequential([\n",
37
+ " Flatten(input_shape=(img_height, img_width, 3)),\n",
38
+ " Dense(512, activation='relu'),\n",
39
+ " Dropout(0.5),\n",
40
+ " Dense(256, activation='relu'),\n",
41
+ " Dropout(0.5),\n",
42
+ " Dense(num_classes, activation='softmax')\n",
43
+ "])\n",
44
+ "dnn_model.compile(optimizer=Adam(), loss='categorical_crossentropy', metrics=['accuracy'])\n",
45
+ "\n",
46
+ "cnn_model = Sequential([\n",
47
+ " Conv2D(32, (3,3), activation='relu', input_shape=(img_height, img_width, 3)),\n",
48
+ " MaxPooling2D(2,2),\n",
49
+ " Conv2D(64, (3,3), activation='relu'),\n",
50
+ " MaxPooling2D(2,2),\n",
51
+ " Conv2D(128, (3,3), activation='relu'),\n",
52
+ " MaxPooling2D(2,2),\n",
53
+ " Flatten(),\n",
54
+ " Dense(512, activation='relu'),\n",
55
+ " Dropout(0.5),\n",
56
+ " Dense(num_classes, activation='softmax')\n",
57
+ "])\n",
58
+ "cnn_model.compile(optimizer=Adam(), loss='categorical_crossentropy', metrics=['accuracy'])\n",
59
+ "\n",
60
+ "dnn_history = dnn_model.fit(train_gen, epochs=20, validation_data=val_gen)\n",
61
+ "cnn_history = cnn_model.fit(train_gen, epochs=20, validation_data=val_gen)\n",
62
+ "\n",
63
+ "comparison = pd.DataFrame({\n",
64
+ " 'Model': ['DNN', 'CNN'],\n",
65
+ " 'Parameters': [dnn_model.count_params(), cnn_model.count_params()],\n",
66
+ " 'Final Train Accuracy': [\n",
67
+ " dnn_history.history['accuracy'][-1],\n",
68
+ " cnn_history.history['accuracy'][-1]\n",
69
+ " ],\n",
70
+ " 'Final Val Accuracy': [\n",
71
+ " dnn_history.history['val_accuracy'][-1],\n",
72
+ " cnn_history.history['val_accuracy'][-1]\n",
73
+ " ]\n",
74
+ "})\n",
75
+ "\n",
76
+ "print(comparison)\n",
77
+ "\n",
78
+ "plt.figure(figsize=(12,5))\n",
79
+ "plt.subplot(1,2,1)\n",
80
+ "plt.plot(dnn_history.history['accuracy'], label='DNN Train')\n",
81
+ "plt.plot(dnn_history.history['val_accuracy'], label='DNN Val')\n",
82
+ "plt.plot(cnn_history.history['accuracy'], label='CNN Train')\n",
83
+ "plt.plot(cnn_history.history['val_accuracy'], label='CNN Val')\n",
84
+ "plt.title('Accuracy')\n",
85
+ "plt.xlabel('Epoch')\n",
86
+ "plt.ylabel('Accuracy')\n",
87
+ "plt.legend()\n",
88
+ "\n",
89
+ "plt.subplot(1,2,2)\n",
90
+ "plt.plot(dnn_history.history['loss'], label='DNN Train')\n",
91
+ "plt.plot(dnn_history.history['val_loss'], label='DNN Val')\n",
92
+ "plt.plot(cnn_history.history['loss'], label='CNN Train')\n",
93
+ "plt.plot(cnn_history.history['val_loss'], label='CNN Val')\n",
94
+ "plt.title('Loss')\n",
95
+ "plt.xlabel('Epoch')\n",
96
+ "plt.ylabel('Loss')\n",
97
+ "plt.legend()\n",
98
+ "plt.show()"
99
+ ]
100
+ }
101
+ ],
102
+ "metadata": {
103
+ "kernelspec": {
104
+ "display_name": "Python 3 (ipykernel)",
105
+ "language": "python",
106
+ "name": "python3"
107
+ },
108
+ "language_info": {
109
+ "codemirror_mode": {
110
+ "name": "ipython",
111
+ "version": 3
112
+ },
113
+ "file_extension": ".py",
114
+ "mimetype": "text/x-python",
115
+ "name": "python",
116
+ "nbconvert_exporter": "python",
117
+ "pygments_lexer": "ipython3",
118
+ "version": "3.12.4"
119
+ }
120
+ },
121
+ "nbformat": 4,
122
+ "nbformat_minor": 5
123
+ }
@@ -0,0 +1,108 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "b417a942-8300-4101-9851-d65880f3bbb4",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import tensorflow as tf\n",
11
+ "from tensorflow.keras.preprocessing.image import ImageDataGenerator\n",
12
+ "from tensorflow.keras.layers import Conv2D, MaxPooling2D, Conv2DTranspose, Input\n",
13
+ "from tensorflow.keras.models import Model\n",
14
+ "import matplotlib.pyplot as plt\n",
15
+ "import numpy as np\n",
16
+ "\n",
17
+ "image_dir = \"image path\"\n",
18
+ "mask_dir = \"mask path\"\n",
19
+ "\n",
20
+ "image_datagen = ImageDataGenerator(rescale=1./255)\n",
21
+ "mask_datagen = ImageDataGenerator(rescale=1./255)\n",
22
+ "\n",
23
+ "image_generator = image_datagen.flow_from_directory(\n",
24
+ " image_dir,\n",
25
+ " class_mode=None,\n",
26
+ " color_mode='rgb',\n",
27
+ " target_size=(128, 128),\n",
28
+ " batch_size=32,\n",
29
+ " seed=42\n",
30
+ ")\n",
31
+ "\n",
32
+ "mask_generator = mask_datagen.flow_from_directory(\n",
33
+ " mask_dir,\n",
34
+ " class_mode=None,\n",
35
+ " color_mode='grayscale',\n",
36
+ " target_size=(128, 128),\n",
37
+ " batch_size=32,\n",
38
+ " seed=42\n",
39
+ ")\n",
40
+ "\n",
41
+ "def build_fcnn():\n",
42
+ " inputs = Input((128, 128, 3))\n",
43
+ " conv1 = Conv2D(128, (3, 3), activation='relu', padding='same')(inputs)\n",
44
+ " pool1 = MaxPooling2D((2, 2))(conv1)\n",
45
+ "\n",
46
+ " conv2 = Conv2D(256, (3, 3), activation='relu', padding='same')(pool1)\n",
47
+ " pool2 = MaxPooling2D((2, 2))(conv2)\n",
48
+ "\n",
49
+ " conv3 = Conv2D(256, (3, 3), activation='relu', padding='same')(pool2)\n",
50
+ " up1 = Conv2DTranspose(128, (2, 2), strides=(2, 2), padding='same')(conv3)\n",
51
+ "\n",
52
+ " conv4 = Conv2D(128, (3, 3), activation='relu', padding='same')(up1)\n",
53
+ " up2 = Conv2DTranspose(64, (2, 2), strides=(2, 2), padding='same')(conv4)\n",
54
+ "\n",
55
+ " outputs = Conv2D(1, (1, 1), activation='sigmoid', padding='same')(up2)\n",
56
+ " return Model(inputs, outputs)\n",
57
+ "\n",
58
+ "model = build_fcnn()\n",
59
+ "model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])\n",
60
+ "model.summary()\n",
61
+ "\n",
62
+ "def combined_generator(image_gen, mask_gen):\n",
63
+ " while True:\n",
64
+ " img_batch = next(image_gen)\n",
65
+ " mask_batch = next(mask_gen)\n",
66
+ " yield img_batch, mask_batch\n",
67
+ "\n",
68
+ "train_generator = combined_generator(image_generator, mask_generator)\n",
69
+ "\n",
70
+ "model.fit(train_generator, steps_per_epoch=len(image_generator), epochs=50)\n",
71
+ "\n",
72
+ "sample_image = image_generator[0][0][0]\n",
73
+ "predicted_mask = model.predict(np.expand_dims(sample_image, axis=0))[0]\n",
74
+ "\n",
75
+ "plt.figure(figsize=(10, 5))\n",
76
+ "plt.subplot(1, 2, 1)\n",
77
+ "plt.title(\"Original Image\")\n",
78
+ "plt.imshow(sample_image)\n",
79
+ "\n",
80
+ "plt.subplot(1, 2, 2)\n",
81
+ "plt.title(\"Predicted Mask\")\n",
82
+ "plt.imshow(predicted_mask.squeeze(), cmap='gray')\n",
83
+ "plt.show()"
84
+ ]
85
+ }
86
+ ],
87
+ "metadata": {
88
+ "kernelspec": {
89
+ "display_name": "Python 3 (ipykernel)",
90
+ "language": "python",
91
+ "name": "python3"
92
+ },
93
+ "language_info": {
94
+ "codemirror_mode": {
95
+ "name": "ipython",
96
+ "version": 3
97
+ },
98
+ "file_extension": ".py",
99
+ "mimetype": "text/x-python",
100
+ "name": "python",
101
+ "nbconvert_exporter": "python",
102
+ "pygments_lexer": "ipython3",
103
+ "version": "3.12.4"
104
+ }
105
+ },
106
+ "nbformat": 4,
107
+ "nbformat_minor": 5
108
+ }