KameliaZaman commited on
Commit
2f56d76
·
verified ·
1 Parent(s): e192a14

Uploaded project structure

Browse files
Butterfly classification with CNN.ipynb ADDED
@@ -0,0 +1,1797 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "9b10cf68",
6
+ "metadata": {
7
+ "papermill": {
8
+ "duration": 0.009368,
9
+ "end_time": "2023-09-03T09:54:26.123203",
10
+ "exception": false,
11
+ "start_time": "2023-09-03T09:54:26.113835",
12
+ "status": "completed"
13
+ },
14
+ "tags": []
15
+ },
16
+ "source": [
17
+ "# Import Libraries and Load Data"
18
+ ]
19
+ },
20
+ {
21
+ "cell_type": "code",
22
+ "execution_count": 1,
23
+ "id": "82a4c58c",
24
+ "metadata": {
25
+ "execution": {
26
+ "iopub.execute_input": "2023-09-03T09:54:26.143814Z",
27
+ "iopub.status.busy": "2023-09-03T09:54:26.143453Z",
28
+ "iopub.status.idle": "2023-09-03T09:54:38.437851Z",
29
+ "shell.execute_reply": "2023-09-03T09:54:38.436857Z"
30
+ },
31
+ "papermill": {
32
+ "duration": 12.307795,
33
+ "end_time": "2023-09-03T09:54:38.440372",
34
+ "exception": false,
35
+ "start_time": "2023-09-03T09:54:26.132577",
36
+ "status": "completed"
37
+ },
38
+ "tags": []
39
+ },
40
+ "outputs": [],
41
+ "source": [
42
+ "## Remove Warnings ## \n",
43
+ "import warnings\n",
44
+ "warnings.filterwarnings(\"ignore\")\n",
45
+ "\n",
46
+ "## Data ## \n",
47
+ "import numpy as np\n",
48
+ "import pandas as pd \n",
49
+ "import os \n",
50
+ "\n",
51
+ "## Visualization ## \n",
52
+ "import matplotlib.pyplot as plt \n",
53
+ "import plotly.express as px\n",
54
+ "import seaborn as sns\n",
55
+ "import plotly.graph_objects as go \n",
56
+ "\n",
57
+ "## Image ## \n",
58
+ "import cv2\n",
59
+ "from tensorflow.keras.preprocessing.image import ImageDataGenerator \n",
60
+ "\n",
61
+ "## Tensorflow ## \n",
62
+ "from tensorflow.keras.models import Sequential, Model\n",
63
+ "from tensorflow.keras.layers import Input, Dense , Conv2D , Dropout , Flatten , Activation, MaxPooling2D , GlobalAveragePooling2D\n",
64
+ "from tensorflow.keras.optimizers import Adam , RMSprop \n",
65
+ "from tensorflow.keras.layers import BatchNormalization\n",
66
+ "from tensorflow.keras.callbacks import ReduceLROnPlateau , EarlyStopping , ModelCheckpoint , LearningRateScheduler\n",
67
+ "from tensorflow.keras.applications import ResNet50V2"
68
+ ]
69
+ },
70
+ {
71
+ "cell_type": "code",
72
+ "execution_count": 2,
73
+ "id": "1906bacd",
74
+ "metadata": {
75
+ "execution": {
76
+ "iopub.execute_input": "2023-09-03T09:54:38.462010Z",
77
+ "iopub.status.busy": "2023-09-03T09:54:38.461382Z",
78
+ "iopub.status.idle": "2023-09-03T09:54:38.530886Z",
79
+ "shell.execute_reply": "2023-09-03T09:54:38.529893Z"
80
+ },
81
+ "papermill": {
82
+ "duration": 0.082889,
83
+ "end_time": "2023-09-03T09:54:38.533290",
84
+ "exception": false,
85
+ "start_time": "2023-09-03T09:54:38.450401",
86
+ "status": "completed"
87
+ },
88
+ "tags": []
89
+ },
90
+ "outputs": [
91
+ {
92
+ "data": {
93
+ "text/html": [
94
+ "<div>\n",
95
+ "<style scoped>\n",
96
+ " .dataframe tbody tr th:only-of-type {\n",
97
+ " vertical-align: middle;\n",
98
+ " }\n",
99
+ "\n",
100
+ " .dataframe tbody tr th {\n",
101
+ " vertical-align: top;\n",
102
+ " }\n",
103
+ "\n",
104
+ " .dataframe thead th {\n",
105
+ " text-align: right;\n",
106
+ " }\n",
107
+ "</style>\n",
108
+ "<table border=\"1\" class=\"dataframe\">\n",
109
+ " <thead>\n",
110
+ " <tr style=\"text-align: right;\">\n",
111
+ " <th></th>\n",
112
+ " <th>class id</th>\n",
113
+ " <th>filepaths</th>\n",
114
+ " <th>labels</th>\n",
115
+ " <th>data set</th>\n",
116
+ " </tr>\n",
117
+ " </thead>\n",
118
+ " <tbody>\n",
119
+ " <tr>\n",
120
+ " <th>0</th>\n",
121
+ " <td>0</td>\n",
122
+ " <td>C:/Users/kamel/Documents/Image Classification/...</td>\n",
123
+ " <td>ADONIS</td>\n",
124
+ " <td>train</td>\n",
125
+ " </tr>\n",
126
+ " <tr>\n",
127
+ " <th>1</th>\n",
128
+ " <td>0</td>\n",
129
+ " <td>C:/Users/kamel/Documents/Image Classification/...</td>\n",
130
+ " <td>ADONIS</td>\n",
131
+ " <td>train</td>\n",
132
+ " </tr>\n",
133
+ " <tr>\n",
134
+ " <th>2</th>\n",
135
+ " <td>0</td>\n",
136
+ " <td>C:/Users/kamel/Documents/Image Classification/...</td>\n",
137
+ " <td>ADONIS</td>\n",
138
+ " <td>train</td>\n",
139
+ " </tr>\n",
140
+ " <tr>\n",
141
+ " <th>3</th>\n",
142
+ " <td>0</td>\n",
143
+ " <td>C:/Users/kamel/Documents/Image Classification/...</td>\n",
144
+ " <td>ADONIS</td>\n",
145
+ " <td>train</td>\n",
146
+ " </tr>\n",
147
+ " <tr>\n",
148
+ " <th>4</th>\n",
149
+ " <td>0</td>\n",
150
+ " <td>C:/Users/kamel/Documents/Image Classification/...</td>\n",
151
+ " <td>ADONIS</td>\n",
152
+ " <td>train</td>\n",
153
+ " </tr>\n",
154
+ " </tbody>\n",
155
+ "</table>\n",
156
+ "</div>"
157
+ ],
158
+ "text/plain": [
159
+ " class id filepaths labels \\\n",
160
+ "0 0 C:/Users/kamel/Documents/Image Classification/... ADONIS \n",
161
+ "1 0 C:/Users/kamel/Documents/Image Classification/... ADONIS \n",
162
+ "2 0 C:/Users/kamel/Documents/Image Classification/... ADONIS \n",
163
+ "3 0 C:/Users/kamel/Documents/Image Classification/... ADONIS \n",
164
+ "4 0 C:/Users/kamel/Documents/Image Classification/... ADONIS \n",
165
+ "\n",
166
+ " data set \n",
167
+ "0 train \n",
168
+ "1 train \n",
169
+ "2 train \n",
170
+ "3 train \n",
171
+ "4 train "
172
+ ]
173
+ },
174
+ "execution_count": 2,
175
+ "metadata": {},
176
+ "output_type": "execute_result"
177
+ }
178
+ ],
179
+ "source": [
180
+ "df = pd.read_csv('C:/Users/kamel/Documents/Image Classification/butterfly-dataset/butterflies and moths.csv') \n",
181
+ "IMAGE_DIR = 'C:/Users/kamel/Documents/Image Classification/butterfly-dataset'\n",
182
+ "df['filepaths'] = IMAGE_DIR + '/' + df['filepaths']\n",
183
+ "df.head()"
184
+ ]
185
+ },
186
+ {
187
+ "cell_type": "code",
188
+ "execution_count": 3,
189
+ "id": "1b2dd2d3",
190
+ "metadata": {
191
+ "execution": {
192
+ "iopub.execute_input": "2023-09-03T09:54:38.555496Z",
193
+ "iopub.status.busy": "2023-09-03T09:54:38.555183Z",
194
+ "iopub.status.idle": "2023-09-03T09:54:38.575753Z",
195
+ "shell.execute_reply": "2023-09-03T09:54:38.574842Z"
196
+ },
197
+ "papermill": {
198
+ "duration": 0.033846,
199
+ "end_time": "2023-09-03T09:54:38.577919",
200
+ "exception": false,
201
+ "start_time": "2023-09-03T09:54:38.544073",
202
+ "status": "completed"
203
+ },
204
+ "tags": []
205
+ },
206
+ "outputs": [],
207
+ "source": [
208
+ "train_df = df.loc[df['data set'] == 'train']\n",
209
+ "val_df = df.loc[df['data set'] == 'valid']\n",
210
+ "test_df = df.loc[df['data set'] == 'test']"
211
+ ]
212
+ },
213
+ {
214
+ "cell_type": "markdown",
215
+ "id": "37bc594c",
216
+ "metadata": {
217
+ "papermill": {
218
+ "duration": 0.009856,
219
+ "end_time": "2023-09-03T09:54:38.597762",
220
+ "exception": false,
221
+ "start_time": "2023-09-03T09:54:38.587906",
222
+ "status": "completed"
223
+ },
224
+ "tags": []
225
+ },
226
+ "source": [
227
+ "# Exploratory Data Analysis"
228
+ ]
229
+ },
230
+ {
231
+ "cell_type": "code",
232
+ "execution_count": 13,
233
+ "id": "01cf1f03",
234
+ "metadata": {
235
+ "execution": {
236
+ "iopub.execute_input": "2023-09-03T09:54:38.641103Z",
237
+ "iopub.status.busy": "2023-09-03T09:54:38.640074Z",
238
+ "iopub.status.idle": "2023-09-03T09:54:40.212205Z",
239
+ "shell.execute_reply": "2023-09-03T09:54:40.211295Z"
240
+ },
241
+ "papermill": {
242
+ "duration": 1.58707,
243
+ "end_time": "2023-09-03T09:54:40.214269",
244
+ "exception": false,
245
+ "start_time": "2023-09-03T09:54:38.627199",
246
+ "status": "completed"
247
+ },
248
+ "tags": []
249
+ },
250
+ "outputs": [
251
+ {
252
+ "data": {
253
+ "application/vnd.plotly.v1+json": {
254
+ "config": {
255
+ "plotlyServerURL": "https://plot.ly"
256
+ },
257
+ "data": [
258
+ {
259
+ "alignmentgroup": "True",
260
+ "hovertemplate": "x=%{x}<br>y=%{y}<br>text=%{text}<br>color=%{marker.color}<extra></extra>",
261
+ "legendgroup": "",
262
+ "marker": {
263
+ "color": [
264
+ 153,
265
+ 150,
266
+ 149,
267
+ 139,
268
+ 138,
269
+ 136,
270
+ 131,
271
+ 128,
272
+ 117,
273
+ 115
274
+ ],
275
+ "coloraxis": "coloraxis",
276
+ "line": {
277
+ "color": "black",
278
+ "width": 1.5
279
+ },
280
+ "pattern": {
281
+ "shape": ""
282
+ }
283
+ },
284
+ "name": "",
285
+ "offsetgroup": "",
286
+ "opacity": 0.8,
287
+ "orientation": "v",
288
+ "showlegend": false,
289
+ "text": [
290
+ 153,
291
+ 150,
292
+ 149,
293
+ 139,
294
+ 138,
295
+ 136,
296
+ 131,
297
+ 128,
298
+ 117,
299
+ 115
300
+ ],
301
+ "textposition": "auto",
302
+ "type": "bar",
303
+ "x": [
304
+ "ATALA",
305
+ "ARCIGERA FLOWER MOTH",
306
+ "BANDED ORANGE HELICONIAN",
307
+ "ATLAS MOTH",
308
+ "APPOLLO",
309
+ "ADONIS",
310
+ "AN 88",
311
+ "BANDED PEACOCK",
312
+ "AFRICAN GIANT SWALLOWTAIL",
313
+ "AMERICAN SNOOT"
314
+ ],
315
+ "xaxis": "x",
316
+ "y": [
317
+ 153,
318
+ 150,
319
+ 149,
320
+ 139,
321
+ 138,
322
+ 136,
323
+ 131,
324
+ 128,
325
+ 117,
326
+ 115
327
+ ],
328
+ "yaxis": "y"
329
+ }
330
+ ],
331
+ "layout": {
332
+ "barmode": "relative",
333
+ "coloraxis": {
334
+ "colorbar": {
335
+ "title": {
336
+ "text": "color"
337
+ }
338
+ },
339
+ "colorscale": [
340
+ [
341
+ 0,
342
+ "rgb(247,251,255)"
343
+ ],
344
+ [
345
+ 0.125,
346
+ "rgb(222,235,247)"
347
+ ],
348
+ [
349
+ 0.25,
350
+ "rgb(198,219,239)"
351
+ ],
352
+ [
353
+ 0.375,
354
+ "rgb(158,202,225)"
355
+ ],
356
+ [
357
+ 0.5,
358
+ "rgb(107,174,214)"
359
+ ],
360
+ [
361
+ 0.625,
362
+ "rgb(66,146,198)"
363
+ ],
364
+ [
365
+ 0.75,
366
+ "rgb(33,113,181)"
367
+ ],
368
+ [
369
+ 0.875,
370
+ "rgb(8,81,156)"
371
+ ],
372
+ [
373
+ 1,
374
+ "rgb(8,48,107)"
375
+ ]
376
+ ]
377
+ },
378
+ "legend": {
379
+ "tracegroupgap": 0
380
+ },
381
+ "margin": {
382
+ "t": 60
383
+ },
384
+ "template": {
385
+ "data": {
386
+ "bar": [
387
+ {
388
+ "error_x": {
389
+ "color": "#2a3f5f"
390
+ },
391
+ "error_y": {
392
+ "color": "#2a3f5f"
393
+ },
394
+ "marker": {
395
+ "line": {
396
+ "color": "white",
397
+ "width": 0.5
398
+ },
399
+ "pattern": {
400
+ "fillmode": "overlay",
401
+ "size": 10,
402
+ "solidity": 0.2
403
+ }
404
+ },
405
+ "type": "bar"
406
+ }
407
+ ],
408
+ "barpolar": [
409
+ {
410
+ "marker": {
411
+ "line": {
412
+ "color": "white",
413
+ "width": 0.5
414
+ },
415
+ "pattern": {
416
+ "fillmode": "overlay",
417
+ "size": 10,
418
+ "solidity": 0.2
419
+ }
420
+ },
421
+ "type": "barpolar"
422
+ }
423
+ ],
424
+ "carpet": [
425
+ {
426
+ "aaxis": {
427
+ "endlinecolor": "#2a3f5f",
428
+ "gridcolor": "#C8D4E3",
429
+ "linecolor": "#C8D4E3",
430
+ "minorgridcolor": "#C8D4E3",
431
+ "startlinecolor": "#2a3f5f"
432
+ },
433
+ "baxis": {
434
+ "endlinecolor": "#2a3f5f",
435
+ "gridcolor": "#C8D4E3",
436
+ "linecolor": "#C8D4E3",
437
+ "minorgridcolor": "#C8D4E3",
438
+ "startlinecolor": "#2a3f5f"
439
+ },
440
+ "type": "carpet"
441
+ }
442
+ ],
443
+ "choropleth": [
444
+ {
445
+ "colorbar": {
446
+ "outlinewidth": 0,
447
+ "ticks": ""
448
+ },
449
+ "type": "choropleth"
450
+ }
451
+ ],
452
+ "contour": [
453
+ {
454
+ "colorbar": {
455
+ "outlinewidth": 0,
456
+ "ticks": ""
457
+ },
458
+ "colorscale": [
459
+ [
460
+ 0,
461
+ "#0d0887"
462
+ ],
463
+ [
464
+ 0.1111111111111111,
465
+ "#46039f"
466
+ ],
467
+ [
468
+ 0.2222222222222222,
469
+ "#7201a8"
470
+ ],
471
+ [
472
+ 0.3333333333333333,
473
+ "#9c179e"
474
+ ],
475
+ [
476
+ 0.4444444444444444,
477
+ "#bd3786"
478
+ ],
479
+ [
480
+ 0.5555555555555556,
481
+ "#d8576b"
482
+ ],
483
+ [
484
+ 0.6666666666666666,
485
+ "#ed7953"
486
+ ],
487
+ [
488
+ 0.7777777777777778,
489
+ "#fb9f3a"
490
+ ],
491
+ [
492
+ 0.8888888888888888,
493
+ "#fdca26"
494
+ ],
495
+ [
496
+ 1,
497
+ "#f0f921"
498
+ ]
499
+ ],
500
+ "type": "contour"
501
+ }
502
+ ],
503
+ "contourcarpet": [
504
+ {
505
+ "colorbar": {
506
+ "outlinewidth": 0,
507
+ "ticks": ""
508
+ },
509
+ "type": "contourcarpet"
510
+ }
511
+ ],
512
+ "heatmap": [
513
+ {
514
+ "colorbar": {
515
+ "outlinewidth": 0,
516
+ "ticks": ""
517
+ },
518
+ "colorscale": [
519
+ [
520
+ 0,
521
+ "#0d0887"
522
+ ],
523
+ [
524
+ 0.1111111111111111,
525
+ "#46039f"
526
+ ],
527
+ [
528
+ 0.2222222222222222,
529
+ "#7201a8"
530
+ ],
531
+ [
532
+ 0.3333333333333333,
533
+ "#9c179e"
534
+ ],
535
+ [
536
+ 0.4444444444444444,
537
+ "#bd3786"
538
+ ],
539
+ [
540
+ 0.5555555555555556,
541
+ "#d8576b"
542
+ ],
543
+ [
544
+ 0.6666666666666666,
545
+ "#ed7953"
546
+ ],
547
+ [
548
+ 0.7777777777777778,
549
+ "#fb9f3a"
550
+ ],
551
+ [
552
+ 0.8888888888888888,
553
+ "#fdca26"
554
+ ],
555
+ [
556
+ 1,
557
+ "#f0f921"
558
+ ]
559
+ ],
560
+ "type": "heatmap"
561
+ }
562
+ ],
563
+ "heatmapgl": [
564
+ {
565
+ "colorbar": {
566
+ "outlinewidth": 0,
567
+ "ticks": ""
568
+ },
569
+ "colorscale": [
570
+ [
571
+ 0,
572
+ "#0d0887"
573
+ ],
574
+ [
575
+ 0.1111111111111111,
576
+ "#46039f"
577
+ ],
578
+ [
579
+ 0.2222222222222222,
580
+ "#7201a8"
581
+ ],
582
+ [
583
+ 0.3333333333333333,
584
+ "#9c179e"
585
+ ],
586
+ [
587
+ 0.4444444444444444,
588
+ "#bd3786"
589
+ ],
590
+ [
591
+ 0.5555555555555556,
592
+ "#d8576b"
593
+ ],
594
+ [
595
+ 0.6666666666666666,
596
+ "#ed7953"
597
+ ],
598
+ [
599
+ 0.7777777777777778,
600
+ "#fb9f3a"
601
+ ],
602
+ [
603
+ 0.8888888888888888,
604
+ "#fdca26"
605
+ ],
606
+ [
607
+ 1,
608
+ "#f0f921"
609
+ ]
610
+ ],
611
+ "type": "heatmapgl"
612
+ }
613
+ ],
614
+ "histogram": [
615
+ {
616
+ "marker": {
617
+ "pattern": {
618
+ "fillmode": "overlay",
619
+ "size": 10,
620
+ "solidity": 0.2
621
+ }
622
+ },
623
+ "type": "histogram"
624
+ }
625
+ ],
626
+ "histogram2d": [
627
+ {
628
+ "colorbar": {
629
+ "outlinewidth": 0,
630
+ "ticks": ""
631
+ },
632
+ "colorscale": [
633
+ [
634
+ 0,
635
+ "#0d0887"
636
+ ],
637
+ [
638
+ 0.1111111111111111,
639
+ "#46039f"
640
+ ],
641
+ [
642
+ 0.2222222222222222,
643
+ "#7201a8"
644
+ ],
645
+ [
646
+ 0.3333333333333333,
647
+ "#9c179e"
648
+ ],
649
+ [
650
+ 0.4444444444444444,
651
+ "#bd3786"
652
+ ],
653
+ [
654
+ 0.5555555555555556,
655
+ "#d8576b"
656
+ ],
657
+ [
658
+ 0.6666666666666666,
659
+ "#ed7953"
660
+ ],
661
+ [
662
+ 0.7777777777777778,
663
+ "#fb9f3a"
664
+ ],
665
+ [
666
+ 0.8888888888888888,
667
+ "#fdca26"
668
+ ],
669
+ [
670
+ 1,
671
+ "#f0f921"
672
+ ]
673
+ ],
674
+ "type": "histogram2d"
675
+ }
676
+ ],
677
+ "histogram2dcontour": [
678
+ {
679
+ "colorbar": {
680
+ "outlinewidth": 0,
681
+ "ticks": ""
682
+ },
683
+ "colorscale": [
684
+ [
685
+ 0,
686
+ "#0d0887"
687
+ ],
688
+ [
689
+ 0.1111111111111111,
690
+ "#46039f"
691
+ ],
692
+ [
693
+ 0.2222222222222222,
694
+ "#7201a8"
695
+ ],
696
+ [
697
+ 0.3333333333333333,
698
+ "#9c179e"
699
+ ],
700
+ [
701
+ 0.4444444444444444,
702
+ "#bd3786"
703
+ ],
704
+ [
705
+ 0.5555555555555556,
706
+ "#d8576b"
707
+ ],
708
+ [
709
+ 0.6666666666666666,
710
+ "#ed7953"
711
+ ],
712
+ [
713
+ 0.7777777777777778,
714
+ "#fb9f3a"
715
+ ],
716
+ [
717
+ 0.8888888888888888,
718
+ "#fdca26"
719
+ ],
720
+ [
721
+ 1,
722
+ "#f0f921"
723
+ ]
724
+ ],
725
+ "type": "histogram2dcontour"
726
+ }
727
+ ],
728
+ "mesh3d": [
729
+ {
730
+ "colorbar": {
731
+ "outlinewidth": 0,
732
+ "ticks": ""
733
+ },
734
+ "type": "mesh3d"
735
+ }
736
+ ],
737
+ "parcoords": [
738
+ {
739
+ "line": {
740
+ "colorbar": {
741
+ "outlinewidth": 0,
742
+ "ticks": ""
743
+ }
744
+ },
745
+ "type": "parcoords"
746
+ }
747
+ ],
748
+ "pie": [
749
+ {
750
+ "automargin": true,
751
+ "type": "pie"
752
+ }
753
+ ],
754
+ "scatter": [
755
+ {
756
+ "fillpattern": {
757
+ "fillmode": "overlay",
758
+ "size": 10,
759
+ "solidity": 0.2
760
+ },
761
+ "type": "scatter"
762
+ }
763
+ ],
764
+ "scatter3d": [
765
+ {
766
+ "line": {
767
+ "colorbar": {
768
+ "outlinewidth": 0,
769
+ "ticks": ""
770
+ }
771
+ },
772
+ "marker": {
773
+ "colorbar": {
774
+ "outlinewidth": 0,
775
+ "ticks": ""
776
+ }
777
+ },
778
+ "type": "scatter3d"
779
+ }
780
+ ],
781
+ "scattercarpet": [
782
+ {
783
+ "marker": {
784
+ "colorbar": {
785
+ "outlinewidth": 0,
786
+ "ticks": ""
787
+ }
788
+ },
789
+ "type": "scattercarpet"
790
+ }
791
+ ],
792
+ "scattergeo": [
793
+ {
794
+ "marker": {
795
+ "colorbar": {
796
+ "outlinewidth": 0,
797
+ "ticks": ""
798
+ }
799
+ },
800
+ "type": "scattergeo"
801
+ }
802
+ ],
803
+ "scattergl": [
804
+ {
805
+ "marker": {
806
+ "colorbar": {
807
+ "outlinewidth": 0,
808
+ "ticks": ""
809
+ }
810
+ },
811
+ "type": "scattergl"
812
+ }
813
+ ],
814
+ "scattermapbox": [
815
+ {
816
+ "marker": {
817
+ "colorbar": {
818
+ "outlinewidth": 0,
819
+ "ticks": ""
820
+ }
821
+ },
822
+ "type": "scattermapbox"
823
+ }
824
+ ],
825
+ "scatterpolar": [
826
+ {
827
+ "marker": {
828
+ "colorbar": {
829
+ "outlinewidth": 0,
830
+ "ticks": ""
831
+ }
832
+ },
833
+ "type": "scatterpolar"
834
+ }
835
+ ],
836
+ "scatterpolargl": [
837
+ {
838
+ "marker": {
839
+ "colorbar": {
840
+ "outlinewidth": 0,
841
+ "ticks": ""
842
+ }
843
+ },
844
+ "type": "scatterpolargl"
845
+ }
846
+ ],
847
+ "scatterternary": [
848
+ {
849
+ "marker": {
850
+ "colorbar": {
851
+ "outlinewidth": 0,
852
+ "ticks": ""
853
+ }
854
+ },
855
+ "type": "scatterternary"
856
+ }
857
+ ],
858
+ "surface": [
859
+ {
860
+ "colorbar": {
861
+ "outlinewidth": 0,
862
+ "ticks": ""
863
+ },
864
+ "colorscale": [
865
+ [
866
+ 0,
867
+ "#0d0887"
868
+ ],
869
+ [
870
+ 0.1111111111111111,
871
+ "#46039f"
872
+ ],
873
+ [
874
+ 0.2222222222222222,
875
+ "#7201a8"
876
+ ],
877
+ [
878
+ 0.3333333333333333,
879
+ "#9c179e"
880
+ ],
881
+ [
882
+ 0.4444444444444444,
883
+ "#bd3786"
884
+ ],
885
+ [
886
+ 0.5555555555555556,
887
+ "#d8576b"
888
+ ],
889
+ [
890
+ 0.6666666666666666,
891
+ "#ed7953"
892
+ ],
893
+ [
894
+ 0.7777777777777778,
895
+ "#fb9f3a"
896
+ ],
897
+ [
898
+ 0.8888888888888888,
899
+ "#fdca26"
900
+ ],
901
+ [
902
+ 1,
903
+ "#f0f921"
904
+ ]
905
+ ],
906
+ "type": "surface"
907
+ }
908
+ ],
909
+ "table": [
910
+ {
911
+ "cells": {
912
+ "fill": {
913
+ "color": "#EBF0F8"
914
+ },
915
+ "line": {
916
+ "color": "white"
917
+ }
918
+ },
919
+ "header": {
920
+ "fill": {
921
+ "color": "#C8D4E3"
922
+ },
923
+ "line": {
924
+ "color": "white"
925
+ }
926
+ },
927
+ "type": "table"
928
+ }
929
+ ]
930
+ },
931
+ "layout": {
932
+ "annotationdefaults": {
933
+ "arrowcolor": "#2a3f5f",
934
+ "arrowhead": 0,
935
+ "arrowwidth": 1
936
+ },
937
+ "autotypenumbers": "strict",
938
+ "coloraxis": {
939
+ "colorbar": {
940
+ "outlinewidth": 0,
941
+ "ticks": ""
942
+ }
943
+ },
944
+ "colorscale": {
945
+ "diverging": [
946
+ [
947
+ 0,
948
+ "#8e0152"
949
+ ],
950
+ [
951
+ 0.1,
952
+ "#c51b7d"
953
+ ],
954
+ [
955
+ 0.2,
956
+ "#de77ae"
957
+ ],
958
+ [
959
+ 0.3,
960
+ "#f1b6da"
961
+ ],
962
+ [
963
+ 0.4,
964
+ "#fde0ef"
965
+ ],
966
+ [
967
+ 0.5,
968
+ "#f7f7f7"
969
+ ],
970
+ [
971
+ 0.6,
972
+ "#e6f5d0"
973
+ ],
974
+ [
975
+ 0.7,
976
+ "#b8e186"
977
+ ],
978
+ [
979
+ 0.8,
980
+ "#7fbc41"
981
+ ],
982
+ [
983
+ 0.9,
984
+ "#4d9221"
985
+ ],
986
+ [
987
+ 1,
988
+ "#276419"
989
+ ]
990
+ ],
991
+ "sequential": [
992
+ [
993
+ 0,
994
+ "#0d0887"
995
+ ],
996
+ [
997
+ 0.1111111111111111,
998
+ "#46039f"
999
+ ],
1000
+ [
1001
+ 0.2222222222222222,
1002
+ "#7201a8"
1003
+ ],
1004
+ [
1005
+ 0.3333333333333333,
1006
+ "#9c179e"
1007
+ ],
1008
+ [
1009
+ 0.4444444444444444,
1010
+ "#bd3786"
1011
+ ],
1012
+ [
1013
+ 0.5555555555555556,
1014
+ "#d8576b"
1015
+ ],
1016
+ [
1017
+ 0.6666666666666666,
1018
+ "#ed7953"
1019
+ ],
1020
+ [
1021
+ 0.7777777777777778,
1022
+ "#fb9f3a"
1023
+ ],
1024
+ [
1025
+ 0.8888888888888888,
1026
+ "#fdca26"
1027
+ ],
1028
+ [
1029
+ 1,
1030
+ "#f0f921"
1031
+ ]
1032
+ ],
1033
+ "sequentialminus": [
1034
+ [
1035
+ 0,
1036
+ "#0d0887"
1037
+ ],
1038
+ [
1039
+ 0.1111111111111111,
1040
+ "#46039f"
1041
+ ],
1042
+ [
1043
+ 0.2222222222222222,
1044
+ "#7201a8"
1045
+ ],
1046
+ [
1047
+ 0.3333333333333333,
1048
+ "#9c179e"
1049
+ ],
1050
+ [
1051
+ 0.4444444444444444,
1052
+ "#bd3786"
1053
+ ],
1054
+ [
1055
+ 0.5555555555555556,
1056
+ "#d8576b"
1057
+ ],
1058
+ [
1059
+ 0.6666666666666666,
1060
+ "#ed7953"
1061
+ ],
1062
+ [
1063
+ 0.7777777777777778,
1064
+ "#fb9f3a"
1065
+ ],
1066
+ [
1067
+ 0.8888888888888888,
1068
+ "#fdca26"
1069
+ ],
1070
+ [
1071
+ 1,
1072
+ "#f0f921"
1073
+ ]
1074
+ ]
1075
+ },
1076
+ "colorway": [
1077
+ "#636efa",
1078
+ "#EF553B",
1079
+ "#00cc96",
1080
+ "#ab63fa",
1081
+ "#FFA15A",
1082
+ "#19d3f3",
1083
+ "#FF6692",
1084
+ "#B6E880",
1085
+ "#FF97FF",
1086
+ "#FECB52"
1087
+ ],
1088
+ "font": {
1089
+ "color": "#2a3f5f"
1090
+ },
1091
+ "geo": {
1092
+ "bgcolor": "white",
1093
+ "lakecolor": "white",
1094
+ "landcolor": "white",
1095
+ "showlakes": true,
1096
+ "showland": true,
1097
+ "subunitcolor": "#C8D4E3"
1098
+ },
1099
+ "hoverlabel": {
1100
+ "align": "left"
1101
+ },
1102
+ "hovermode": "closest",
1103
+ "mapbox": {
1104
+ "style": "light"
1105
+ },
1106
+ "paper_bgcolor": "white",
1107
+ "plot_bgcolor": "white",
1108
+ "polar": {
1109
+ "angularaxis": {
1110
+ "gridcolor": "#EBF0F8",
1111
+ "linecolor": "#EBF0F8",
1112
+ "ticks": ""
1113
+ },
1114
+ "bgcolor": "white",
1115
+ "radialaxis": {
1116
+ "gridcolor": "#EBF0F8",
1117
+ "linecolor": "#EBF0F8",
1118
+ "ticks": ""
1119
+ }
1120
+ },
1121
+ "scene": {
1122
+ "xaxis": {
1123
+ "backgroundcolor": "white",
1124
+ "gridcolor": "#DFE8F3",
1125
+ "gridwidth": 2,
1126
+ "linecolor": "#EBF0F8",
1127
+ "showbackground": true,
1128
+ "ticks": "",
1129
+ "zerolinecolor": "#EBF0F8"
1130
+ },
1131
+ "yaxis": {
1132
+ "backgroundcolor": "white",
1133
+ "gridcolor": "#DFE8F3",
1134
+ "gridwidth": 2,
1135
+ "linecolor": "#EBF0F8",
1136
+ "showbackground": true,
1137
+ "ticks": "",
1138
+ "zerolinecolor": "#EBF0F8"
1139
+ },
1140
+ "zaxis": {
1141
+ "backgroundcolor": "white",
1142
+ "gridcolor": "#DFE8F3",
1143
+ "gridwidth": 2,
1144
+ "linecolor": "#EBF0F8",
1145
+ "showbackground": true,
1146
+ "ticks": "",
1147
+ "zerolinecolor": "#EBF0F8"
1148
+ }
1149
+ },
1150
+ "shapedefaults": {
1151
+ "line": {
1152
+ "color": "#2a3f5f"
1153
+ }
1154
+ },
1155
+ "ternary": {
1156
+ "aaxis": {
1157
+ "gridcolor": "#DFE8F3",
1158
+ "linecolor": "#A2B1C6",
1159
+ "ticks": ""
1160
+ },
1161
+ "baxis": {
1162
+ "gridcolor": "#DFE8F3",
1163
+ "linecolor": "#A2B1C6",
1164
+ "ticks": ""
1165
+ },
1166
+ "bgcolor": "white",
1167
+ "caxis": {
1168
+ "gridcolor": "#DFE8F3",
1169
+ "linecolor": "#A2B1C6",
1170
+ "ticks": ""
1171
+ }
1172
+ },
1173
+ "title": {
1174
+ "x": 0.05
1175
+ },
1176
+ "xaxis": {
1177
+ "automargin": true,
1178
+ "gridcolor": "#EBF0F8",
1179
+ "linecolor": "#EBF0F8",
1180
+ "ticks": "",
1181
+ "title": {
1182
+ "standoff": 15
1183
+ },
1184
+ "zerolinecolor": "#EBF0F8",
1185
+ "zerolinewidth": 2
1186
+ },
1187
+ "yaxis": {
1188
+ "automargin": true,
1189
+ "gridcolor": "#EBF0F8",
1190
+ "linecolor": "#EBF0F8",
1191
+ "ticks": "",
1192
+ "title": {
1193
+ "standoff": 15
1194
+ },
1195
+ "zerolinecolor": "#EBF0F8",
1196
+ "zerolinewidth": 2
1197
+ }
1198
+ }
1199
+ },
1200
+ "title": {
1201
+ "text": "Labels Distribution"
1202
+ },
1203
+ "xaxis": {
1204
+ "anchor": "y",
1205
+ "domain": [
1206
+ 0,
1207
+ 1
1208
+ ],
1209
+ "title": {
1210
+ "text": "Label"
1211
+ }
1212
+ },
1213
+ "yaxis": {
1214
+ "anchor": "x",
1215
+ "domain": [
1216
+ 0,
1217
+ 1
1218
+ ],
1219
+ "title": {
1220
+ "text": "Count"
1221
+ }
1222
+ }
1223
+ }
1224
+ },
1225
+ "text/html": [
1226
+ "<div> <div id=\"f9b15681-d1a5-42e5-8bc5-eeb80fa77381\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div> <script type=\"text/javascript\"> require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById(\"f9b15681-d1a5-42e5-8bc5-eeb80fa77381\")) { Plotly.newPlot( \"f9b15681-d1a5-42e5-8bc5-eeb80fa77381\", [{\"alignmentgroup\":\"True\",\"hovertemplate\":\"x=%{x}<br>y=%{y}<br>text=%{text}<br>color=%{marker.color}<extra></extra>\",\"legendgroup\":\"\",\"marker\":{\"color\":[153,150,149,139,138,136,131,128,117,115],\"coloraxis\":\"coloraxis\",\"pattern\":{\"shape\":\"\"},\"line\":{\"color\":\"black\",\"width\":1.5}},\"name\":\"\",\"offsetgroup\":\"\",\"orientation\":\"v\",\"showlegend\":false,\"text\":[153.0,150.0,149.0,139.0,138.0,136.0,131.0,128.0,117.0,115.0],\"textposition\":\"auto\",\"x\":[\"ATALA\",\"ARCIGERA FLOWER MOTH\",\"BANDED ORANGE HELICONIAN\",\"ATLAS MOTH\",\"APPOLLO\",\"ADONIS\",\"AN 88\",\"BANDED PEACOCK\",\"AFRICAN GIANT SWALLOWTAIL\",\"AMERICAN SNOOT\"],\"xaxis\":\"x\",\"y\":[153,150,149,139,138,136,131,128,117,115],\"yaxis\":\"y\",\"type\":\"bar\",\"opacity\":0.8}], {\"template\":{\"data\":{\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"white\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"bar\":[{\"error_x\":{\"color\":\"#2a3f5f\"},\"error_y\":{\"color\":\"#2a3f5f\"},\"marker\":{\"line\":{\"color\":\"white\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"#C8D4E3\",\"linecolor\":\"#C8D4E3\",\"minorgridcolor\":\"#C8D4E3\",\"startlinecolor\":\"#2a3f5f\"},\"baxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"#C8D4E3\",\"linecolor\":\"#C8D4E3\",\"minorgridcolor\":\"#C8D4E3\",\"startlinecolor\":\"#2a3f5f\"},\"type\":\"carpet\"}],\"choropleth\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"type\":\"choropleth\"}],\"contourcarpet\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"type\":\"contourcarpet\"}],\"contour\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"contour\"}],\"heatmapgl\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"heatmapgl\"}],\"heatmap\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"heatmap\"}],\"histogram2dcontour\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"histogram2dcontour\"}],\"histogram2d\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"histogram2d\"}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"mesh3d\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"type\":\"mesh3d\"}],\"parcoords\":[{\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"parcoords\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}],\"scatter3d\":[{\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatter3d\"}],\"scattercarpet\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattercarpet\"}],\"scattergeo\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattergeo\"}],\"scattergl\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattergl\"}],\"scattermapbox\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scattermapbox\"}],\"scatterpolargl\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatterpolargl\"}],\"scatterpolar\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatterpolar\"}],\"scatter\":[{\"fillpattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2},\"type\":\"scatter\"}],\"scatterternary\":[{\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"type\":\"scatterternary\"}],\"surface\":[{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"type\":\"surface\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#EBF0F8\"},\"line\":{\"color\":\"white\"}},\"header\":{\"fill\":{\"color\":\"#C8D4E3\"},\"line\":{\"color\":\"white\"}},\"type\":\"table\"}]},\"layout\":{\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"autotypenumbers\":\"strict\",\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]],\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]},\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#2a3f5f\"},\"geo\":{\"bgcolor\":\"white\",\"lakecolor\":\"white\",\"landcolor\":\"white\",\"showlakes\":true,\"showland\":true,\"subunitcolor\":\"#C8D4E3\"},\"hoverlabel\":{\"align\":\"left\"},\"hovermode\":\"closest\",\"mapbox\":{\"style\":\"light\"},\"paper_bgcolor\":\"white\",\"plot_bgcolor\":\"white\",\"polar\":{\"angularaxis\":{\"gridcolor\":\"#EBF0F8\",\"linecolor\":\"#EBF0F8\",\"ticks\":\"\"},\"bgcolor\":\"white\",\"radialaxis\":{\"gridcolor\":\"#EBF0F8\",\"linecolor\":\"#EBF0F8\",\"ticks\":\"\"}},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"white\",\"gridcolor\":\"#DFE8F3\",\"gridwidth\":2,\"linecolor\":\"#EBF0F8\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"#EBF0F8\"},\"yaxis\":{\"backgroundcolor\":\"white\",\"gridcolor\":\"#DFE8F3\",\"gridwidth\":2,\"linecolor\":\"#EBF0F8\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"#EBF0F8\"},\"zaxis\":{\"backgroundcolor\":\"white\",\"gridcolor\":\"#DFE8F3\",\"gridwidth\":2,\"linecolor\":\"#EBF0F8\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"#EBF0F8\"}},\"shapedefaults\":{\"line\":{\"color\":\"#2a3f5f\"}},\"ternary\":{\"aaxis\":{\"gridcolor\":\"#DFE8F3\",\"linecolor\":\"#A2B1C6\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"#DFE8F3\",\"linecolor\":\"#A2B1C6\",\"ticks\":\"\"},\"bgcolor\":\"white\",\"caxis\":{\"gridcolor\":\"#DFE8F3\",\"linecolor\":\"#A2B1C6\",\"ticks\":\"\"}},\"title\":{\"x\":0.05},\"xaxis\":{\"automargin\":true,\"gridcolor\":\"#EBF0F8\",\"linecolor\":\"#EBF0F8\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"#EBF0F8\",\"zerolinewidth\":2},\"yaxis\":{\"automargin\":true,\"gridcolor\":\"#EBF0F8\",\"linecolor\":\"#EBF0F8\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"#EBF0F8\",\"zerolinewidth\":2}}},\"xaxis\":{\"anchor\":\"y\",\"domain\":[0.0,1.0],\"title\":{\"text\":\"Label\"}},\"yaxis\":{\"anchor\":\"x\",\"domain\":[0.0,1.0],\"title\":{\"text\":\"Count\"}},\"coloraxis\":{\"colorbar\":{\"title\":{\"text\":\"color\"}},\"colorscale\":[[0.0,\"rgb(247,251,255)\"],[0.125,\"rgb(222,235,247)\"],[0.25,\"rgb(198,219,239)\"],[0.375,\"rgb(158,202,225)\"],[0.5,\"rgb(107,174,214)\"],[0.625,\"rgb(66,146,198)\"],[0.75,\"rgb(33,113,181)\"],[0.875,\"rgb(8,81,156)\"],[1.0,\"rgb(8,48,107)\"]]},\"legend\":{\"tracegroupgap\":0},\"margin\":{\"t\":60},\"barmode\":\"relative\",\"title\":{\"text\":\"Labels Distribution\"}}, {\"responsive\": true} ).then(function(){\n",
1227
+ " \n",
1228
+ "var gd = document.getElementById('f9b15681-d1a5-42e5-8bc5-eeb80fa77381');\n",
1229
+ "var x = new MutationObserver(function (mutations, observer) {{\n",
1230
+ " var display = window.getComputedStyle(gd).display;\n",
1231
+ " if (!display || display === 'none') {{\n",
1232
+ " console.log([gd, 'removed!']);\n",
1233
+ " Plotly.purge(gd);\n",
1234
+ " observer.disconnect();\n",
1235
+ " }}\n",
1236
+ "}});\n",
1237
+ "\n",
1238
+ "// Listen for the removal of the full notebook cells\n",
1239
+ "var notebookContainer = gd.closest('#notebook-container');\n",
1240
+ "if (notebookContainer) {{\n",
1241
+ " x.observe(notebookContainer, {childList: true});\n",
1242
+ "}}\n",
1243
+ "\n",
1244
+ "// Listen for the clearing of the current output cell\n",
1245
+ "var outputEl = gd.closest('.output');\n",
1246
+ "if (outputEl) {{\n",
1247
+ " x.observe(outputEl, {childList: true});\n",
1248
+ "}}\n",
1249
+ "\n",
1250
+ " }) }; }); </script> </div>"
1251
+ ]
1252
+ },
1253
+ "metadata": {},
1254
+ "output_type": "display_data"
1255
+ }
1256
+ ],
1257
+ "source": [
1258
+ "label_counts = df['labels'].value_counts()[:10]\n",
1259
+ "\n",
1260
+ "fig = px.bar(x=label_counts.index, \n",
1261
+ " y=label_counts.values,\n",
1262
+ " color=label_counts.values,\n",
1263
+ " text=label_counts.values,\n",
1264
+ " color_continuous_scale='Blues')\n",
1265
+ "\n",
1266
+ "fig.update_layout(\n",
1267
+ " title_text='Labels Distribution',\n",
1268
+ " template='plotly_white',\n",
1269
+ " xaxis=dict(\n",
1270
+ " title='Label',\n",
1271
+ " ),\n",
1272
+ " yaxis=dict(\n",
1273
+ " title='Count',\n",
1274
+ " )\n",
1275
+ ")\n",
1276
+ "\n",
1277
+ "fig.update_traces(marker_line_color='black', \n",
1278
+ " marker_line_width=1.5, \n",
1279
+ " opacity=0.8)\n",
1280
+ " \n",
1281
+ "fig.show()"
1282
+ ]
1283
+ },
1284
+ {
1285
+ "cell_type": "markdown",
1286
+ "id": "40cae06a",
1287
+ "metadata": {
1288
+ "papermill": {
1289
+ "duration": 0.045333,
1290
+ "end_time": "2023-09-03T09:54:44.387581",
1291
+ "exception": false,
1292
+ "start_time": "2023-09-03T09:54:44.342248",
1293
+ "status": "completed"
1294
+ },
1295
+ "tags": []
1296
+ },
1297
+ "source": [
1298
+ "# Generate Image using ImageDataGenerator"
1299
+ ]
1300
+ },
1301
+ {
1302
+ "cell_type": "code",
1303
+ "execution_count": 5,
1304
+ "id": "9c49b50f",
1305
+ "metadata": {
1306
+ "execution": {
1307
+ "iopub.execute_input": "2023-09-03T09:54:44.571283Z",
1308
+ "iopub.status.busy": "2023-09-03T09:54:44.570890Z",
1309
+ "iopub.status.idle": "2023-09-03T09:54:47.843050Z",
1310
+ "shell.execute_reply": "2023-09-03T09:54:47.842111Z"
1311
+ },
1312
+ "papermill": {
1313
+ "duration": 3.322283,
1314
+ "end_time": "2023-09-03T09:54:47.845125",
1315
+ "exception": false,
1316
+ "start_time": "2023-09-03T09:54:44.522842",
1317
+ "status": "completed"
1318
+ },
1319
+ "tags": []
1320
+ },
1321
+ "outputs": [
1322
+ {
1323
+ "name": "stdout",
1324
+ "output_type": "stream",
1325
+ "text": [
1326
+ "Found 1256 images belonging to 10 classes.\n",
1327
+ "Found 50 images belonging to 10 classes.\n"
1328
+ ]
1329
+ }
1330
+ ],
1331
+ "source": [
1332
+ "# only train data needs to be augmented \n",
1333
+ "train_gen = ImageDataGenerator(horizontal_flip=True, vertical_flip=True, rescale=1/255.)\n",
1334
+ "val_gen = ImageDataGenerator(rescale=1/255.)\n",
1335
+ "\n",
1336
+ "train_dir = 'C:/Users/kamel/Documents/Image Classification/butterfly-dataset/train'\n",
1337
+ "val_dir = 'C:/Users/kamel/Documents/Image Classification/butterfly-dataset/valid'\n",
1338
+ "\n",
1339
+ "BATCH_SIZE = 16\n",
1340
+ "SEED = 56\n",
1341
+ "IMAGE_SIZE = (244, 244)\n",
1342
+ "\n",
1343
+ "train_flow_gen = train_gen.flow_from_directory(directory=train_dir,\n",
1344
+ " class_mode='sparse',\n",
1345
+ " batch_size=BATCH_SIZE,\n",
1346
+ " target_size=IMAGE_SIZE,\n",
1347
+ " seed=SEED)\n",
1348
+ "\n",
1349
+ "val_flow_gen = val_gen.flow_from_directory(directory=val_dir,\n",
1350
+ " class_mode='sparse',\n",
1351
+ " batch_size=BATCH_SIZE,\n",
1352
+ " target_size=IMAGE_SIZE,\n",
1353
+ " seed=SEED)"
1354
+ ]
1355
+ },
1356
+ {
1357
+ "cell_type": "markdown",
1358
+ "id": "0398ba07",
1359
+ "metadata": {
1360
+ "papermill": {
1361
+ "duration": 0.045878,
1362
+ "end_time": "2023-09-03T09:54:47.938297",
1363
+ "exception": false,
1364
+ "start_time": "2023-09-03T09:54:47.892419",
1365
+ "status": "completed"
1366
+ },
1367
+ "tags": []
1368
+ },
1369
+ "source": [
1370
+ "# Create Model"
1371
+ ]
1372
+ },
1373
+ {
1374
+ "cell_type": "code",
1375
+ "execution_count": 6,
1376
+ "id": "2b80bd86",
1377
+ "metadata": {
1378
+ "execution": {
1379
+ "iopub.execute_input": "2023-09-03T09:54:48.123906Z",
1380
+ "iopub.status.busy": "2023-09-03T09:54:48.122767Z",
1381
+ "iopub.status.idle": "2023-09-03T09:54:48.130732Z",
1382
+ "shell.execute_reply": "2023-09-03T09:54:48.129884Z"
1383
+ },
1384
+ "papermill": {
1385
+ "duration": 0.058368,
1386
+ "end_time": "2023-09-03T09:54:48.132785",
1387
+ "exception": false,
1388
+ "start_time": "2023-09-03T09:54:48.074417",
1389
+ "status": "completed"
1390
+ },
1391
+ "tags": []
1392
+ },
1393
+ "outputs": [],
1394
+ "source": [
1395
+ "verbose=False\n",
1396
+ " \n",
1397
+ "input_tensor = Input(shape=(224, 224, 3))\n",
1398
+ " \n",
1399
+ "base_model = ResNet50V2(input_tensor=input_tensor, include_top=False, weights='imagenet')\n",
1400
+ " \n",
1401
+ "bm_output = base_model.output\n",
1402
+ "\n",
1403
+ "x = GlobalAveragePooling2D()(bm_output)\n",
1404
+ "x = Dense(1024, activation='relu')(x)\n",
1405
+ "x = Dropout(rate=0.5)(x)\n",
1406
+ "output = Dense(100, activation='softmax')(x)\n",
1407
+ "model = Model(inputs=input_tensor, outputs=output)\n",
1408
+ " \n",
1409
+ "if verbose:\n",
1410
+ " model.summary()"
1411
+ ]
1412
+ },
1413
+ {
1414
+ "cell_type": "markdown",
1415
+ "id": "c28b3bd4",
1416
+ "metadata": {
1417
+ "papermill": {
1418
+ "duration": 0.327423,
1419
+ "end_time": "2023-09-03T10:55:37.594519",
1420
+ "exception": false,
1421
+ "start_time": "2023-09-03T10:55:37.267096",
1422
+ "status": "completed"
1423
+ },
1424
+ "tags": []
1425
+ },
1426
+ "source": [
1427
+ "# ResNet Modelling"
1428
+ ]
1429
+ },
1430
+ {
1431
+ "cell_type": "code",
1432
+ "execution_count": 7,
1433
+ "id": "e1087e22",
1434
+ "metadata": {
1435
+ "execution": {
1436
+ "iopub.execute_input": "2023-09-03T10:55:38.752875Z",
1437
+ "iopub.status.busy": "2023-09-03T10:55:38.752385Z",
1438
+ "iopub.status.idle": "2023-09-03T10:55:41.001254Z",
1439
+ "shell.execute_reply": "2023-09-03T10:55:41.000298Z"
1440
+ },
1441
+ "papermill": {
1442
+ "duration": 2.573106,
1443
+ "end_time": "2023-09-03T10:55:41.003664",
1444
+ "exception": false,
1445
+ "start_time": "2023-09-03T10:55:38.430558",
1446
+ "status": "completed"
1447
+ },
1448
+ "tags": []
1449
+ },
1450
+ "outputs": [],
1451
+ "source": [
1452
+ "model.compile(optimizer=Adam(lr=0.001), loss='sparse_categorical_crossentropy', metrics=['accuracy'])\n",
1453
+ "\n",
1454
+ "rlr_cb = ReduceLROnPlateau(monitor='val_loss', factor=0.2, patience=3, mode='min', verbose=0)\n",
1455
+ "early_cb = EarlyStopping(monitor='val_loss', patience=5, mode='min', verbose=0)"
1456
+ ]
1457
+ },
1458
+ {
1459
+ "cell_type": "code",
1460
+ "execution_count": 10,
1461
+ "id": "19196570",
1462
+ "metadata": {
1463
+ "execution": {
1464
+ "iopub.execute_input": "2023-09-03T10:55:41.562460Z",
1465
+ "iopub.status.busy": "2023-09-03T10:55:41.562088Z",
1466
+ "iopub.status.idle": "2023-09-03T11:28:47.817367Z",
1467
+ "shell.execute_reply": "2023-09-03T11:28:47.816362Z"
1468
+ },
1469
+ "papermill": {
1470
+ "duration": 1986.53774,
1471
+ "end_time": "2023-09-03T11:28:47.819746",
1472
+ "exception": false,
1473
+ "start_time": "2023-09-03T10:55:41.282006",
1474
+ "status": "completed"
1475
+ },
1476
+ "tags": []
1477
+ },
1478
+ "outputs": [
1479
+ {
1480
+ "name": "stdout",
1481
+ "output_type": "stream",
1482
+ "text": [
1483
+ "Epoch 1/5\n",
1484
+ "79/79 [==============================] - 661s 8s/step - loss: 1.2424 - accuracy: 0.6815 - val_loss: 76.2388 - val_accuracy: 0.1400 - lr: 0.0010\n",
1485
+ "Epoch 2/5\n",
1486
+ "79/79 [==============================] - 686s 9s/step - loss: 0.6616 - accuracy: 0.8169 - val_loss: 3.6352 - val_accuracy: 0.6000 - lr: 0.0010\n",
1487
+ "Epoch 3/5\n",
1488
+ "79/79 [==============================] - 692s 9s/step - loss: 0.4898 - accuracy: 0.8583 - val_loss: 6.5402 - val_accuracy: 0.3800 - lr: 0.0010\n",
1489
+ "Epoch 4/5\n",
1490
+ "79/79 [==============================] - 699s 9s/step - loss: 0.4228 - accuracy: 0.8933 - val_loss: 0.5610 - val_accuracy: 0.8200 - lr: 0.0010\n",
1491
+ "Epoch 5/5\n",
1492
+ "79/79 [==============================] - 694s 9s/step - loss: 0.2828 - accuracy: 0.9132 - val_loss: 0.0705 - val_accuracy: 0.9800 - lr: 0.0010\n"
1493
+ ]
1494
+ },
1495
+ {
1496
+ "data": {
1497
+ "text/plain": [
1498
+ "<keras.callbacks.History at 0x2569b583a00>"
1499
+ ]
1500
+ },
1501
+ "execution_count": 10,
1502
+ "metadata": {},
1503
+ "output_type": "execute_result"
1504
+ }
1505
+ ],
1506
+ "source": [
1507
+ "model.fit(train_flow_gen, epochs=5,\n",
1508
+ " steps_per_epoch=int(np.ceil(train_df.shape[0]/BATCH_SIZE)),\n",
1509
+ " validation_data=val_flow_gen,\n",
1510
+ " validation_steps=int(np.ceil(val_df.shape[0]/BATCH_SIZE)),\n",
1511
+ " callbacks=[rlr_cb, early_cb])"
1512
+ ]
1513
+ },
1514
+ {
1515
+ "cell_type": "code",
1516
+ "execution_count": 12,
1517
+ "id": "a7fdf171",
1518
+ "metadata": {},
1519
+ "outputs": [
1520
+ {
1521
+ "name": "stdout",
1522
+ "output_type": "stream",
1523
+ "text": [
1524
+ "Found 50 images belonging to 10 classes.\n"
1525
+ ]
1526
+ }
1527
+ ],
1528
+ "source": [
1529
+ "test_dir = 'C:/Users/kamel/Documents/Image Classification/butterfly-dataset/test'\n",
1530
+ "test_gen = ImageDataGenerator(rescale=1/255.)\n",
1531
+ "test_flow_gen = test_gen.flow_from_directory(directory=test_dir,\n",
1532
+ " class_mode='sparse',\n",
1533
+ " batch_size=BATCH_SIZE,\n",
1534
+ " target_size=IMAGE_SIZE,\n",
1535
+ " seed=SEED)"
1536
+ ]
1537
+ },
1538
+ {
1539
+ "cell_type": "code",
1540
+ "execution_count": 13,
1541
+ "id": "f5ac91bb",
1542
+ "metadata": {
1543
+ "execution": {
1544
+ "iopub.execute_input": "2023-09-03T11:28:48.864295Z",
1545
+ "iopub.status.busy": "2023-09-03T11:28:48.863901Z",
1546
+ "iopub.status.idle": "2023-09-03T11:28:54.311623Z",
1547
+ "shell.execute_reply": "2023-09-03T11:28:54.310452Z"
1548
+ },
1549
+ "papermill": {
1550
+ "duration": 5.996544,
1551
+ "end_time": "2023-09-03T11:28:54.313850",
1552
+ "exception": false,
1553
+ "start_time": "2023-09-03T11:28:48.317306",
1554
+ "status": "completed"
1555
+ },
1556
+ "tags": []
1557
+ },
1558
+ "outputs": [
1559
+ {
1560
+ "name": "stdout",
1561
+ "output_type": "stream",
1562
+ "text": [
1563
+ "4/4 [==============================] - 5s 1s/step - loss: 0.1499 - accuracy: 0.9400\n",
1564
+ "ResNet Test Data Accuracy: 0.9399999976158142\n"
1565
+ ]
1566
+ }
1567
+ ],
1568
+ "source": [
1569
+ "print('ResNet Test Data Accuracy: {0}'.format(model.evaluate(test_flow_gen)[1:][0]))"
1570
+ ]
1571
+ },
1572
+ {
1573
+ "cell_type": "code",
1574
+ "execution_count": 14,
1575
+ "id": "78b5d06a",
1576
+ "metadata": {},
1577
+ "outputs": [],
1578
+ "source": [
1579
+ "# Save the current weights manually\n",
1580
+ "model.save('C:/Users/kamel/Documents/Image Classification/model_checkpoint_manual_effnet.h5')"
1581
+ ]
1582
+ },
1583
+ {
1584
+ "cell_type": "markdown",
1585
+ "id": "0a9e58e9",
1586
+ "metadata": {},
1587
+ "source": [
1588
+ "# Deployment"
1589
+ ]
1590
+ },
1591
+ {
1592
+ "cell_type": "code",
1593
+ "execution_count": 4,
1594
+ "id": "72ab47ea",
1595
+ "metadata": {},
1596
+ "outputs": [
1597
+ {
1598
+ "name": "stdout",
1599
+ "output_type": "stream",
1600
+ "text": [
1601
+ "Running on local URL: http://127.0.0.1:7861\n",
1602
+ "\n",
1603
+ "To create a public link, set `share=True` in `launch()`.\n"
1604
+ ]
1605
+ },
1606
+ {
1607
+ "data": {
1608
+ "text/html": [
1609
+ "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
1610
+ ],
1611
+ "text/plain": [
1612
+ "<IPython.core.display.HTML object>"
1613
+ ]
1614
+ },
1615
+ "metadata": {},
1616
+ "output_type": "display_data"
1617
+ },
1618
+ {
1619
+ "data": {
1620
+ "text/plain": []
1621
+ },
1622
+ "execution_count": 4,
1623
+ "metadata": {},
1624
+ "output_type": "execute_result"
1625
+ },
1626
+ {
1627
+ "name": "stdout",
1628
+ "output_type": "stream",
1629
+ "text": [
1630
+ "1/1 [==============================] - 1s 1s/step\n"
1631
+ ]
1632
+ },
1633
+ {
1634
+ "name": "stderr",
1635
+ "output_type": "stream",
1636
+ "text": [
1637
+ "Traceback (most recent call last):\n",
1638
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\gradio\\queueing.py\", line 495, in call_prediction\n",
1639
+ " output = await route_utils.call_process_api(\n",
1640
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\gradio\\route_utils.py\", line 232, in call_process_api\n",
1641
+ " output = await app.get_blocks().process_api(\n",
1642
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\gradio\\blocks.py\", line 1561, in process_api\n",
1643
+ " result = await self.call_function(\n",
1644
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\gradio\\blocks.py\", line 1179, in call_function\n",
1645
+ " prediction = await anyio.to_thread.run_sync(\n",
1646
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\anyio\\to_thread.py\", line 28, in run_sync\n",
1647
+ " return await get_asynclib().run_sync_in_worker_thread(func, *args, cancellable=cancellable,\n",
1648
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\anyio\\_backends\\_asyncio.py\", line 818, in run_sync_in_worker_thread\n",
1649
+ " return await future\n",
1650
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\anyio\\_backends\\_asyncio.py\", line 754, in run\n",
1651
+ " result = context.run(func, *args)\n",
1652
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\gradio\\utils.py\", line 678, in wrapper\n",
1653
+ " response = f(*args, **kwargs)\n",
1654
+ " File \"C:\\Users\\kamel\\AppData\\Local\\Temp\\ipykernel_9500\\3770787755.py\", line 35, in classify_image\n",
1655
+ " img = preprocess_image(img)\n",
1656
+ " File \"C:\\Users\\kamel\\AppData\\Local\\Temp\\ipykernel_9500\\3770787755.py\", line 28, in preprocess_image\n",
1657
+ " raise ValueError(\"Unsupported input type. Please provide a file path or a NumPy array.\")\n",
1658
+ "ValueError: Unsupported input type. Please provide a file path or a NumPy array.\n"
1659
+ ]
1660
+ },
1661
+ {
1662
+ "name": "stdout",
1663
+ "output_type": "stream",
1664
+ "text": [
1665
+ "1/1 [==============================] - 0s 131ms/step\n"
1666
+ ]
1667
+ },
1668
+ {
1669
+ "name": "stderr",
1670
+ "output_type": "stream",
1671
+ "text": [
1672
+ "Traceback (most recent call last):\n",
1673
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\gradio\\queueing.py\", line 495, in call_prediction\n",
1674
+ " output = await route_utils.call_process_api(\n",
1675
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\gradio\\route_utils.py\", line 232, in call_process_api\n",
1676
+ " output = await app.get_blocks().process_api(\n",
1677
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\gradio\\blocks.py\", line 1561, in process_api\n",
1678
+ " result = await self.call_function(\n",
1679
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\gradio\\blocks.py\", line 1179, in call_function\n",
1680
+ " prediction = await anyio.to_thread.run_sync(\n",
1681
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\anyio\\to_thread.py\", line 28, in run_sync\n",
1682
+ " return await get_asynclib().run_sync_in_worker_thread(func, *args, cancellable=cancellable,\n",
1683
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\anyio\\_backends\\_asyncio.py\", line 818, in run_sync_in_worker_thread\n",
1684
+ " return await future\n",
1685
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\anyio\\_backends\\_asyncio.py\", line 754, in run\n",
1686
+ " result = context.run(func, *args)\n",
1687
+ " File \"D:\\Software\\anaconda3\\lib\\site-packages\\gradio\\utils.py\", line 678, in wrapper\n",
1688
+ " response = f(*args, **kwargs)\n",
1689
+ " File \"C:\\Users\\kamel\\AppData\\Local\\Temp\\ipykernel_9500\\3770787755.py\", line 35, in classify_image\n",
1690
+ " img = preprocess_image(img)\n",
1691
+ " File \"C:\\Users\\kamel\\AppData\\Local\\Temp\\ipykernel_9500\\3770787755.py\", line 28, in preprocess_image\n",
1692
+ " raise ValueError(\"Unsupported input type. Please provide a file path or a NumPy array.\")\n",
1693
+ "ValueError: Unsupported input type. Please provide a file path or a NumPy array.\n"
1694
+ ]
1695
+ }
1696
+ ],
1697
+ "source": [
1698
+ "import gradio as gr\n",
1699
+ "import tensorflow as tf\n",
1700
+ "from tensorflow.keras.models import load_model\n",
1701
+ "import numpy as np\n",
1702
+ "import cv2\n",
1703
+ "\n",
1704
+ "# Load the trained model\n",
1705
+ "model_path = 'C:/Users/kamel/Documents/Image Classification/model_checkpoint_manual_effnet.h5'\n",
1706
+ "model = load_model(model_path)\n",
1707
+ "\n",
1708
+ "class_names = ['ADONIS', 'AFRICAN GIANT SWALLOWTAIL', 'AMERICAN SNOOT', 'AN 88', 'APPOLLO', 'ARCIGERA FLOWER MOTH', 'ATALA', 'ATLAS MOTH', 'BANDED ORANGE HELICONIAN', 'BANDED PEACOCK']\n",
1709
+ "\n",
1710
+ "# Define a function to preprocess the input image\n",
1711
+ "def preprocess_image(img):\n",
1712
+ " # Check if img is a file path or an image object\n",
1713
+ " if isinstance(img, str):\n",
1714
+ " # Load and preprocess the image\n",
1715
+ " img = cv2.imread(img)\n",
1716
+ " img = cv2.resize(img, (224, 224))\n",
1717
+ " img = img / 255.0 # Normalize pixel values\n",
1718
+ " img = np.expand_dims(img, axis=0) # Add batch dimension\n",
1719
+ " elif isinstance(img, np.ndarray):\n",
1720
+ " # If img is already an image array, resize it\n",
1721
+ " img = cv2.resize(img, (224, 224))\n",
1722
+ " img = img / 255.0 # Normalize pixel values\n",
1723
+ " img = np.expand_dims(img, axis=0) # Add batch dimension\n",
1724
+ " else:\n",
1725
+ " raise ValueError(\"Unsupported input type. Please provide a file path or a NumPy array.\")\n",
1726
+ "\n",
1727
+ " return img\n",
1728
+ "\n",
1729
+ "# Define the classification function\n",
1730
+ "def classify_image(img):\n",
1731
+ " # Preprocess the image\n",
1732
+ " img = preprocess_image(img)\n",
1733
+ " \n",
1734
+ " # Make predictions\n",
1735
+ " predictions = model.predict(img)\n",
1736
+ " \n",
1737
+ " # Get the predicted class label\n",
1738
+ " predicted_class = np.argmax(predictions)\n",
1739
+ " \n",
1740
+ " # Get the predicted class name\n",
1741
+ " predicted_class_name = class_names[predicted_class]\n",
1742
+ " \n",
1743
+ " return f\"Predicted Class: {predicted_class_name}\"\n",
1744
+ "\n",
1745
+ "# Create a Gradio interface\n",
1746
+ "iface = gr.Interface(fn=classify_image, \n",
1747
+ " inputs=\"image\",\n",
1748
+ " outputs=\"text\",\n",
1749
+ " live=True)\n",
1750
+ "\n",
1751
+ "# Launch the Gradio app\n",
1752
+ "iface.launch()\n"
1753
+ ]
1754
+ },
1755
+ {
1756
+ "cell_type": "code",
1757
+ "execution_count": null,
1758
+ "id": "b97686a4",
1759
+ "metadata": {},
1760
+ "outputs": [],
1761
+ "source": []
1762
+ }
1763
+ ],
1764
+ "metadata": {
1765
+ "kernelspec": {
1766
+ "display_name": "Python 3 (ipykernel)",
1767
+ "language": "python",
1768
+ "name": "python3"
1769
+ },
1770
+ "language_info": {
1771
+ "codemirror_mode": {
1772
+ "name": "ipython",
1773
+ "version": 3
1774
+ },
1775
+ "file_extension": ".py",
1776
+ "mimetype": "text/x-python",
1777
+ "name": "python",
1778
+ "nbconvert_exporter": "python",
1779
+ "pygments_lexer": "ipython3",
1780
+ "version": "3.9.18"
1781
+ },
1782
+ "papermill": {
1783
+ "default_parameters": {},
1784
+ "duration": 5680.107554,
1785
+ "end_time": "2023-09-03T11:29:02.521595",
1786
+ "environment_variables": {},
1787
+ "exception": null,
1788
+ "input_path": "__notebook__.ipynb",
1789
+ "output_path": "__notebook__.ipynb",
1790
+ "parameters": {},
1791
+ "start_time": "2023-09-03T09:54:22.414041",
1792
+ "version": "2.4.0"
1793
+ }
1794
+ },
1795
+ "nbformat": 4,
1796
+ "nbformat_minor": 5
1797
+ }