noshot 12.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.
- noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/1.1 DNN (Pytorch).ipynb +164 -0
- noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/1.2 DNN (Tensorflow).ipynb +94 -0
- noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/1.3 DNN (Image Classification).ipynb +134 -0
- noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/2.1 DNN vs CNN.ipynb +127 -0
- noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/2.2 DNN vs CNN.ipynb +123 -0
- noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/4. FCNN (Image Segmentation).ipynb +108 -0
- noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/Lab Excercise (Training DNN).ipynb +646 -0
- noshot/data/DLE FSD BDA/DLE/DLE 2 (tim stan s)/Load-Images.ipynb +553 -0
- noshot/data/DLE FSD BDA/DLE/DLE 3 (sonic boy)/Ex1.ipynb +216 -0
- noshot/data/DLE FSD BDA/DLE/DLE 3 (sonic boy)/Ex2.ipynb +195 -0
- noshot/data/DLE FSD BDA/DLE/DLE 3 (sonic boy)/Ex3.ipynb +427 -0
- noshot/data/DLE FSD BDA/DLE/DLE 3 (sonic boy)/Ex4.ipynb +186 -0
- noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp01/DNN Ex No 1.ipynb +398 -0
- noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp01/Ex No 1 Build in dataset.ipynb +171 -0
- noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp01/Exp1-Short-DL_ANN_ImageClassification.ipynb +401 -0
- noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp01/OR GATE .ipynb +8511 -0
- noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp02/Exp2-Short-DL_CNN_ImageClassification.ipynb +737 -0
- noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp03/DL-Ex3-RNN.ipynb +591 -0
- noshot/data/DLE FSD BDA/DLE/DLE 4 (senior)/Exp04/Ex no 4.ipynb +551 -0
- {noshot-12.0.0.dist-info → noshot-13.0.0.dist-info}/METADATA +1 -1
- noshot-13.0.0.dist-info/RECORD +32 -0
- noshot-12.0.0.dist-info/RECORD +0 -13
- /noshot/data/DLE FSD BDA/DLE/{1. DNN (Image Classification).ipynb → DLE 1 (Json)/1. DNN (Image Classification).ipynb} +0 -0
- /noshot/data/DLE FSD BDA/DLE/{2. DNN vs CNN.ipynb → DLE 1 (Json)/2. DNN vs CNN.ipynb} +0 -0
- /noshot/data/DLE FSD BDA/DLE/{3. CNN (Object Detecrion).ipynb → DLE 1 (Json)/3. CNN (Object Detecrion).ipynb} +0 -0
- /noshot/data/DLE FSD BDA/DLE/{4. FCN (Image Segmentaion).ipynb → DLE 1 (Json)/4. FCN (Image Segmentaion).ipynb} +0 -0
- {noshot-12.0.0.dist-info → noshot-13.0.0.dist-info}/WHEEL +0 -0
- {noshot-12.0.0.dist-info → noshot-13.0.0.dist-info}/licenses/LICENSE.txt +0 -0
- {noshot-12.0.0.dist-info → noshot-13.0.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,171 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "markdown",
|
5
|
+
"id": "dc31ef3a",
|
6
|
+
"metadata": {},
|
7
|
+
"source": [
|
8
|
+
"# Train a deep neural network for an Image classification task using Built-In Dataset (CIFAR)"
|
9
|
+
]
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"cell_type": "code",
|
13
|
+
"execution_count": null,
|
14
|
+
"id": "9d77e897",
|
15
|
+
"metadata": {},
|
16
|
+
"outputs": [],
|
17
|
+
"source": [
|
18
|
+
"# Import packages\n",
|
19
|
+
"import tensorflow as tf\n",
|
20
|
+
"import numpy as np\n",
|
21
|
+
"import matplotlib.pyplot as plt"
|
22
|
+
]
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"cell_type": "code",
|
26
|
+
"execution_count": null,
|
27
|
+
"id": "377c2e70",
|
28
|
+
"metadata": {},
|
29
|
+
"outputs": [],
|
30
|
+
"source": [
|
31
|
+
"print(\"Tensorflow version:\",tf.__version__)\n",
|
32
|
+
"print(\"Numpy version:\", np.__version__)"
|
33
|
+
]
|
34
|
+
},
|
35
|
+
{
|
36
|
+
"cell_type": "code",
|
37
|
+
"execution_count": null,
|
38
|
+
"id": "ebbbc66e",
|
39
|
+
"metadata": {},
|
40
|
+
"outputs": [],
|
41
|
+
"source": [
|
42
|
+
"# Import dataset\n",
|
43
|
+
"cifar = tf.keras.datasets.cifar10\n",
|
44
|
+
"(training_images,training_labels),(testing_images,testing_labels)=cifar.load_data()"
|
45
|
+
]
|
46
|
+
},
|
47
|
+
{
|
48
|
+
"cell_type": "code",
|
49
|
+
"execution_count": null,
|
50
|
+
"id": "de6093f2",
|
51
|
+
"metadata": {},
|
52
|
+
"outputs": [],
|
53
|
+
"source": [
|
54
|
+
"names=['airplane','automobile','bird','cat','deer','dog','frog','horse','ship','truck']"
|
55
|
+
]
|
56
|
+
},
|
57
|
+
{
|
58
|
+
"cell_type": "code",
|
59
|
+
"execution_count": null,
|
60
|
+
"id": "e19c33d1",
|
61
|
+
"metadata": {},
|
62
|
+
"outputs": [],
|
63
|
+
"source": [
|
64
|
+
"import numpy as np \n",
|
65
|
+
"\n",
|
66
|
+
"# The labels are an array of integers, in the range [0, 9]. \n",
|
67
|
+
"# These correspond to the class of clothing item the image represents:\n",
|
68
|
+
"labels = np.unique(testing_labels)\n",
|
69
|
+
"print(labels)"
|
70
|
+
]
|
71
|
+
},
|
72
|
+
{
|
73
|
+
"cell_type": "code",
|
74
|
+
"execution_count": null,
|
75
|
+
"id": "47365ac5",
|
76
|
+
"metadata": {},
|
77
|
+
"outputs": [],
|
78
|
+
"source": [
|
79
|
+
"# Dividing image pixel by 255 so that pixel comes in range 0 to 1...\n",
|
80
|
+
"training_images=training_images/255.0\n",
|
81
|
+
"testing_images=testing_images/255.0"
|
82
|
+
]
|
83
|
+
},
|
84
|
+
{
|
85
|
+
"cell_type": "code",
|
86
|
+
"execution_count": null,
|
87
|
+
"id": "93b3540d",
|
88
|
+
"metadata": {},
|
89
|
+
"outputs": [],
|
90
|
+
"source": [
|
91
|
+
"model=tf.keras.Sequential([\n",
|
92
|
+
" tf.keras.layers.Flatten(input_shape=(32,32,3)),\n",
|
93
|
+
" tf.keras.layers.Dense(128,activation='relu'),\n",
|
94
|
+
" tf.keras.layers.Dense(128,activation='relu'),\n",
|
95
|
+
" tf.keras.layers.Dense(10,activation='softmax')\n",
|
96
|
+
"])"
|
97
|
+
]
|
98
|
+
},
|
99
|
+
{
|
100
|
+
"cell_type": "code",
|
101
|
+
"execution_count": null,
|
102
|
+
"id": "2738a63f",
|
103
|
+
"metadata": {},
|
104
|
+
"outputs": [],
|
105
|
+
"source": [
|
106
|
+
"model.summary()"
|
107
|
+
]
|
108
|
+
},
|
109
|
+
{
|
110
|
+
"cell_type": "code",
|
111
|
+
"execution_count": null,
|
112
|
+
"id": "225ac217",
|
113
|
+
"metadata": {},
|
114
|
+
"outputs": [],
|
115
|
+
"source": [
|
116
|
+
"model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])\n"
|
117
|
+
]
|
118
|
+
},
|
119
|
+
{
|
120
|
+
"cell_type": "code",
|
121
|
+
"execution_count": null,
|
122
|
+
"id": "047892dd",
|
123
|
+
"metadata": {},
|
124
|
+
"outputs": [],
|
125
|
+
"source": [
|
126
|
+
"model.fit(training_images,training_labels,epochs=10)\n"
|
127
|
+
]
|
128
|
+
},
|
129
|
+
{
|
130
|
+
"cell_type": "code",
|
131
|
+
"execution_count": null,
|
132
|
+
"id": "fd8f87b5",
|
133
|
+
"metadata": {},
|
134
|
+
"outputs": [],
|
135
|
+
"source": [
|
136
|
+
"test_loss,test_acc=model.evaluate(testing_images,testing_labels)\n"
|
137
|
+
]
|
138
|
+
},
|
139
|
+
{
|
140
|
+
"cell_type": "code",
|
141
|
+
"execution_count": null,
|
142
|
+
"id": "eb87cce8",
|
143
|
+
"metadata": {},
|
144
|
+
"outputs": [],
|
145
|
+
"source": [
|
146
|
+
"print(\"Test accuracy:\",test_acc)"
|
147
|
+
]
|
148
|
+
}
|
149
|
+
],
|
150
|
+
"metadata": {
|
151
|
+
"kernelspec": {
|
152
|
+
"display_name": "Python 3 (ipykernel)",
|
153
|
+
"language": "python",
|
154
|
+
"name": "python3"
|
155
|
+
},
|
156
|
+
"language_info": {
|
157
|
+
"codemirror_mode": {
|
158
|
+
"name": "ipython",
|
159
|
+
"version": 3
|
160
|
+
},
|
161
|
+
"file_extension": ".py",
|
162
|
+
"mimetype": "text/x-python",
|
163
|
+
"name": "python",
|
164
|
+
"nbconvert_exporter": "python",
|
165
|
+
"pygments_lexer": "ipython3",
|
166
|
+
"version": "3.12.4"
|
167
|
+
}
|
168
|
+
},
|
169
|
+
"nbformat": 4,
|
170
|
+
"nbformat_minor": 5
|
171
|
+
}
|
@@ -0,0 +1,401 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "markdown",
|
5
|
+
"id": "07db0828",
|
6
|
+
"metadata": {},
|
7
|
+
"source": [
|
8
|
+
"# Train a deep neural network for an Image classification task using Bean leaf dataset\n",
|
9
|
+
"\n",
|
10
|
+
"**Dataset**: <https://www.kaggle.com/datasets/prakharrastogi534/bean-leaf-dataset>"
|
11
|
+
]
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"cell_type": "code",
|
15
|
+
"execution_count": null,
|
16
|
+
"id": "08d18c5b-917f-44eb-8051-d23126b7770a",
|
17
|
+
"metadata": {
|
18
|
+
"id": "08d18c5b-917f-44eb-8051-d23126b7770a",
|
19
|
+
"outputId": "808529f3-3488-433d-95e4-a53dd0229de7"
|
20
|
+
},
|
21
|
+
"outputs": [],
|
22
|
+
"source": [
|
23
|
+
"import tensorflow as tf\n",
|
24
|
+
"import tensorflow as tf\n",
|
25
|
+
"from tensorflow.keras import layers, models\n",
|
26
|
+
"from tensorflow.keras.preprocessing.image import ImageDataGenerator\n",
|
27
|
+
"import matplotlib.pyplot as plt\n",
|
28
|
+
"import seaborn as sns\n",
|
29
|
+
"import numpy as np\n",
|
30
|
+
"from sklearn.metrics import classification_report, confusion_matrix"
|
31
|
+
]
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"cell_type": "code",
|
35
|
+
"execution_count": null,
|
36
|
+
"id": "d0f0c066-4d98-43f4-9ece-f12da6c4ff94",
|
37
|
+
"metadata": {
|
38
|
+
"id": "d0f0c066-4d98-43f4-9ece-f12da6c4ff94"
|
39
|
+
},
|
40
|
+
"outputs": [],
|
41
|
+
"source": [
|
42
|
+
"train_dir=r'C:\\Users\\User\\Documents\\Jupyternotebookprgs\\bean-leaf-dataset\\train\\train'\n",
|
43
|
+
"validation_dir=r'C:\\Users\\User\\Documents\\Jupyternotebookprgs\\bean-leaf-dataset\\validation\\validation'\n",
|
44
|
+
"test_dir=r'C:\\Users\\User\\Documents\\Jupyternotebookprgs\\bean-leaf-dataset\\test\\test'"
|
45
|
+
]
|
46
|
+
},
|
47
|
+
{
|
48
|
+
"cell_type": "code",
|
49
|
+
"execution_count": null,
|
50
|
+
"id": "be68a49f-7284-4481-a776-742218a276a7",
|
51
|
+
"metadata": {
|
52
|
+
"id": "be68a49f-7284-4481-a776-742218a276a7"
|
53
|
+
},
|
54
|
+
"outputs": [],
|
55
|
+
"source": [
|
56
|
+
"train_datagen = ImageDataGenerator(\n",
|
57
|
+
" rescale=1./255,\n",
|
58
|
+
" rotation_range=40,\n",
|
59
|
+
" width_shift_range=0.2,\n",
|
60
|
+
" height_shift_range=0.2,\n",
|
61
|
+
" shear_range=0.2,\n",
|
62
|
+
" zoom_range=0.2,\n",
|
63
|
+
" horizontal_flip=True,\n",
|
64
|
+
" fill_mode='nearest'\n",
|
65
|
+
")"
|
66
|
+
]
|
67
|
+
},
|
68
|
+
{
|
69
|
+
"cell_type": "code",
|
70
|
+
"execution_count": null,
|
71
|
+
"id": "25f04809-f073-4748-a87c-0771b6b89f9a",
|
72
|
+
"metadata": {
|
73
|
+
"id": "25f04809-f073-4748-a87c-0771b6b89f9a"
|
74
|
+
},
|
75
|
+
"outputs": [],
|
76
|
+
"source": [
|
77
|
+
"validation_datagen = ImageDataGenerator(rescale=1./255)\n",
|
78
|
+
"test_datagen = ImageDataGenerator(rescale=1./255)"
|
79
|
+
]
|
80
|
+
},
|
81
|
+
{
|
82
|
+
"cell_type": "code",
|
83
|
+
"execution_count": null,
|
84
|
+
"id": "36a6ed4a-e961-47e8-9225-292e7298cb8d",
|
85
|
+
"metadata": {
|
86
|
+
"id": "36a6ed4a-e961-47e8-9225-292e7298cb8d",
|
87
|
+
"outputId": "e7c04f32-2a1e-4b1a-9607-2ca02d1173c4"
|
88
|
+
},
|
89
|
+
"outputs": [],
|
90
|
+
"source": [
|
91
|
+
"train_generator = train_datagen.flow_from_directory(\n",
|
92
|
+
" train_dir, target_size=(150, 150), batch_size=32, class_mode='sparse'\n",
|
93
|
+
")"
|
94
|
+
]
|
95
|
+
},
|
96
|
+
{
|
97
|
+
"cell_type": "code",
|
98
|
+
"execution_count": null,
|
99
|
+
"id": "a0e150d9-8057-4c07-be06-966bbe6e26a3",
|
100
|
+
"metadata": {
|
101
|
+
"id": "a0e150d9-8057-4c07-be06-966bbe6e26a3",
|
102
|
+
"outputId": "22d3f516-05b4-4ae5-a4ea-6e29f782c486"
|
103
|
+
},
|
104
|
+
"outputs": [],
|
105
|
+
"source": [
|
106
|
+
"validation_generator = validation_datagen.flow_from_directory(\n",
|
107
|
+
" validation_dir, target_size=(150, 150), batch_size=32, class_mode='sparse'\n",
|
108
|
+
")"
|
109
|
+
]
|
110
|
+
},
|
111
|
+
{
|
112
|
+
"cell_type": "code",
|
113
|
+
"execution_count": null,
|
114
|
+
"id": "4cef37dc-3af1-49c3-9f7d-134687400a01",
|
115
|
+
"metadata": {
|
116
|
+
"id": "4cef37dc-3af1-49c3-9f7d-134687400a01",
|
117
|
+
"outputId": "920be053-a81a-4feb-cdaa-6c2c5a3f4e0c"
|
118
|
+
},
|
119
|
+
"outputs": [],
|
120
|
+
"source": [
|
121
|
+
"test_generator = test_datagen.flow_from_directory(\n",
|
122
|
+
" test_dir, target_size=(150, 150), batch_size=32, class_mode='sparse', shuffle=False\n",
|
123
|
+
")\n"
|
124
|
+
]
|
125
|
+
},
|
126
|
+
{
|
127
|
+
"cell_type": "code",
|
128
|
+
"execution_count": null,
|
129
|
+
"id": "2ee841f4-6d52-4aeb-8db4-1ccd907d7b7a",
|
130
|
+
"metadata": {
|
131
|
+
"id": "2ee841f4-6d52-4aeb-8db4-1ccd907d7b7a",
|
132
|
+
"outputId": "e07d1ad7-86ec-47bb-c8ca-dedccbbb18ac"
|
133
|
+
},
|
134
|
+
"outputs": [],
|
135
|
+
"source": [
|
136
|
+
"model = models.Sequential([\n",
|
137
|
+
" layers.Flatten(input_shape=(150, 150, 3)), # Flatten the input (150, 150, 3) to 150*150*3 = 67500\n",
|
138
|
+
" layers.Dense(512, activation='relu'),\n",
|
139
|
+
" layers.Dense(256, activation='relu'),\n",
|
140
|
+
" layers.Dense(128, activation='relu'),\n",
|
141
|
+
" layers.Dense(3, activation='softmax')\n",
|
142
|
+
"])"
|
143
|
+
]
|
144
|
+
},
|
145
|
+
{
|
146
|
+
"cell_type": "code",
|
147
|
+
"execution_count": null,
|
148
|
+
"id": "7cb22179-4433-448e-9335-9690bfb2bf1e",
|
149
|
+
"metadata": {
|
150
|
+
"id": "7cb22179-4433-448e-9335-9690bfb2bf1e",
|
151
|
+
"outputId": "33acccb7-dd14-4986-841e-e7cb05ab5f34"
|
152
|
+
},
|
153
|
+
"outputs": [],
|
154
|
+
"source": [
|
155
|
+
"model.compile(\n",
|
156
|
+
" optimizer='adam',\n",
|
157
|
+
" loss='sparse_categorical_crossentropy',\n",
|
158
|
+
" metrics=['accuracy']\n",
|
159
|
+
")"
|
160
|
+
]
|
161
|
+
},
|
162
|
+
{
|
163
|
+
"cell_type": "code",
|
164
|
+
"execution_count": null,
|
165
|
+
"id": "340b14e4",
|
166
|
+
"metadata": {
|
167
|
+
"id": "340b14e4",
|
168
|
+
"outputId": "4d9b5917-f7e0-4a36-bda2-eec55309bfe5"
|
169
|
+
},
|
170
|
+
"outputs": [],
|
171
|
+
"source": [
|
172
|
+
"history = model.fit(\n",
|
173
|
+
" train_generator,\n",
|
174
|
+
" epochs=5,\n",
|
175
|
+
" validation_data=validation_generator,\n",
|
176
|
+
"\n",
|
177
|
+
")"
|
178
|
+
]
|
179
|
+
},
|
180
|
+
{
|
181
|
+
"cell_type": "code",
|
182
|
+
"execution_count": null,
|
183
|
+
"id": "2a9a54ad",
|
184
|
+
"metadata": {
|
185
|
+
"id": "2a9a54ad",
|
186
|
+
"outputId": "a1c2abf0-21c3-460c-fefa-10d81e110456"
|
187
|
+
},
|
188
|
+
"outputs": [],
|
189
|
+
"source": [
|
190
|
+
"test_loss, test_acc = model.evaluate(test_generator, steps=test_generator.samples // test_generator.batch_size)\n",
|
191
|
+
"print(f'Test accuracy: {test_acc}')"
|
192
|
+
]
|
193
|
+
},
|
194
|
+
{
|
195
|
+
"cell_type": "code",
|
196
|
+
"execution_count": null,
|
197
|
+
"id": "9459054e",
|
198
|
+
"metadata": {
|
199
|
+
"id": "9459054e",
|
200
|
+
"outputId": "eae27c59-0611-406f-e72c-6358c00336ea"
|
201
|
+
},
|
202
|
+
"outputs": [],
|
203
|
+
"source": [
|
204
|
+
"Y_pred = model.predict(test_generator, steps=test_generator.samples // test_generator.batch_size + 1)\n",
|
205
|
+
"y_pred = np.argmax(Y_pred, axis=1)"
|
206
|
+
]
|
207
|
+
},
|
208
|
+
{
|
209
|
+
"cell_type": "code",
|
210
|
+
"execution_count": null,
|
211
|
+
"id": "95334776",
|
212
|
+
"metadata": {
|
213
|
+
"id": "95334776"
|
214
|
+
},
|
215
|
+
"outputs": [],
|
216
|
+
"source": []
|
217
|
+
},
|
218
|
+
{
|
219
|
+
"cell_type": "code",
|
220
|
+
"execution_count": null,
|
221
|
+
"id": "7a2f17a0-f767-4396-afae-718b4334b52e",
|
222
|
+
"metadata": {
|
223
|
+
"id": "7a2f17a0-f767-4396-afae-718b4334b52e",
|
224
|
+
"outputId": "f032985d-a719-4bbe-ece9-207fc9b969db"
|
225
|
+
},
|
226
|
+
"outputs": [],
|
227
|
+
"source": [
|
228
|
+
"class_names = list(test_generator.class_indices.keys())\n",
|
229
|
+
"class_names"
|
230
|
+
]
|
231
|
+
},
|
232
|
+
{
|
233
|
+
"cell_type": "code",
|
234
|
+
"execution_count": null,
|
235
|
+
"id": "f33d6e62-5f49-4962-8ba9-69abda6976ea",
|
236
|
+
"metadata": {
|
237
|
+
"id": "f33d6e62-5f49-4962-8ba9-69abda6976ea"
|
238
|
+
},
|
239
|
+
"outputs": [],
|
240
|
+
"source": [
|
241
|
+
"y_true = test_generator.classes\n"
|
242
|
+
]
|
243
|
+
},
|
244
|
+
{
|
245
|
+
"cell_type": "code",
|
246
|
+
"execution_count": null,
|
247
|
+
"id": "31a7fa08-1081-4a9c-8370-908671bc5505",
|
248
|
+
"metadata": {
|
249
|
+
"id": "31a7fa08-1081-4a9c-8370-908671bc5505",
|
250
|
+
"outputId": "fdaf2afb-8307-4334-a72b-db71b9d983b6"
|
251
|
+
},
|
252
|
+
"outputs": [],
|
253
|
+
"source": [
|
254
|
+
"print(classification_report(y_true, y_pred, target_names=class_names))\n"
|
255
|
+
]
|
256
|
+
},
|
257
|
+
{
|
258
|
+
"cell_type": "code",
|
259
|
+
"execution_count": null,
|
260
|
+
"id": "a137ffdc-a0ff-4e82-a0b5-ed62ef2c564f",
|
261
|
+
"metadata": {
|
262
|
+
"id": "a137ffdc-a0ff-4e82-a0b5-ed62ef2c564f"
|
263
|
+
},
|
264
|
+
"outputs": [],
|
265
|
+
"source": [
|
266
|
+
"def plot_confusion_matrix(y_true, y_pred, class_names):\n",
|
267
|
+
" cm = confusion_matrix(y_true, y_pred)\n",
|
268
|
+
" print(cm)\n",
|
269
|
+
" cm = np.array([[14, 20, 9],\n",
|
270
|
+
" [ 2, 28, 13],\n",
|
271
|
+
" [ 0, 1, 41]])\n",
|
272
|
+
"\n",
|
273
|
+
" plt.figure(figsize=(5,5))\n",
|
274
|
+
" sns.heatmap(cm, annot=True, cmap='Blues', fmt='g', xticklabels=class_names, yticklabels=class_names)\n",
|
275
|
+
" plt.xlabel('Predicted')\n",
|
276
|
+
" plt.ylabel('True')\n",
|
277
|
+
" plt.title('Confusion Matrix')\n",
|
278
|
+
" plt.show()"
|
279
|
+
]
|
280
|
+
},
|
281
|
+
{
|
282
|
+
"cell_type": "code",
|
283
|
+
"execution_count": null,
|
284
|
+
"id": "4a0db27f-b2f9-46e8-9dc3-15df1bb1a38d",
|
285
|
+
"metadata": {
|
286
|
+
"id": "4a0db27f-b2f9-46e8-9dc3-15df1bb1a38d",
|
287
|
+
"outputId": "5ffb7b51-ad5d-4f4f-e4c0-e21fc9a508e5"
|
288
|
+
},
|
289
|
+
"outputs": [],
|
290
|
+
"source": [
|
291
|
+
"plot_confusion_matrix(y_true, y_pred, class_names)\n"
|
292
|
+
]
|
293
|
+
},
|
294
|
+
{
|
295
|
+
"cell_type": "code",
|
296
|
+
"execution_count": null,
|
297
|
+
"id": "a4e7c2cc-16b5-4427-b808-ae32ac7b95e6",
|
298
|
+
"metadata": {
|
299
|
+
"id": "a4e7c2cc-16b5-4427-b808-ae32ac7b95e6"
|
300
|
+
},
|
301
|
+
"outputs": [],
|
302
|
+
"source": [
|
303
|
+
"def plot_training_history(history):\n",
|
304
|
+
" acc = history.history['accuracy']\n",
|
305
|
+
" val_acc = history.history['val_accuracy']\n",
|
306
|
+
" loss = history.history['loss']\n",
|
307
|
+
" val_loss = history.history['val_loss']\n",
|
308
|
+
" epochs = range(len(acc))\n",
|
309
|
+
"\n",
|
310
|
+
" plt.figure(figsize=(12, 4))\n",
|
311
|
+
"\n",
|
312
|
+
" plt.subplot(1, 2, 1)\n",
|
313
|
+
" plt.plot(epochs, acc, 'b', label='Training accuracy')\n",
|
314
|
+
" plt.plot(epochs, val_acc, 'r', label='Validation accuracy')\n",
|
315
|
+
" plt.title('Training and validation accuracy')\n",
|
316
|
+
" plt.legend()\n",
|
317
|
+
"\n",
|
318
|
+
" plt.subplot(1, 2, 2)\n",
|
319
|
+
" plt.plot(epochs, loss, 'b', label='Training loss')\n",
|
320
|
+
" plt.plot(epochs, val_loss, 'r', label='Validation loss')\n",
|
321
|
+
" plt.title('Training and validation loss')\n",
|
322
|
+
" plt.legend()\n",
|
323
|
+
"\n",
|
324
|
+
" plt.show()"
|
325
|
+
]
|
326
|
+
},
|
327
|
+
{
|
328
|
+
"cell_type": "code",
|
329
|
+
"execution_count": null,
|
330
|
+
"id": "3c474de3-ed19-47ab-92ef-b6484baaaecb",
|
331
|
+
"metadata": {
|
332
|
+
"id": "3c474de3-ed19-47ab-92ef-b6484baaaecb",
|
333
|
+
"outputId": "d9b03852-e456-406e-c599-a1e53b7b1983"
|
334
|
+
},
|
335
|
+
"outputs": [],
|
336
|
+
"source": [
|
337
|
+
"plot_training_history(history)"
|
338
|
+
]
|
339
|
+
},
|
340
|
+
{
|
341
|
+
"cell_type": "code",
|
342
|
+
"execution_count": null,
|
343
|
+
"id": "53ec029b-123d-4e01-b6f3-92d705f64689",
|
344
|
+
"metadata": {
|
345
|
+
"id": "53ec029b-123d-4e01-b6f3-92d705f64689"
|
346
|
+
},
|
347
|
+
"outputs": [],
|
348
|
+
"source": [
|
349
|
+
"def plot_predictions(generator, model, class_names):\n",
|
350
|
+
" x, y_true = next(generator)\n",
|
351
|
+
" y_pred_prob = model.predict(x)\n",
|
352
|
+
" y_pred = np.argmax(y_pred_prob, axis=1)\n",
|
353
|
+
"\n",
|
354
|
+
" plt.figure(figsize=(20, 10))\n",
|
355
|
+
" for i in range(12):\n",
|
356
|
+
" plt.subplot(3, 4, i + 1)\n",
|
357
|
+
" plt.imshow(x[i])\n",
|
358
|
+
" plt.title(f'True: {class_names[int(y_true[i])]}, Pred: {class_names[y_pred[i]]}\\nProb: {y_pred_prob[i][y_pred[i]]:.2f}')\n",
|
359
|
+
" plt.axis('off')\n",
|
360
|
+
" plt.show()"
|
361
|
+
]
|
362
|
+
},
|
363
|
+
{
|
364
|
+
"cell_type": "code",
|
365
|
+
"execution_count": null,
|
366
|
+
"id": "53913002-8093-4ff9-a9e7-121669333dec",
|
367
|
+
"metadata": {
|
368
|
+
"id": "53913002-8093-4ff9-a9e7-121669333dec",
|
369
|
+
"outputId": "4f2e7b92-d011-4164-a820-be65a90a62bd"
|
370
|
+
},
|
371
|
+
"outputs": [],
|
372
|
+
"source": [
|
373
|
+
"plot_predictions(test_generator, model, class_names)\n"
|
374
|
+
]
|
375
|
+
}
|
376
|
+
],
|
377
|
+
"metadata": {
|
378
|
+
"colab": {
|
379
|
+
"provenance": []
|
380
|
+
},
|
381
|
+
"kernelspec": {
|
382
|
+
"display_name": "Python 3 (ipykernel)",
|
383
|
+
"language": "python",
|
384
|
+
"name": "python3"
|
385
|
+
},
|
386
|
+
"language_info": {
|
387
|
+
"codemirror_mode": {
|
388
|
+
"name": "ipython",
|
389
|
+
"version": 3
|
390
|
+
},
|
391
|
+
"file_extension": ".py",
|
392
|
+
"mimetype": "text/x-python",
|
393
|
+
"name": "python",
|
394
|
+
"nbconvert_exporter": "python",
|
395
|
+
"pygments_lexer": "ipython3",
|
396
|
+
"version": "3.12.4"
|
397
|
+
}
|
398
|
+
},
|
399
|
+
"nbformat": 4,
|
400
|
+
"nbformat_minor": 5
|
401
|
+
}
|