1. The Lizard class lets us know that an object has a color and length, but it doesn't tell us what the color and length are, because the class only describes the object. 2. A class is like a blueprint for an object, we can create as many different objects as possible from the same class.
1. A class is considered a self-contained unit that contains code and data. It can be seen as packaging attributes and methods together and then encapsulating them into classes.
Class: Declare a class and specify the class name, such as Lizard __init__: class constructor, when a new instance of the class is created as a parameter of this constructor (such as name), the constructor will be called self: a special parameter that makes We can create attribute values stored or encapsulated in class objects, and when we call constructors or other methods, Python automatically passes the self parameter
1. Things passed to the constructor will be discarded by default, but anything in self will always be remembered as long as this object exists.
torch.nn
import torch.nn as nn
1. torch.nn contains all the typical components needed to build a neural network. The important components we need to build a neural network are layers, and torch.nn contains classes that help us construct layers. 2. Each layer of the neural network has two important components, the first is transformation (transformation), and the second is the collection of weights (collection of weights). Recalling Object Oriented Programming (OOP), we might see that transformations are represented in code and sets of weights are represented in data, a fact that makes layers an excellent candidate for class representation using OOP . 3. In the neural network package, there is a special class called Module, which is the parent class of all neural network modules. This means that all Pytorch layers extend the nn.Module class and inherit all Pytorch built-in functions. In OOP, this concept is called inheritance.