[AI] "Hands-on Learning-Deep Learning-PyTorch Edition" Notes (16): Customize network layers, save/load parameters, and use GPU

Summary of AI Learning Catalog

1. Customize the network layer

Customizing the network layer is easy and can be completed in three steps

  • Inherited class: nn.Module
  • Define the initialization function: define the code that needs to be initialized in __init__
  • Define forward propagation function: forward

1.1 Network layer without parameters

1) Define the network layer

import torch
import torch.nn.functional as F
from torch import nn

class CenteredLayer(nn.Module)

Guess you like

Origin blog.csdn.net/u010168781/article/details/132223227