小编viv*_*ith的帖子

当我将 Weight_decay 参数添加到 PyTorch 中的优化器时,我的训练精度保持在 10%。我正在使用 CIFAR10 数据集和 LeNet CNN 模型

我正在 LeNet CNN 模型上训练 CIFAR10 数据集。我在 Google Colab 上使用 PyTorch。仅当我使用 Adam 优化器并将 model.parameters() 作为唯一参数时,该代码才会运行。但是,当我更改优化器或使用 Weight_decay 参数时,准确度在所有时期都保持在 10%。我无法理解它发生的原因。

# CNN Model - LeNet    
class LeNet_ReLU(nn.Module):
    def __init__(self):
        super().__init__()
        self.cnn_model = nn.Sequential(nn.Conv2d(3,6,5), 
                                       nn.ReLU(),
                                       nn.AvgPool2d(2, stride=2), 
                                       nn.Conv2d(6,16,5), 
                                       nn.ReLU(),
                                       nn.AvgPool2d(2, stride=2))  
        self.fc_model = nn.Sequential(nn.Linear(400, 120),   
                                      nn.ReLU(),
                                      nn.Linear(120,84),  
                                      nn.ReLU(),
                                      nn.Linear(84,10))

    def forward(self, x):
        x = self.cnn_model(x)
        x = x.view(x.size(0), -1)
        x = self.fc_model(x)
        return x

# Importing dataset and creating dataloader
batch_size = 128
trainset = torchvision.datasets.CIFAR10(root='./data', train=True, download=True,
                                    transform=transforms.ToTensor())
trainloader = utils_data.DataLoader(trainset, batch_size=batch_size, shuffle=True) …
Run Code Online (Sandbox Code Playgroud)

python optimization conv-neural-network pytorch

5
推荐指数
1
解决办法
3103
查看次数