您的位置:

CIFAR100数据集阐述

一、CIFAR100分类

CIFAR100是一个包含100个类别的图像数据集,每个类别包含600张图像,其中有500个用于训练,100个用于测试。cifar100的图像尺寸为32×32像素,RGB三通道,总共有50000个训练样本和10000个测试样本。

二、CIFAR100数据集准确率

在先进的卷积神经网络的帮助下,CIFAR100被广泛用于深度学习的模型训练和比较。最先进的卷积神经网络在CIFAR100测试集上的平均准确性为87%左右。

三、CIFAR100数据集大小

CIFAR100数据集的大小为174.6MB。该数据集包含Python版本的元数据和文件。你可以从官方网站上下载和使用它,以便对深度学习模型进行训练和测试。

四、CIFAR100准确率排名

近年来,对CIFAR100数据集表现最佳的模型是图像分类中的ResNet模型,具有巨大的深度和高度优化的结构。最优的ResNet模型在CIFAR100数据集上的测试准确率高达81%。与此同时,在不使用任何卷积或全连接层的情况下,FITNET在CIFAR100数据集上获得了可以接受的准确性,其测试准确率约为74%。

五、CIFAR100最高准确率

import torch
import torch.optim as optim
import torchvision
import torchvision.transforms as transforms
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import DataLoader
from torchvision.datasets import CIFAR100


class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = nn.Conv2d(3, 96, 3, padding=1)
        self.conv2 = nn.Conv2d(96, 96, 3, padding=1)
        self.conv3 = nn.Conv2d(96, 96, 3, stride=2, padding=1)
        self.conv4 = nn.Conv2d(96, 192, 3, padding=1)
        self.conv5 = nn.Conv2d(192, 192, 3, padding=1)
        self.conv6 = nn.Conv2d(192, 192, 3, stride=2, padding=1)
        self.conv7 = nn.Conv2d(192, 192, 3, padding=1)
        self.conv8 = nn.Conv2d(192, 192, 1)
        self.conv9 = nn.Conv2d(192, 100, 1)
        self.fc1 = nn.Linear(4096, 1024)
        self.fc2 = nn.Linear(1024, 100)
        self.pool = nn.MaxPool2d(3, stride=2)
        self.dropout1 = nn.Dropout2d(0.5)
        self.dropout2 = nn.Dropout()

    def forward(self, x):
        x = F.relu(self.conv1(x))
        x = F.relu(self.conv2(x))
        x = self.conv3(x)
        x = self.dropout1(x)
        x = F.relu(self.conv4(x))
        x = F.relu(self.conv5(x))
        x = self.conv6(x)
        x = self.dropout1(x)
        x = F.relu(self.conv7(x))
        x = F.relu(self.conv8(x))
        x = self.conv9(x)
        x = self.pool(x)
        x = x.view(-1, 4096)
        x = F.relu(self.fc1(x))
        x = self.dropout2(x)
        x = self.fc2(x)
        return x


transform_train = transforms.Compose(
    [transforms.RandomCrop(32, padding=4),
     transforms.RandomHorizontalFlip(),
     transforms.ToTensor(),
     transforms.Normalize((0.5071, 0.4867, 0.4408), (0.2675, 0.2565, 0.2761))])

transform_test = transforms.Compose(
    [transforms.ToTensor(),
     transforms.Normalize((0.5071, 0.4867, 0.4408), (0.2675, 0.2565, 0.2761))])

train_set = CIFAR100(root='./data', train=True, download=True, transform=transform_train)
train_loader = DataLoader(train_set, batch_size=128, shuffle=True, num_workers=2)

test_set = CIFAR100(root='./data', train=False, download=True, transform=transform_test)
test_loader = DataLoader(test_set, batch_size=128, shuffle=False, num_workers=2)

classes = ('apple', 'aquarium_fish', 'baby', 'bear', 'beaver', 'bed', 'bee', 'beetle', 'bicycle', 'bottle', 'bowl', 'boy',
           'bridge', 'bus', 'butterfly', 'camel', 'can', 'castle', 'caterpillar', 'cattle', 'chair', 'chimpanzee',
           'clock', 'cloud', 'cockroach', 'couch', 'crab', 'crocodile', 'cup', 'dinosaur', 'dolphin', 'elephant',
           'flatfish', 'forest', 'fox', 'girl', 'hamster', 'house', 'kangaroo', 'keyboard', 'lamp', 'lawn_mower',
           'leopard', 'lion', 'lizard', 'lobster', 'man', 'maple_tree', 'motorcycle', 'mountain', 'mouse', 'mushroom',
           'oak_tree', 'orange', 'orchid', 'otter', 'palm_tree', 'pear', 'pickup_truck', 'pine_tree', 'plain',
           'plate', 'poppy', 'porcupine', 'possum', 'rabbit', 'raccoon', 'ray', 'road', 'rocket', 'rose', 'sea',
           'seal', 'shark', 'shrew', 'skunk', 'skyscraper', 'snail', 'snake', 'spider', 'squirrel', 'streetcar',
           'sunflower', 'sweet_pepper', 'table', 'tank', 'telephone', 'television', 'tiger', 'tractor',
           'train', 'trout', 'tulip', 'turtle', 'wardrobe', 'whale', 'willow_tree', 'wolf', 'woman', 'worm')

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model = Net().to(device)

optimizer = optim.SGD(model.parameters(), lr=0.1, momentum=0.9, weight_decay=0.0001, nesterov=True)
scheduler = optim.lr_scheduler.MultiStepLR(optimizer, milestones=[300, 350], gamma=0.1)
criterion = nn.CrossEntropyLoss()

def train(epoch):
    model.train()
    train_loss = 0
    correct = 0
    total = 0
    for batch_idx, (inputs, targets) in enumerate(train_loader):
        inputs, targets = inputs.to(device), targets.to(device)
        optimizer.zero_grad()
        outputs = model(inputs)
        loss = criterion(outputs, targets)
        loss.backward()
        optimizer.step()

        train_loss += loss.item()
        _, predicted = outputs.max(1)
        total += targets.size(0)
        correct += predicted.eq(targets).sum().item()

    print('Epoch:%d, Loss: %.3f | Acc: %.3f%% (%d/%d)'
          % (epoch, train_loss / (batch_idx + 1), 100. * correct / total, correct, total))


def test(epoch):
    model.eval()
    test_loss = 0
    correct = 0
    total = 0
    with torch.no_grad():
        for batch_idx, (inputs, targets) in enumerate(test_loader):
            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()

        print('Epoch:%d, Test_loss: %.3f | Test_acc: %.3f%% (%d/%d)'
              % (epoch, test_loss / (batch_idx + 1), 100. * correct / total, correct, total))

        return correct / total


best_acc = 0.0
for epoch in range(1, 400):
    train(epoch)
    acc = test(epoch)
    best_acc = max(best_acc, acc)
    if epoch == 200 or epoch == 300 or epoch == 350 or epoch == 380:
        torch.save(model.state_dict(), 'ckpt_epoch_{}.pth'.format(epoch))
    scheduler.step()

print("最高准确率:%.3f" % (best_acc * 100))