Neural network skeleton nn.Module
- nn.Module in brackets indicates inheriting the Module class
- init initialization
calls the parent class initialization function - forward
scipy download
pip install scipy -i https://pypi.douban.com/simple/
Use and modification of existing network models (VGG16)
When pretrained is True, it needs to be downloaded and trained on imageNet
(changed to weights after 0.15)
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.
Either load it into the classifier
or directly change it in the Linear inside it.
Save the model
- method 1
Saves the network structure and parameters in the network model
-
Method 1 Loading the model
-
Method 2 (official recommendation)
output dictionary format
and restore to network model: create a new network model structure