|
1 | 1 | """
|
2 | 2 | Build Model Tutorial
|
3 |
| -======================================= |
4 |
| -
|
5 |
| -The data has been loaded and transformed we can now build the model. |
6 |
| -We will leverage `torch.nn <https://pytorch.org/docs/stable/nn.html>`_ predefined layers that PyTorch has that can simplify our code. |
7 |
| -
|
8 |
| -In the below example, for our FashionMNIT image dataset, we are using a `Sequential` |
9 |
| -container from class `torch.nn. Sequential <https://pytorch.org/docs/stable/generated/torch.nn.Sequential.html>`_ |
10 |
| -that allows us to define the model layers inline. In the "Sequential" in-line model building format the ``forward()`` |
11 |
| -method is created for you and the modules you add are passed in as a list or dictionary in the order that are they are defined. |
12 |
| -
|
13 |
| -Another way to bulid this model is with a class |
14 |
| -using `nn.Module <https://pytorch.org/docs/stable/generated/torch.nn.Module.html)>`_ |
15 |
| -A big plus with using a class that inherits ``nn.Module`` is better parameter management across all nested submodules. |
16 |
| -This gives us more flexibility, because we can construct layers of any complexity, including the ones with shared weights. |
17 |
| -
|
18 |
| -Lets break down the steps to build this model below |
| 3 | +============================ |
19 | 4 | """
|
20 | 5 |
|
| 6 | +########################################## |
| 7 | +# The data has been loaded and transformed we can now build the model. |
| 8 | +# We will leverage `torch.nn <https://pytorch.org/docs/stable/nn.html>`_ predefined layers that PyTorch has that can simplify our code. |
| 9 | +# |
| 10 | +# In the below example, for our FashionMNIT image dataset, we are using a `Sequential` |
| 11 | +# container from class `torch.nn. Sequential <https://pytorch.org/docs/stable/generated/torch.nn.Sequential.html>`_ |
| 12 | +# that allows us to define the model layers inline. In the "Sequential" in-line model building format the ``forward()`` |
| 13 | +# method is created for you and the modules you add are passed in as a list or dictionary in the order that are they are defined. |
| 14 | +# |
| 15 | +# Another way to bulid this model is with a class |
| 16 | +# using `nn.Module <https://pytorch.org/docs/stable/generated/torch.nn.Module.html)>`_ |
| 17 | +# A big plus with using a class that inherits ``nn.Module`` is better parameter management across all nested submodules. |
| 18 | +# This gives us more flexibility, because we can construct layers of any complexity, including the ones with shared weights. |
| 19 | +# |
| 20 | +# Lets break down the steps to build this model below |
| 21 | +# |
| 22 | + |
21 | 23 | ##########################################
|
22 | 24 | # Inline nn.Sequential Example:
|
23 | 25 | # ----------------------------
|
|
0 commit comments