Artificial intelligence learning 06--pytorch06--Neural network skeleton nn.Module & scipy download & use and modification of existing network models (VGG16)

Neural network skeleton nn.Module

Insert image description here

  • nn.Module in brackets indicates inheriting the Module class
  • init initialization
    calls the parent class initialization function
  • forward
    Insert image description here

scipy download

pip install scipy -i https://pypi.douban.com/simple/
Insert image description here

Use and modification of existing network models (VGG16)

Insert image description here
When pretrained is True, it needs to be downloaded and trained on imageNet
(changed to weights after 0.15)
Insert image description here

Insert image description here
Insert image description here
Use the existing network and change the structure.
Many frameworks use VGG16 to extract features, and then add some network structures after VGG16.

Current goal: change VGG16 to 10 and use CFAR10 for training.

You can add a linear layer, let in_feature=1000, out_feature=10.
This method is only suitable for modification of the front and rear parts. If you want to skip layers or connect across layers, you can only write it yourself.

Insert image description here
Either load it into the classifier
Insert image description here
or directly change it in the Linear inside it.
Insert image description here
Insert image description here

Save the model

  • method 1

Insert image description here
Saves the network structure and parameters in the network model

  • Method 1 Loading the model
    Insert image description here

  • Method 2 (official recommendation)
    output dictionary format
    Insert image description here
    and restore to network model: create a new network model structure
    Insert image description here

Guess you like

Origin blog.csdn.net/AMWICD/article/details/128756713