# Deep Learning with PyTorch: A 60 Minute Blitz,Training a Classifier

**URL:** <https://discuss.pytorch.org/t/deep-learning-with-pytorch-a-60-minute-blitz-training-a-classifier/30408>\
**Category:** vision\
**Created:** [November 24, 2018, 9:24am UTC](https://discuss.pytorch.org/t/deep-learning-with-pytorch-a-60-minute-blitz-training-a-classifier/30408 "2018-11-24T09:24:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neda](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/neda/32/7779_2.png) [@Neda](https://discuss.pytorch.org/u/Neda)\
**Post date:** [November 24, 2018, 9:24am UTC](https://discuss.pytorch.org/t/deep-learning-with-pytorch-a-60-minute-blitz-training-a-classifier/30408/1 "2018-11-24T09:24:43Z")

</div>

Where weight initialised in the Pytorch tutorial. In the `self.conv1 = nn.Conv2d(3, 6, 5)` layer, there are 6 different kernels (output-feature) but how the value of the kernel assigned? is it weight initialised in `criterion = nn.CrossEntropyLoss()`. any comment will be appreciated.

---

<div class="post-metadata">

**Author:** ![InnovArul](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/innovarul/32/5282_2.png) [@InnovArul](https://discuss.pytorch.org/u/InnovArul)\
**Post date:** [November 24, 2018, 1:28pm UTC](https://discuss.pytorch.org/t/deep-learning-with-pytorch-a-60-minute-blitz-training-a-classifier/30408/2 "2018-11-24T13:28:52Z")

</div>

The weight initialization happens here:

> <https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/conv.py#L41-L47>

---

<div class="post-metadata">

**Author:** ![Neda](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/neda/32/7779_2.png) [@Neda](https://discuss.pytorch.org/u/Neda)\
**Post date:** [December 3, 2018, 6:53pm UTC](https://discuss.pytorch.org/t/deep-learning-with-pytorch-a-60-minute-blitz-training-a-classifier/30408/3 "2018-12-03T18:53:39Z")

</div>

@InnovArul thank you for the link. I still cannot understand how weight initialization happened. For example in the [Tutorial CIFAR10](https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html#sphx-glr-beginner-blitz-cifar10-tutorial-py) could you please tell me where weight initialization happened. I know in the first layer which is conv1 we use 6 filters with the kernel size of 5\*5, but my question is how the values of these kernels specified?

---

<div class="post-metadata">

**Author:** ![RicCu](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/riccu/32/12845_2.png) [@RicCu](https://discuss.pytorch.org/u/RicCu)\
**Post date:** [December 3, 2018, 8:00pm UTC](https://discuss.pytorch.org/t/deep-learning-with-pytorch-a-60-minute-blitz-training-a-classifier/30408/4 "2018-12-03T20:00:15Z")

</div>

They are initialized at the time the Module is instantiated, i.e. `conv1 = nn.Conv2d(3, 6, 5)`, through the `reset_parameters()` method, which is executed as part of the Module’s [` __init__ `](https://pytorch.org/docs/master/_modules/torch/nn/modules/conv.html#_ConvNd). The dimensions of the kernel and bias are set through the module’s [constructor arguments](https://pytorch.org/docs/master/nn.html#conv2d). If you want to change the parameters’ initialization you can do so explicitly with the functions defined in [torch.nn.init](https://pytorch.org/docs/master/nn.html#torch-nn-init) and the Module’s `apply(fn)` method, e.g.

```auto
def init_weights(m):
    if type(m) == nn.Linear:
        torch.nn.init.xavier_uniform(m.weight)
    elif type(m) == nn.Conv2d:
        # Some other initalization

net = Net()
net.apply(init_weights)

```
