@@ -90,11 +90,6 @@ First, let's import the required dependencies:
90
90
91
91
albumentations are already installed
92
92
93
-
94
-
95
-
96
- .. GENERATED FROM PYTHON SOURCE LINES 93-100
97
-
98
93
VGG Configuration
99
94
-----------------
100
95
@@ -103,8 +98,6 @@ We use the CIFAR100 dataset. The authors of the VGG paper scale images ``isotrop
103
98
which means increasing the size of an image while maintaining its proportions,
104
99
preventing distortion and maintaining the consistency of the object.
105
100
106
- .. GENERATED FROM PYTHON SOURCE LINES 100-140
107
-
108
101
.. code-block :: default
109
102
110
103
@@ -146,17 +139,12 @@ preventing distortion and maintaining the consistency of the object.
146
139
147
140
model_layers =None
148
141
149
-
150
- .. GENERATED FROM PYTHON SOURCE LINES 141-147
151
-
152
142
.. note :: In the code above, we have defined the batch size as 32,
153
143
which is recommended for Google Colab. However, if you are
154
144
running this code on a machine with 24GB of GPU memory,
155
145
you can set the batch size to 128. You can modify the batch
156
146
size according to your preference and hardware capabilities.
157
147
158
- .. GENERATED FROM PYTHON SOURCE LINES 149-174
159
-
160
148
Defining the dataset
161
149
--------------------
162
150
@@ -182,9 +170,6 @@ thus improving its performance on both test data and in real-world applications.
182
170
To apply preprocessing, we need to override the CIFAR100 class that we have imported from the
183
171
``torchvision.datasets `` with a custom class:
184
172
185
-
186
- .. GENERATED FROM PYTHON SOURCE LINES 174-227
187
-
188
173
.. code-block :: default
189
174
190
175
@@ -240,9 +225,6 @@ To apply preprocessing, we need to override the CIFAR100 class that we have impo
240
225
img=img.transpose((2,0,1))
241
226
return img, target
242
227
243
-
244
- .. GENERATED FROM PYTHON SOURCE LINES 228-238
245
-
246
228
Define Model
247
229
------------
248
230
@@ -254,8 +236,6 @@ We will use two main components to define the model:
254
236
* ``Config_channels ``: This refers to the number of output channels for each layer.
255
237
* ``Config_kernels ``: This refers to the kernel size (or filter size) for each layer.
256
238
257
- .. GENERATED FROM PYTHON SOURCE LINES 238-266
258
-
259
239
.. code-block :: default
260
240
261
241
@@ -285,13 +265,8 @@ We will use two main components to define the model:
285
265
"E":[3,3,2,3,3,2,3,3,3,3,2,3,3,3,3,2,3,3,3,3,2],
286
266
}
287
267
288
- .. GENERATED FROM PYTHON SOURCE LINES 267-269
289
-
290
268
Next, we define a model class that generates a model with a choice of six versions.
291
269
292
-
293
- .. GENERATED FROM PYTHON SOURCE LINES 269-363
294
-
295
270
.. code-block :: default
296
271
297
272
@@ -300,7 +275,6 @@ Next, we define a model class that generates a model with a choice of six versio
300
275
in_channels = 3
301
276
i = 1
302
277
for out_channels , kernel in zip(cfg_c,cfg_k) :
303
- # print(f"{i} th layer {out_channels} processing")
304
278
if out_channels == "M" :
305
279
feature_extract += [nn.MaxPool2d(kernel,2) ]
306
280
elif out_channels == "LRN":
@@ -372,8 +346,6 @@ Next, we define a model class that generates a model with a choice of six versio
372
346
self.last_xavier+=1
373
347
nn.init.constant_(m.bias, 0)
374
348
375
- .. GENERATED FROM PYTHON SOURCE LINES 364-377
376
-
377
349
Initializing Model Weights
378
350
----------------------------
379
351
@@ -388,8 +360,6 @@ to initialize the model weights. Specifically, we will apply Xavier
388
360
initialization to the first few layers and the last few layers, while using
389
361
random initialization for the remaining layers.
390
362
391
- .. GENERATED FROM PYTHON SOURCE LINES 377-399
392
-
393
363
.. code-block :: default
394
364
395
365
# .. note::
@@ -413,15 +383,11 @@ random initialization for the remaining layers.
413
383
#
414
384
# These values have been found to work well in practice.
415
385
416
- .. GENERATED FROM PYTHON SOURCE LINES 400-405
417
-
418
386
Training the Model
419
387
------------------
420
388
421
389
First, let's define top-k error.
422
390
423
- .. GENERATED FROM PYTHON SOURCE LINES 405-422
424
-
425
391
.. code-block :: default
426
392
427
393
def accuracy(output, target, topk=(1,)):
@@ -439,13 +405,9 @@ First, let's define top-k error.
439
405
res.append(correct_k)
440
406
return res
441
407
442
- .. GENERATED FROM PYTHON SOURCE LINES 423-426
443
-
444
408
Next, we initiate the model and loss function, optimizer and schedulers. In the VGG model,
445
409
they use a softmax output, Momentum Optimizer, and scheduling based on accuracy.
446
410
447
- .. GENERATED FROM PYTHON SOURCE LINES 426-434
448
-
449
411
.. code-block :: default
450
412
451
413
model_version='B'
0 commit comments