基于VGG16预训练模型实现cifar10数据集的分类任务

一、VGG16预训练模型介绍

VGG16是由牛津大学视觉几何组在2014年ILSVRC竞赛中提出的深度卷积神经网络模型。其名称"VGG"即来源于该实验室,"16"代表其包含权重参数的层数为16层(13个卷积层 + 3个全连接层)。

该模型在当年的ImageNet大规模视觉识别挑战赛中取得了优异成绩(分类任务亚军,定位任务冠军),其简洁、统一的结构使其成为理解CNN架构的绝佳范例。

核心架构特点

  1. 结构简洁 : 整个网络只使用了 3x3 的小型卷积核2x2 的最大池化层,层层堆叠。

    • 小卷积核的优势:多个小卷积核(如两层3x3)的感受野等同于一个大卷积核(如5x5),但参数更少,非线性变换更多(使用了更多的ReLU激活函数),增强了模型的判别能力。
  2. 深度增加: 通过堆叠多个卷积层来增加网络的深度(16-19层),从而学习更复杂、更抽象的特征。这印证了"深度"对于提升模型性能的重要性。

  3. 统一的架构 : 所有卷积层使用相同的填充(padding='same')和步长,保持特征图空间尺寸不变,仅在池化层后尺寸减半。

  4. 全连接分类器: 最后使用三个全连接层将学习到的特征映射到1000个类别(ImageNet类别数)的分数上。

简化的VGG16结构图

text

复制代码
输入 (224x224x3)
=> [2 x 卷积(64)] -> 池化          # Block 1
=> [2 x 卷积(128)] -> 池化         # Block 2
=> [3 x 卷积(256)] -> 池化         # Block 3
=> [3 x 卷积(512)] -> 池化         # Block 4
=> [3 x 卷积(512)] -> 池化         # Block 5
=> 全连接(4096) -> Dropout
=> 全连接(4096) -> Dropout
=> 全连接(1000) -> Softmax

什么是"预训练模型"?

"预训练"是指模型已经在大规模数据集(如ImageNet,包含1400万张图片,1000个类别) 上进行了充分的训练,其权重参数已经学习到了非常丰富的通用视觉特征:

  • 浅层: 学习到了边缘、角点、纹理、颜色等低级特征。

  • 中层: 学习到了形状、部件等中级特征。

  • 深层: 学习到了与特定类别(如狗脸、车轮)相关的高级语义特征。

使用预训练模型的好处(即"迁移学习")

  1. 节省大量时间和计算资源: 无需从零开始训练一个深度网络(在ImageNet上训练VGG16可能需要数周时间)。

  2. 小数据集也能取得好效果: 即使你自己的数据集很小,也可以利用模型已学到的通用特征,只需针对你的特定任务进行微调。

  3. 作为强大的特征提取器: 可以直接移除最后的全连接层,将VGG16的输出作为图像的固定长度特征向量,用于其他机器学习任务。

二、使用VGG16完成cifar-10数据集分类任务的代码实现

1.VGG模型定义

python 复制代码
import torch
import torch.nn as nn
import torch.optim as optim
import torchvision
import torchvision.transforms as transforms
from torch.utils.data import DataLoader
import time
import os
from tqdm import tqdm
import numpy as np

# 设置随机种子以确保可重复性
def set_seed(seed=42):
    torch.manual_seed(seed)
    torch.cuda.manual_seed(seed)
    torch.backends.cudnn.deterministic = True
    torch.backends.cudnn.benchmark = False
    np.random.seed(seed)

set_seed(42)

# 一、VGG模型定义
class VGG(nn.Module):
    def __init__(self, vgg_name='VGG16', num_classes=10):
        super(VGG, self).__init__()
        self.features = self._make_layers(self.cfg[vgg_name])
        # 使用自适应平均池化替代固定池化,使网络适应不同输入尺寸
        self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
        self.classifier = nn.Sequential(
            nn.Linear(512, 512),
            nn.ReLU(True),
            nn.Dropout(0.5),  # 增加dropout率防止过拟合
            nn.Linear(512, 512),
            nn.ReLU(True),
            nn.Dropout(0.5),
            nn.Linear(512, num_classes),
        )
        # 权重初始化
        self._initialize_weights()
        
    cfg = {
        'VGG11': [64, 'M', 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'],
        'VGG13': [64, 64, 'M', 128, 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'],
        'VGG16': [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 'M', 512, 512, 512, 'M', 512, 512, 512, 'M'],
        'VGG19': [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 256, 'M', 512, 512, 512, 512, 'M', 512, 512, 512, 512, 'M'],
    }
    
    def _make_layers(self, cfg):
        layers = []
        in_channels = 3
        for x in cfg:
            if x == 'M':
                layers += [nn.MaxPool2d(kernel_size=2, stride=2)]
            else:
                layers += [
                    nn.Conv2d(in_channels, x, kernel_size=3, padding=1),
                    nn.BatchNorm2d(x),
                    nn.ReLU(inplace=True)
                ]
                in_channels = x
        return nn.Sequential(*layers)
    
    def _initialize_weights(self):
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
                if m.bias is not None:
                    nn.init.constant_(m.bias, 0)
            elif isinstance(m, nn.BatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)
            elif isinstance(m, nn.Linear):
                nn.init.normal_(m.weight, 0, 0.01)
                nn.init.constant_(m.bias, 0)
    
    def forward(self, x):
        x = self.features(x)
        x = self.avgpool(x)
        x = torch.flatten(x, 1)
        x = self.classifier(x)
        return x

2.数据集的下载和预处理

python 复制代码
# 二、数据集的下载和预处理
def get_dataloaders(batch_size=128, augment=True):
    # CIFAR-10数据集的均值和标准差
    mean = [0.4914, 0.4822, 0.4465]
    std = [0.2023, 0.1994, 0.2010]
    
    if augment:
        # 训练数据增强 - 增加更多增强方法
        train_transform = transforms.Compose([
            transforms.RandomCrop(32, padding=4),
            transforms.RandomHorizontalFlip(),
            transforms.RandomRotation(10),  # 新增:随机旋转
            transforms.ColorJitter(brightness=0.2, contrast=0.2, saturation=0.2),  # 新增:颜色抖动
            transforms.ToTensor(),
            transforms.Normalize(mean, std)
        ])
    else:
        train_transform = transforms.Compose([
            transforms.ToTensor(),
            transforms.Normalize(mean, std)
        ])
    
    # 测试/验证集转换
    test_transform = transforms.Compose([
        transforms.ToTensor(),
        transforms.Normalize(mean, std)
    ])
    
    # 下载训练集和测试集
    train_dataset = torchvision.datasets.CIFAR10(
        root='./data', train=True, download=False, transform=train_transform
    )
    
    test_dataset = torchvision.datasets.CIFAR10(
        root='./data', train=False, download=False, transform=test_transform
    )
    
    # 创建数据加载器
    train_loader = DataLoader(
        train_dataset, batch_size=batch_size, shuffle=True, num_workers=4, pin_memory=True
    )
    
    test_loader = DataLoader(
        test_dataset, batch_size=batch_size, shuffle=False, num_workers=4, pin_memory=True
    )
    
    # CIFAR-10类别名称
    classes = ('plane', 'car', 'bird', 'cat', 'deer', 
               'dog', 'frog', 'horse', 'ship', 'truck')
    
    return train_loader, test_loader, classes

3.编写训练函数

python 复制代码
# 四、编写训练函数(使用Adam优化器)
def train_model(model, train_loader, criterion, optimizer, device, epoch, total_epochs, scheduler=None):
    model.train()
    train_loss = 0.0
    correct = 0
    total = 0
    
    pbar = tqdm(train_loader, desc=f'Epoch [{epoch+1}/{total_epochs}]')
    for batch_idx, (inputs, targets) in enumerate(pbar):
        inputs, targets = inputs.to(device), targets.to(device)
        
        # 前向传播
        outputs = model(inputs)
        loss = criterion(outputs, targets)
        
        # 反向传播和优化
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()
        
        # 统计
        train_loss += loss.item()
        _, predicted = outputs.max(1)
        total += targets.size(0)
        correct += predicted.eq(targets).sum().item()
        
        # 更新进度条
        pbar.set_postfix({
            'Loss': f'{train_loss/(batch_idx+1):.4f}',
            'Acc': f'{100.*correct/total:.2f}%'
        })
    
    # 每个epoch结束后更新学习率
    if scheduler is not None:
        scheduler.step()
    
    return train_loss/len(train_loader), 100.*correct/total

4.编写推理函数

python 复制代码
# 五、编写推理函数
def evaluate_model(model, test_loader, criterion, device):
    model.eval()
    test_loss = 0.0
    correct = 0
    total = 0
    
    with torch.no_grad():
        pbar = tqdm(test_loader, desc='Testing')
        for batch_idx, (inputs, targets) in enumerate(pbar):
            inputs, targets = inputs.to(device), targets.to(device)
            
            # 前向传播
            outputs = model(inputs)
            loss = criterion(outputs, targets)
            
            # 统计
            test_loss += loss.item()
            _, predicted = outputs.max(1)
            total += targets.size(0)
            correct += predicted.eq(targets).sum().item()
            
            # 更新进度条
            pbar.set_postfix({
                'Loss': f'{test_loss/(batch_idx+1):.4f}',
                'Acc': f'{100.*correct/total:.2f}%'
            })
    
    return test_loss/len(test_loader), 100.*correct/total

# 保存和加载模型的函数
def save_checkpoint(model, optimizer, epoch, accuracy, filename='vgg_cifar10.pth'):
    checkpoint = {
        'epoch': epoch,
        'model_state_dict': model.state_dict(),
        'optimizer_state_dict': optimizer.state_dict(),
        'accuracy': accuracy,
        'best_accuracy': accuracy,  # 保存最佳准确率
    }
    torch.save(checkpoint, filename)
    print(f'Checkpoint saved to {filename}')
    return filename

def load_checkpoint(model, optimizer, filename='vgg_cifar10.pth'):
    if os.path.exists(filename):
        checkpoint = torch.load(filename, map_location='cpu')
        model.load_state_dict(checkpoint['model_state_dict'])
        optimizer.load_state_dict(checkpoint['optimizer_state_dict'])
        epoch = checkpoint['epoch']
        accuracy = checkpoint['accuracy']
        print(f'Checkpoint loaded from {filename}')
        print(f'Resuming from epoch {epoch+1} with accuracy {accuracy:.2f}%')
        return epoch, accuracy
    return 0, 0.0

5.编写运行主函数

python 复制代码
def main():
    # 超参数设置 - 针对Adam优化器调整
    batch_size = 128
    learning_rate = 0.001  # Adam通常使用较小的学习率
    num_epochs = 50  # Adam收敛更快,可以减少epoch数
    weight_decay = 1e-4  # L2正则化
    checkpoint_path = 'vgg_cifar10_adam.pth'
    
    # 设备配置
    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
    print(f'Using device: {device}')
    if torch.cuda.is_available():
        print(f'GPU: {torch.cuda.get_device_name(0)}')
    
    # 获取数据加载器
    print('Loading CIFAR-10 dataset...')
    train_loader, test_loader, classes = get_dataloaders(batch_size, augment=True)
    print(f'Training samples: {len(train_loader.dataset)}')
    print(f'Test samples: {len(test_loader.dataset)}')
    
    # 创建模型
    print('Creating VGG16 model...')
    model = VGG(vgg_name='VGG16', num_classes=10).to(device)
    
    # 输出模型参数量
    total_params = sum(p.numel() for p in model.parameters())
    trainable_params = sum(p.numel() for p in model.parameters() if p.requires_grad)
    print(f'Total parameters: {total_params:,}')
    print(f'Trainable parameters: {trainable_params:,}')
    
    # 定义损失函数
    criterion = nn.CrossEntropyLoss()
    
    # 使用Adam优化器 - 核心修改点
    optimizer = optim.Adam(
        model.parameters(), 
        lr=learning_rate,
        betas=(0.9, 0.999),  # Adam默认的beta参数
        eps=1e-08,  # 数值稳定性
        weight_decay=weight_decay  # L2正则化
    )
    
    # 学习率调度器 - 使用余弦退火
    scheduler = optim.lr_scheduler.CosineAnnealingLR(
        optimizer, 
        T_max=num_epochs,
        eta_min=1e-6  # 最小学习率
    )
    
    # 加载检查点(如果存在)
    start_epoch = 0
    best_acc = 0.0
    
    if os.path.exists(checkpoint_path):
        start_epoch, best_acc = load_checkpoint(model, optimizer, checkpoint_path)
        start_epoch += 1  # 从下一个epoch开始
    
    print('\n' + '='*60)
    print('Starting training with Adam optimizer...')
    print('='*60)
    
    # 训练历史记录
    train_history = {'loss': [], 'acc': []}
    test_history = {'loss': [], 'acc': []}
    
    # 训练循环
    for epoch in range(start_epoch, num_epochs):
        print(f'\nEpoch {epoch+1}/{num_epochs}')
        print('-' * 60)
        
        # 训练一个epoch
        train_loss, train_acc = train_model(
            model, train_loader, criterion, optimizer, device, epoch, num_epochs, scheduler
        )
        
        # 评估模型
        test_loss, test_acc = evaluate_model(
            model, test_loader, criterion, device
        )
        
        # 记录历史
        train_history['loss'].append(train_loss)
        train_history['acc'].append(train_acc)
        test_history['loss'].append(test_loss)
        test_history['acc'].append(test_acc)
        
        # 打印epoch结果
        print(f'\nEpoch {epoch+1} Summary:')
        print(f'  Train Loss: {train_loss:.4f}, Train Acc: {train_acc:.2f}%')
        print(f'  Test Loss:  {test_loss:.4f}, Test Acc:  {test_acc:.2f}%')
        print(f'  Learning Rate: {optimizer.param_groups[0]["lr"]:.6f}')
        
        # 保存最佳模型
        if test_acc > best_acc:
            best_acc = test_acc
            save_checkpoint(model, optimizer, epoch, best_acc, checkpoint_path)
            print(f'  ✓ New best accuracy: {best_acc:.2f}%')
        else:
            print(f'  Best accuracy so far: {best_acc:.2f}%')
    
    print('\n' + '='*60)
    print(f'Training completed! Best accuracy: {best_acc:.2f}%')
    print('='*60)
    
    # 最终测试
    print('\nFinal evaluation on test set...')
    model.eval()
    
    # 计算整体准确率
    _, final_acc = evaluate_model(model, test_loader, criterion, device)
    print(f'Final test accuracy: {final_acc:.2f}%')
    
    # 计算每个类别的准确率
    class_correct = list(0. for _ in range(10))
    class_total = list(0. for _ in range(10))
    
    with torch.no_grad():
        for inputs, targets in test_loader:
            inputs, targets = inputs.to(device), targets.to(device)
            outputs = model(inputs)
            _, predicted = torch.max(outputs, 1)
            c = (predicted == targets).squeeze()
            
            for i in range(len(targets)):
                label = targets[i]
                class_correct[label] += c[i].item()
                class_total[label] += 1
    
    print('\nPer-class accuracy:')
    for i in range(10):
        accuracy = 100 * class_correct[i] / class_total[i] if class_total[i] > 0 else 0
        print(f'{classes[i]:10s}: {accuracy:.2f}%')
    
    # 可视化训练过程
    try:
        import matplotlib.pyplot as plt
        
        plt.figure(figsize=(12, 4))
        
        plt.subplot(1, 2, 1)
        plt.plot(train_history['loss'], label='Train Loss')
        plt.plot(test_history['loss'], label='Test Loss')
        plt.xlabel('Epoch')
        plt.ylabel('Loss')
        plt.title('Training and Test Loss')
        plt.legend()
        plt.grid(True)
        
        plt.subplot(1, 2, 2)
        plt.plot(train_history['acc'], label='Train Acc')
        plt.plot(test_history['acc'], label='Test Acc')
        plt.xlabel('Epoch')
        plt.ylabel('Accuracy (%)')
        plt.title('Training and Test Accuracy')
        plt.legend()
        plt.grid(True)
        
        plt.tight_layout()
        plt.savefig('training_history.png')
        plt.show()
        print('\nTraining history plot saved as "training_history.png"')
        
    except ImportError:
        print("\nMatplotlib not installed. Skipping training history plot.")
    
    return model, best_acc, train_history, test_history

# 推理单个样本的函数
def predict_single_image(model, image_tensor, device, classes):
    model.eval()
    with torch.no_grad():
        image_tensor = image_tensor.unsqueeze(0).to(device)
        output = model(image_tensor)
        probabilities = torch.nn.functional.softmax(output, dim=1)
        confidence, predicted = torch.max(probabilities, 1)
        return classes[predicted.item()], confidence.item(), probabilities.squeeze().cpu().numpy()

# 批量推理函数
def predict_batch(model, data_loader, device, classes, num_samples=5):
    model.eval()
    samples = []
    
    with torch.no_grad():
        for i, (inputs, targets) in enumerate(data_loader):
            if i >= num_samples:
                break
            inputs, targets = inputs.to(device), targets.to(device)
            outputs = model(inputs)
            probabilities = torch.nn.functional.softmax(outputs, dim=1)
            confidences, predicted = torch.max(probabilities, 1)
            
            for j in range(len(inputs)):
                samples.append({
                    'image': inputs[j].cpu(),
                    'true_label': classes[targets[j].item()],
                    'predicted_label': classes[predicted[j].item()],
                    'confidence': confidences[j].item(),
                    'probabilities': probabilities[j].cpu().numpy()
                })
    
    return samples

6.运行代码

python 复制代码
if __name__ == '__main__':
    # 运行主函数
    print("CIFAR-10 Classification with VGG16 and Adam Optimizer")
    print("=" * 60)
    
    trained_model, best_accuracy, train_hist, test_hist = main()
    
    # 示例:如何加载已训练的模型进行推理
    print("\n" + "="*60)
    print("Example of loading trained model for inference:")
    print("="*60)
    
    # 加载训练好的模型
    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
    loaded_model = VGG(vgg_name='VGG16', num_classes=10).to(device)
    
    if os.path.exists('vgg_cifar10_adam.pth'):
        checkpoint = torch.load('vgg_cifar10_adam.pth', map_location=device)
        loaded_model.load_state_dict(checkpoint['model_state_dict'])
        print(f"Model loaded with accuracy: {checkpoint['accuracy']:.2f}%")
    
    # 获取一个测试样本
    _, test_loader, classes = get_dataloaders(batch_size=1, augment=False)
    
    # 进行单样本预测
    sample_data, sample_label = next(iter(test_loader))
    predicted_class, confidence, probs = predict_single_image(
        loaded_model, sample_data[0], device, classes
    )
    true_class = classes[sample_label[0]]
    
    print(f"\nSample prediction:")
    print(f"  True class: {true_class}")
    print(f"  Predicted: {predicted_class}")
    print(f"  Confidence: {confidence:.4f}")
    
    # 显示概率分布
    print(f"\nTop-3 predictions:")
    top3_indices = np.argsort(probs)[-3:][::-1]
    for idx in top3_indices:
        print(f"  {classes[idx]:10s}: {probs[idx]*100:.2f}%")
    
    # 批量推理示例
    print(f"\nBatch prediction example (5 samples):")
    batch_samples = predict_batch(loaded_model, test_loader, device, classes, num_samples=5)
    
    for i, sample in enumerate(batch_samples):
        print(f"\nSample {i+1}:")
        print(f"  True: {sample['true_label']}")
        print(f"  Predicted: {sample['predicted_label']}")
        print(f"  Confidence: {sample['confidence']:.4f}")
        print(f"  Correct: {sample['true_label'] == sample['predicted_label']}")

7.运行结果

bash 复制代码
CIFAR-10 Classification with VGG16 and Adam Optimizer
============================================================
Using device: cuda
GPU: NVIDIA A10
Loading CIFAR-10 dataset...
Training samples: 50000
Test samples: 10000
Creating VGG16 model...
Total parameters: 15,253,578
Trainable parameters: 15,253,578

============================================================
Starting training with Adam optimizer...
============================================================

Epoch 1/50
------------------------------------------------------------
Epoch [1/50]: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:09<00:00, 42.93it/s, Loss=1.9394, Acc=18.51%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 113.95it/s, Loss=1.8139, Acc=22.46%]

Epoch 1 Summary:
  Train Loss: 1.9394, Train Acc: 18.51%
  Test Loss:  1.8139, Test Acc:  22.46%
  Learning Rate: 0.000999
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 22.46%

Epoch 2/50
------------------------------------------------------------
Epoch [2/50]: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.06it/s, Loss=1.7429, Acc=29.58%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 123.73it/s, Loss=1.6092, Acc=31.65%]

Epoch 2 Summary:
  Train Loss: 1.7429, Train Acc: 29.58%
  Test Loss:  1.6092, Test Acc:  31.65%
  Learning Rate: 0.000996
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 31.65%

Epoch 3/50
------------------------------------------------------------
Epoch [3/50]: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.72it/s, Loss=1.5381, Acc=37.53%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 123.45it/s, Loss=1.3972, Acc=44.37%]

Epoch 3 Summary:
  Train Loss: 1.5381, Train Acc: 37.53%
  Test Loss:  1.3972, Test Acc:  44.37%
  Learning Rate: 0.000991
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 44.37%

Epoch 4/50
------------------------------------------------------------
Epoch [4/50]: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.37it/s, Loss=1.4013, Acc=46.21%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 113.20it/s, Loss=1.4810, Acc=46.81%]

Epoch 4 Summary:
  Train Loss: 1.4013, Train Acc: 46.21%
  Test Loss:  1.4810, Test Acc:  46.81%
  Learning Rate: 0.000984
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 46.81%

Epoch 5/50
------------------------------------------------------------
Epoch [5/50]: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.66it/s, Loss=1.2177, Acc=55.89%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 121.50it/s, Loss=1.0224, Acc=61.99%]

Epoch 5 Summary:
  Train Loss: 1.2177, Train Acc: 55.89%
  Test Loss:  1.0224, Test Acc:  61.99%
  Learning Rate: 0.000976
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 61.99%

Epoch 6/50
------------------------------------------------------------
Epoch [6/50]: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.16it/s, Loss=1.0876, Acc=61.36%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 116.79it/s, Loss=1.0151, Acc=62.04%]

Epoch 6 Summary:
  Train Loss: 1.0876, Train Acc: 61.36%
  Test Loss:  1.0151, Test Acc:  62.04%
  Learning Rate: 0.000965
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 62.04%

Epoch 7/50
------------------------------------------------------------
Epoch [7/50]: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 48.18it/s, Loss=0.9829, Acc=66.23%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 120.06it/s, Loss=0.8446, Acc=70.21%]

Epoch 7 Summary:
  Train Loss: 0.9829, Train Acc: 66.23%
  Test Loss:  0.8446, Test Acc:  70.21%
  Learning Rate: 0.000952
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 70.21%

Epoch 8/50
------------------------------------------------------------
Epoch [8/50]: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 46.62it/s, Loss=0.9062, Acc=69.40%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 127.84it/s, Loss=0.8525, Acc=69.17%]

Epoch 8 Summary:
  Train Loss: 0.9062, Train Acc: 69.40%
  Test Loss:  0.8525, Test Acc:  69.17%
  Learning Rate: 0.000938
  Best accuracy so far: 70.21%

Epoch 9/50
------------------------------------------------------------
Epoch [9/50]: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 48.21it/s, Loss=0.8405, Acc=72.04%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 122.21it/s, Loss=0.7243, Acc=74.94%]

Epoch 9 Summary:
  Train Loss: 0.8405, Train Acc: 72.04%
  Test Loss:  0.7243, Test Acc:  74.94%
  Learning Rate: 0.000922
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 74.94%

Epoch 10/50
------------------------------------------------------------
Epoch [10/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 48.05it/s, Loss=0.7861, Acc=74.14%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 122.88it/s, Loss=0.6716, Acc=77.18%]

Epoch 10 Summary:
  Train Loss: 0.7861, Train Acc: 74.14%
  Test Loss:  0.6716, Test Acc:  77.18%
  Learning Rate: 0.000905
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 77.18%

Epoch 11/50
------------------------------------------------------------
Epoch [11/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 46.69it/s, Loss=0.7378, Acc=75.93%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 116.50it/s, Loss=0.7056, Acc=76.44%]

Epoch 11 Summary:
  Train Loss: 0.7378, Train Acc: 75.93%
  Test Loss:  0.7056, Test Acc:  76.44%
  Learning Rate: 0.000885
  Best accuracy so far: 77.18%

Epoch 12/50
------------------------------------------------------------
Epoch [12/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.18it/s, Loss=0.6839, Acc=77.92%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 116.77it/s, Loss=0.6370, Acc=79.17%]

Epoch 12 Summary:
  Train Loss: 0.6839, Train Acc: 77.92%
  Test Loss:  0.6370, Test Acc:  79.17%
  Learning Rate: 0.000865
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 79.17%

Epoch 13/50
------------------------------------------------------------
Epoch [13/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.88it/s, Loss=0.6446, Acc=79.28%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 123.09it/s, Loss=0.6212, Acc=80.10%]

Epoch 13 Summary:
  Train Loss: 0.6446, Train Acc: 79.28%
  Test Loss:  0.6212, Test Acc:  80.10%
  Learning Rate: 0.000842
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 80.10%

Epoch 14/50
------------------------------------------------------------
Epoch [14/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 46.37it/s, Loss=0.6169, Acc=80.52%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 125.15it/s, Loss=0.5722, Acc=81.16%]

Epoch 14 Summary:
  Train Loss: 0.6169, Train Acc: 80.52%
  Test Loss:  0.5722, Test Acc:  81.16%
  Learning Rate: 0.000819
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 81.16%

Epoch 15/50
------------------------------------------------------------
Epoch [15/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.32it/s, Loss=0.5796, Acc=81.51%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 127.21it/s, Loss=0.5241, Acc=82.77%]

Epoch 15 Summary:
  Train Loss: 0.5796, Train Acc: 81.51%
  Test Loss:  0.5241, Test Acc:  82.77%
  Learning Rate: 0.000794
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 82.77%

Epoch 16/50
------------------------------------------------------------
Epoch [16/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 46.82it/s, Loss=0.5572, Acc=82.50%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 121.74it/s, Loss=0.5138, Acc=83.70%]

Epoch 16 Summary:
  Train Loss: 0.5572, Train Acc: 82.50%
  Test Loss:  0.5138, Test Acc:  83.70%
  Learning Rate: 0.000768
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 83.70%

Epoch 17/50
------------------------------------------------------------
Epoch [17/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.03it/s, Loss=0.5275, Acc=83.20%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 121.98it/s, Loss=0.5286, Acc=82.88%]

Epoch 17 Summary:
  Train Loss: 0.5275, Train Acc: 83.20%
  Test Loss:  0.5286, Test Acc:  82.88%
  Learning Rate: 0.000741
  Best accuracy so far: 83.70%

Epoch 18/50
------------------------------------------------------------
Epoch [18/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.02it/s, Loss=0.4992, Acc=83.91%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 119.51it/s, Loss=0.4460, Acc=85.74%]

Epoch 18 Summary:
  Train Loss: 0.4992, Train Acc: 83.91%
  Test Loss:  0.4460, Test Acc:  85.74%
  Learning Rate: 0.000713
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 85.74%

Epoch 19/50
------------------------------------------------------------
Epoch [19/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 46.96it/s, Loss=0.4783, Acc=84.80%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 122.48it/s, Loss=0.4538, Acc=85.12%]

Epoch 19 Summary:
  Train Loss: 0.4783, Train Acc: 84.80%
  Test Loss:  0.4538, Test Acc:  85.12%
  Learning Rate: 0.000684
  Best accuracy so far: 85.74%

Epoch 20/50
------------------------------------------------------------
Epoch [20/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 48.75it/s, Loss=0.4546, Acc=85.77%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 121.34it/s, Loss=0.4288, Acc=86.17%]

Epoch 20 Summary:
  Train Loss: 0.4546, Train Acc: 85.77%
  Test Loss:  0.4288, Test Acc:  86.17%
  Learning Rate: 0.000655
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 86.17%

Epoch 21/50
------------------------------------------------------------
Epoch [21/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.48it/s, Loss=0.4297, Acc=86.22%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 120.66it/s, Loss=0.4071, Acc=86.73%]

Epoch 21 Summary:
  Train Loss: 0.4297, Train Acc: 86.22%
  Test Loss:  0.4071, Test Acc:  86.73%
  Learning Rate: 0.000625
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 86.73%

Epoch 22/50
------------------------------------------------------------
Epoch [22/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:07<00:00, 49.18it/s, Loss=0.4141, Acc=87.05%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 128.09it/s, Loss=0.3893, Acc=87.24%]

Epoch 22 Summary:
  Train Loss: 0.4141, Train Acc: 87.05%
  Test Loss:  0.3893, Test Acc:  87.24%
  Learning Rate: 0.000594
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 87.24%

Epoch 23/50
------------------------------------------------------------
Epoch [23/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.52it/s, Loss=0.3998, Acc=87.41%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 115.41it/s, Loss=0.4047, Acc=86.47%]

Epoch 23 Summary:
  Train Loss: 0.3998, Train Acc: 87.41%
  Test Loss:  0.4047, Test Acc:  86.47%
  Learning Rate: 0.000563
  Best accuracy so far: 87.24%

Epoch 24/50
------------------------------------------------------------
Epoch [24/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 48.22it/s, Loss=0.3718, Acc=88.15%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 114.41it/s, Loss=0.3994, Acc=87.72%]

Epoch 24 Summary:
  Train Loss: 0.3718, Train Acc: 88.15%
  Test Loss:  0.3994, Test Acc:  87.72%
  Learning Rate: 0.000532
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 87.72%

Epoch 25/50
------------------------------------------------------------
Epoch [25/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.24it/s, Loss=0.3588, Acc=88.63%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 126.66it/s, Loss=0.3802, Acc=87.96%]

Epoch 25 Summary:
  Train Loss: 0.3588, Train Acc: 88.63%
  Test Loss:  0.3802, Test Acc:  87.96%
  Learning Rate: 0.000500
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 87.96%

Epoch 26/50
------------------------------------------------------------
Epoch [26/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.97it/s, Loss=0.3444, Acc=88.91%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 127.61it/s, Loss=0.3737, Acc=88.21%]

Epoch 26 Summary:
  Train Loss: 0.3444, Train Acc: 88.91%
  Test Loss:  0.3737, Test Acc:  88.21%
  Learning Rate: 0.000469
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 88.21%

Epoch 27/50
------------------------------------------------------------
Epoch [27/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 46.88it/s, Loss=0.3279, Acc=89.61%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 123.66it/s, Loss=0.3584, Acc=88.69%]

Epoch 27 Summary:
  Train Loss: 0.3279, Train Acc: 89.61%
  Test Loss:  0.3584, Test Acc:  88.69%
  Learning Rate: 0.000438
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 88.69%

Epoch 28/50
------------------------------------------------------------
Epoch [28/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.07it/s, Loss=0.3105, Acc=90.20%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 125.97it/s, Loss=0.3683, Acc=88.47%]

Epoch 28 Summary:
  Train Loss: 0.3105, Train Acc: 90.20%
  Test Loss:  0.3683, Test Acc:  88.47%
  Learning Rate: 0.000407
  Best accuracy so far: 88.69%

Epoch 29/50
------------------------------------------------------------
Epoch [29/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.82it/s, Loss=0.2947, Acc=90.62%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 131.06it/s, Loss=0.3779, Acc=88.34%]

Epoch 29 Summary:
  Train Loss: 0.2947, Train Acc: 90.62%
  Test Loss:  0.3779, Test Acc:  88.34%
  Learning Rate: 0.000376
  Best accuracy so far: 88.69%

Epoch 30/50
------------------------------------------------------------
Epoch [30/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 46.94it/s, Loss=0.2772, Acc=91.21%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 121.69it/s, Loss=0.3554, Acc=89.52%]

Epoch 30 Summary:
  Train Loss: 0.2772, Train Acc: 91.21%
  Test Loss:  0.3554, Test Acc:  89.52%
  Learning Rate: 0.000346
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 89.52%

Epoch 31/50
------------------------------------------------------------
Epoch [31/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 48.19it/s, Loss=0.2596, Acc=91.62%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 125.21it/s, Loss=0.3542, Acc=89.17%]

Epoch 31 Summary:
  Train Loss: 0.2596, Train Acc: 91.62%
  Test Loss:  0.3542, Test Acc:  89.17%
  Learning Rate: 0.000317
  Best accuracy so far: 89.52%

Epoch 32/50
------------------------------------------------------------
Epoch [32/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:07<00:00, 49.37it/s, Loss=0.2503, Acc=91.95%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 127.54it/s, Loss=0.3437, Acc=89.53%]

Epoch 32 Summary:
  Train Loss: 0.2503, Train Acc: 91.95%
  Test Loss:  0.3437, Test Acc:  89.53%
  Learning Rate: 0.000288
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 89.53%

Epoch 33/50
------------------------------------------------------------
Epoch [33/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.23it/s, Loss=0.2377, Acc=92.33%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 129.89it/s, Loss=0.3482, Acc=89.58%]

Epoch 33 Summary:
  Train Loss: 0.2377, Train Acc: 92.33%
  Test Loss:  0.3482, Test Acc:  89.58%
  Learning Rate: 0.000260
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 89.58%

Epoch 34/50
------------------------------------------------------------
Epoch [34/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.78it/s, Loss=0.2209, Acc=92.90%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 123.00it/s, Loss=0.3234, Acc=90.05%]

Epoch 34 Summary:
  Train Loss: 0.2209, Train Acc: 92.90%
  Test Loss:  0.3234, Test Acc:  90.05%
  Learning Rate: 0.000233
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 90.05%

Epoch 35/50
------------------------------------------------------------
Epoch [35/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 48.48it/s, Loss=0.2091, Acc=93.37%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 125.25it/s, Loss=0.3197, Acc=90.58%]

Epoch 35 Summary:
  Train Loss: 0.2091, Train Acc: 93.37%
  Test Loss:  0.3197, Test Acc:  90.58%
  Learning Rate: 0.000207
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 90.58%

Epoch 36/50
------------------------------------------------------------
Epoch [36/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:07<00:00, 49.22it/s, Loss=0.2001, Acc=93.60%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 119.29it/s, Loss=0.3270, Acc=90.08%]

Epoch 36 Summary:
  Train Loss: 0.2001, Train Acc: 93.60%
  Test Loss:  0.3270, Test Acc:  90.08%
  Learning Rate: 0.000182
  Best accuracy so far: 90.58%

Epoch 37/50
------------------------------------------------------------
Epoch [37/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 48.12it/s, Loss=0.1865, Acc=94.12%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 118.03it/s, Loss=0.3194, Acc=90.85%]

Epoch 37 Summary:
  Train Loss: 0.1865, Train Acc: 94.12%
  Test Loss:  0.3194, Test Acc:  90.85%
  Learning Rate: 0.000159
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 90.85%

Epoch 38/50
------------------------------------------------------------
Epoch [38/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 48.60it/s, Loss=0.1741, Acc=94.31%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 123.94it/s, Loss=0.3292, Acc=90.60%]

Epoch 38 Summary:
  Train Loss: 0.1741, Train Acc: 94.31%
  Test Loss:  0.3292, Test Acc:  90.60%
  Learning Rate: 0.000136
  Best accuracy so far: 90.85%

Epoch 39/50
------------------------------------------------------------
Epoch [39/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.92it/s, Loss=0.1674, Acc=94.60%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 125.14it/s, Loss=0.3275, Acc=90.58%]

Epoch 39 Summary:
  Train Loss: 0.1674, Train Acc: 94.60%
  Test Loss:  0.3275, Test Acc:  90.58%
  Learning Rate: 0.000116
  Best accuracy so far: 90.85%

Epoch 40/50
------------------------------------------------------------
Epoch [40/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.69it/s, Loss=0.1575, Acc=94.93%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 122.13it/s, Loss=0.3226, Acc=91.00%]

Epoch 40 Summary:
  Train Loss: 0.1575, Train Acc: 94.93%
  Test Loss:  0.3226, Test Acc:  91.00%
  Learning Rate: 0.000096
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 91.00%

Epoch 41/50
------------------------------------------------------------
Epoch [41/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.73it/s, Loss=0.1479, Acc=95.25%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 127.99it/s, Loss=0.3322, Acc=90.91%]

Epoch 41 Summary:
  Train Loss: 0.1479, Train Acc: 95.25%
  Test Loss:  0.3322, Test Acc:  90.91%
  Learning Rate: 0.000079
  Best accuracy so far: 91.00%

Epoch 42/50
------------------------------------------------------------
Epoch [42/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.34it/s, Loss=0.1396, Acc=95.51%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 128.65it/s, Loss=0.3289, Acc=90.85%]

Epoch 42 Summary:
  Train Loss: 0.1396, Train Acc: 95.51%
  Test Loss:  0.3289, Test Acc:  90.85%
  Learning Rate: 0.000063
  Best accuracy so far: 91.00%

Epoch 43/50
------------------------------------------------------------
Epoch [43/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.57it/s, Loss=0.1341, Acc=95.71%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 119.33it/s, Loss=0.3246, Acc=91.08%]

Epoch 43 Summary:
  Train Loss: 0.1341, Train Acc: 95.71%
  Test Loss:  0.3246, Test Acc:  91.08%
  Learning Rate: 0.000049
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 91.08%

Epoch 44/50
------------------------------------------------------------
Epoch [44/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 48.10it/s, Loss=0.1290, Acc=95.87%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 121.71it/s, Loss=0.3253, Acc=91.08%]

Epoch 44 Summary:
  Train Loss: 0.1290, Train Acc: 95.87%
  Test Loss:  0.3253, Test Acc:  91.08%
  Learning Rate: 0.000036
  Best accuracy so far: 91.08%

Epoch 45/50
------------------------------------------------------------
Epoch [45/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 48.58it/s, Loss=0.1268, Acc=95.93%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 124.60it/s, Loss=0.3236, Acc=90.93%]

Epoch 45 Summary:
  Train Loss: 0.1268, Train Acc: 95.93%
  Test Loss:  0.3236, Test Acc:  90.93%
  Learning Rate: 0.000025
  Best accuracy so far: 91.08%

Epoch 46/50
------------------------------------------------------------
Epoch [46/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 48.18it/s, Loss=0.1255, Acc=95.95%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 124.80it/s, Loss=0.3289, Acc=91.12%]

Epoch 46 Summary:
  Train Loss: 0.1255, Train Acc: 95.95%
  Test Loss:  0.3289, Test Acc:  91.12%
  Learning Rate: 0.000017
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 91.12%

Epoch 47/50
------------------------------------------------------------
Epoch [47/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 47.63it/s, Loss=0.1169, Acc=96.23%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 116.13it/s, Loss=0.3302, Acc=91.25%]

Epoch 47 Summary:
  Train Loss: 0.1169, Train Acc: 96.23%
  Test Loss:  0.3302, Test Acc:  91.25%
  Learning Rate: 0.000010
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 91.25%

Epoch 48/50
------------------------------------------------------------
Epoch [48/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:07<00:00, 49.47it/s, Loss=0.1177, Acc=96.20%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 121.34it/s, Loss=0.3267, Acc=91.17%]

Epoch 48 Summary:
  Train Loss: 0.1177, Train Acc: 96.20%
  Test Loss:  0.3267, Test Acc:  91.17%
  Learning Rate: 0.000005
  Best accuracy so far: 91.25%

Epoch 49/50
------------------------------------------------------------
Epoch [49/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 48.47it/s, Loss=0.1141, Acc=96.31%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 128.37it/s, Loss=0.3244, Acc=91.30%]

Epoch 49 Summary:
  Train Loss: 0.1141, Train Acc: 96.31%
  Test Loss:  0.3244, Test Acc:  91.30%
  Learning Rate: 0.000002
Checkpoint saved to vgg_cifar10_adam.pth
  ✓ New best accuracy: 91.30%

Epoch 50/50
------------------------------------------------------------
Epoch [50/50]: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 391/391 [00:08<00:00, 45.87it/s, Loss=0.1171, Acc=96.25%]
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 123.41it/s, Loss=0.3267, Acc=91.22%]

Epoch 50 Summary:
  Train Loss: 0.1171, Train Acc: 96.25%
  Test Loss:  0.3267, Test Acc:  91.22%
  Learning Rate: 0.000001
  Best accuracy so far: 91.30%

============================================================
Training completed! Best accuracy: 91.30%
============================================================

Final evaluation on test set...
Testing: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 79/79 [00:00<00:00, 126.94it/s, Loss=0.3267, Acc=91.22%]
Final test accuracy: 91.22%

Per-class accuracy:
plane     : 93.00%
car       : 96.40%
bird      : 87.40%
cat       : 81.90%
deer      : 91.70%
dog       : 85.80%
frog      : 92.80%
horse     : 93.10%
ship      : 95.40%
truck     : 94.70%

Training history plot saved as "training_history.png"

============================================================
Example of loading trained model for inference:
============================================================
Model loaded with accuracy: 91.30%

Sample prediction:
  True class: cat
  Predicted: cat
  Confidence: 0.9976

Top-3 predictions:
  cat       : 99.76%
  dog       : 0.23%
  frog      : 0.01%

Batch prediction example (5 samples):

Sample 1:
  True: cat
  Predicted: cat
  Confidence: 0.9976
  Correct: True

Sample 2:
  True: ship
  Predicted: ship
  Confidence: 1.0000
  Correct: True

Sample 3:
  True: ship
  Predicted: ship
  Confidence: 0.9998
  Correct: True

Sample 4:
  True: plane
  Predicted: plane
  Confidence: 0.9820
  Correct: True

Sample 5:
  True: frog
  Predicted: frog
  Confidence: 1.0000
  Correct: True
相关推荐
腾视科技2 小时前
什么是AI算力模组?
人工智能
Funny_AI_LAB2 小时前
从手动调参到多智能体编排:ChatDev 2.0 正在重构我们的开发范式
人工智能·ai·重构·agi
予枫的编程笔记2 小时前
【Java进阶】深度解密 AQS:Java 并发包背后的“灵魂骨架”
人工智能
feifeigo1232 小时前
基于深度学习的刀具磨损状态实时监测
人工智能·深度学习
丝斯20112 小时前
AI学习笔记整理(45)——大模型数据读取技术与模型部署
人工智能·笔记·学习
大模型最新论文速读2 小时前
RelayLLM:token 级大小模型接力加速推理
论文阅读·人工智能·深度学习·机器学习·自然语言处理
智驱力人工智能2 小时前
矿场轨道异物AI监测系统 构建矿山运输安全的智能感知防线 轨道异物检测 基于YOLO的轨道异物识别算法 地铁隧道轨道异物实时预警技术
人工智能·opencv·算法·安全·yolo·边缘计算
杜子不疼.2 小时前
【AI】重构知识体系:跨模态信息处理与关联理解
人工智能·重构
设计是门艺术2 小时前
2026 工作总结 PPT 生成工具 TOP5!
人工智能