- 1、Base_Line_V2_Deepernet
- 2、条件预设
- A、数据使用情况
- B、模型架构
- C、训练参数设置
- 3、总结
- 1、第100epoch
- 2、第210个epoch
- 3、第257个epoch
- 4、第307个epoch
全民炼丹师们大家好、这是练习时长19248.2s个人练习生深一点的CNN。喜欢唱、跳、rap、篮球
music。不不不,只会分类十一种食物。
1、完全使用labeled的数据集,没有采用unlabeled的数据集,数据量为train_set:3080,valid_set:660
2、 添加了Augment策略,增加图片的多样性
# It is important to do data augmentation in training.
train_tfm = transforms.Compose([
transforms.Resize((224, 224)),
transforms.RandomChoice(
[transforms.AutoAugment(),
transforms.AutoAugment(transforms.AutoAugmentPolicy.CIFAR10),
transforms.AutoAugment(transforms.AutoAugmentPolicy.SVHN)]
),
# 随机水平翻转
transforms.RandomHorizontalFlip(p=0.5),
# 对图像执行随机仿射变换。
transforms.RandomAffine(degrees=20, translate=(0.2, 0.2), scale=(0.7, 1.3)),
transforms.ToTensor(),
])
# We don't need augmentations in testing and validation.
# All we need here is to resize the PIL image and transform it into Tensor.
test_tfm = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
])
B、模型架构
1、更换模型结构,增加卷积层数
class CNN(nn.Module):
def __init__(self):
super(CNN, self).__init__()
# The arguments for commonly used modules:
# torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding)
# torch.nn.MaxPool2d(kernel_size, stride, padding)
# input image size: [3, 128, 128]
self.cnn_layers = nn.Sequential(
# 3 * 224 * 224 -> 64 * 111 * 111
nn.Conv2d(3, 32, 3, padding=1),
nn.BatchNorm2d(32),
nn.ReLU(),
nn.Conv2d(32, 64, 3),
nn.BatchNorm2d(64),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2),
# 64 * 111 * 111 -> 128 * 54 * 54
nn.Conv2d(64, 128, 3),
nn.BatchNorm2d(128),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2),
# 128 * 54 * 54 -> 256 * 26 * 26
nn.Conv2d(128, 256, 3),
nn.BatchNorm2d(256),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2),
# 256 * 26 * 26 -> 256 * 12 * 12
nn.Conv2d(256, 256, 3),
nn.BatchNorm2d(256),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2),
# 256 * 12 * 12 -> 512 * 5 * 5
nn.Conv2d(256, 512, 3),
nn.BatchNorm2d(512),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2),
)
self.fc_layers = nn.Sequential(
nn.Linear(512 * 5 * 5, 512),
nn.ReLU(),
nn.BatchNorm1d(512),
nn.Dropout(0.5),
nn.Linear(512, 11),
)
def forward(self, x):
# input (x): [batch_size, 3, 128, 128]
# output: [batch_size, 11]
# Extract features by convolutional layers.
x = self.cnn_layers(x)
# The extracted feature map must be flatten before going to fully-connected layers.
x = x.flatten(1)
# The features are transformed by fully-connected layers to obtain the final logits.
x = self.fc_layers(x)
return x
C、训练参数设置
Batch_size_Data = 32 criterion = nn.CrossEntropyLoss() optimizer = torch.optim.Adam(model.parameters(), lr=0.0003, weight_decay=1e-5)3、总结
选择这些epoch的原因,是因为在这些点保存了最好的模型。
1、第100epoch
5331.0s 299 [ Train | 100/1000 ] loss = 1.04892, acc = 0.64530 5339.5s 301 [ Valid | 100/1000 ] loss = 1.31053, acc = 0.57619
感觉较为正常,模型正常拟合,就是前面训练的时候会突然出现一个尖刺,可能突然学到了数据里的一些噪,没有做好约束,在后面当数据加了归一化,就没有出现过这种尖刺
2、第210个epoch
10984.2s 641 [ Train | 210/1000 ] loss = 0.61395, acc = 0.79510 10992.9s 643 [ Valid | 210/1000 ] loss = 1.05069, acc = 0.69792
感觉也还行,还没有出现很严重的过拟合,在test上面表现得也很不错,但距离strong baseline还有点远
3、第257个epoch
13428.7s 784 [ Train | 257/1000 ] loss = 0.53473, acc = 0.82216 13437.4s 786 [ Valid | 257/1000 ] loss = 0.97210, acc = 0.71012
这个时候的话,已经开始过拟合越来越严重了。
4、第307个epoch
16059.4s 939 [ Train | 307/1000 ] loss = 0.46704, acc = 0.85116 16068.9s 941 [ Valid | 307/1000 ] loss = 0.91456, acc = 0.75238
到这个时候已经出现了较为严重的过拟合了,验证集几乎不变,训练集还是在一直降,学了太多了。导致其实最后的效果也不好
但这一次,相较于上次,加深了模型深度,训练效果比第一次好很多,学到了更多的特征,提升也很大,分数提升了大概0.25左右。可以尝试在数据增加正则化,让模型收敛更快,降低过拟合
希望各位大佬能够提点简易,最近才接触到炼丹,啥也不会,也不知道该怎么去分析这些结果,调参也不行,就知道莽数据集和模型结构。希望各位大佬能够教教我如何去更加可视化的看训练出来的数据,如何去分析数据集及训练出来的结果。
暑期编程PK赛 得CSDN机械键盘等精美礼品!


