How to increase accuracy on CIFAR dataset

average_ml_enjoyer: <p>Hi guys! i’ve been training my model on the CIFAR dataset, but its testing accuracy seems to stop at 70% no matter how I tweak the hyperparameters, has this simple CNN model reached its limit on this dataset? If so then how can I know if it did?<br>
import pandas as pd<br>
import torch<br>
from torch.utils.data import TensorDataset, DataLoader<br>
from sklearn.model_selection import train_test_split<br>
from sklearn.preprocessing import StandardScaler<br>
import torch.nn as nn<br>
import torch.optim as optim<br>
from torchvision.transforms import ToTensor<br>
import matplotlib.pyplot as plt<br>
import torchvision<br>
import torchvision.transforms as transforms<br>
from torch.utils.data import TensorDataset, DataLoader, Subset</p>
<h1><a name="check-if-cuda-is-available-1" class="anchor" href="#check-if-cuda-is-available-1"></a>Check if CUDA is available</h1>
<p>cuda_available = torch.cuda.is_available()<br>
print(f"CUDA available: {cuda_available}")</p>
<h1><a name="print-the-name-of-the-gpu-2" class="anchor" href="#print-the-name-of-the-gpu-2"></a>Print the name of the GPU</h1>
<p>if cuda_available:<br>
device=“cuda”<br>
print(f"GPU: {torch.cuda.get_device_name(0)}")<br>
else:<br>
device=“cpu”<br>
<span class="hashtag-raw">#import</span> data<br>
transform = transforms.Compose([transforms.ToTensor(),transforms.Normalize((0.5,0.5,0.5),(0.5,0.5,0.5))])<br>
temp_data = torchvision.datasets.CIFAR10(root=“data”,train=True,download=True,transform=transform)<br>
test_data = torchvision.datasets.CIFAR10(root=“data”,train=False,download=True,transform=transform)<br>
train_indices, val_indices = train_test_split(list(range(len(temp_data))), test_size=0.2, shuffle=True)<br>
train_data = Subset(temp_data, train_indices)<br>
val_data = Subset(temp_data, val_indices)<br>
train_dataloader = DataLoader(train_data, batch_size=80, shuffle = True)<br>
val_dataloader = DataLoader(val_data, batch_size=len(val_data), shuffle=True)<br>
test_dataloader = DataLoader(val_data, batch_size=len(test_data), shuffle=True)</p>
<h1><a name="get-a-batch-of-data-from-the-dataloader-3" class="anchor" href="#get-a-batch-of-data-from-the-dataloader-3"></a>Get a batch of data from the DataLoader</h1>
<p>for batch in val_dataloader:<br>
x_val, y_val = batch<br>
x_val, y_val = x_val.to(device), y_val.to(device)<br>
<span class="hashtag-raw">#CNN</span><br>
class model(nn.Module):<br>
def <strong>init</strong>(self):<br>
super(model, self).<strong>init</strong>()<br>
self.conv1 = nn.Sequential(<br>
nn.Conv2d(<br>
in_channels = 3,<br>
out_channels = 16,<br>
kernel_size = 3,<br>
stride = 1,<br>
padding = 1,<br>
),<br>
nn.BatchNorm2d(16),<br>
nn.ReLU(),<br>
nn.MaxPool2d(kernel_size = 2)<br>
)<br>
self.conv2 = nn.Sequential(<br>
nn.Conv2d(<br>
in_channels = 16,<br>
out_channels = 32,<br>
kernel_size = 5,<br>
stride = 1,<br>
padding = 1,<br>
),<br>
nn.BatchNorm2d(32),<br>
nn.ReLU(),<br>
nn.MaxPool2d(kernel_size = 2)</p>
<pre><code>)
self.out = nn.Sequential(
    nn.Linear(32*7*7, 256),
    nn.ReLU(),
    nn.Linear(256, 10)
    )
</code></pre>
<p>def forward(self, x):<br>
x = self.conv1(x)<br>
x = self.conv2(x)</p>
<pre><code>x = x.view(-1, 32*7*7)
x = self.out(x)
return x
</code></pre>
<p>model = model()<br>
model = model.to(device)<br>
<span class="hashtag-raw">#hyperparameters</span><br>
learning_rate = 0.01<br>
optimizer = optim.SGD(model.parameters(), lr=learning_rate, momentum = 0.5, weight_decay = 0.001)<br>
epochs = 20<br>
train_loss = <span class="chcklst-box fa fa-square-o fa-fw"></span><br>
vali_loss = <span class="chcklst-box fa fa-square-o fa-fw"></span><br>
test_loss_list = <span class="chcklst-box fa fa-square-o fa-fw"></span><br>
loss_fn = nn.CrossEntropyLoss()<br>
<span class="hashtag-raw">#train</span> loop<br>
def train_loop(dataloader, model, loss_fn, optimizer):<br>
size = len(dataloader.dataset)<br>
model.train()<br>
for batch, (x, Y) in enumerate(train_dataloader):<br>
x, Y = x.to(device), Y.to(device)<br>
pred = model(x)<br>
optimizer.zero_grad()<br>
loss = loss_fn(pred, Y)<br>
loss.backward()</p>
<pre><code>optimizer.step()

if batch%500 == 0:
  model.eval()
  val_loss = loss_fn(model(x_val), y_val).item()
  current = (batch + 1) * len(x)
  print(f"loss:{loss:&gt;7f}[{current:&gt;5d}/{size:&gt;5d}]")
</code></pre>
<p>train_loss.append(loss.item())<br>
vali_loss.append(val_loss)</p>
<p><span class="hashtag-raw">#test</span> loop<br>
def test_loop(dataloader, model, loss_fn, optimizer):<br>
model.eval()<br>
count = 0<br>
test_loss = 0<br>
size = 0<br>
num_batches = len(dataloader)</p>
<p>with torch.no_grad():<br>
for x, y in dataloader:</p>
<pre><code>x, y = x.to(device), y.to(device)
pred = model(x)
test_loss += loss_fn(pred, y).item()
count += (pred.argmax(1) == y).sum().item()
size += y.size(0)
</code></pre>
<p>test_loss = test_loss / num_batches<br>
accuracy = count / size<br>
print(f"Test Loss: {test_loss:.4f}, Accuracy: {accuracy:.4f}")<br>
test_loss_list.append(test_loss)</p>
<p>for x in range(epochs):<br>
print(f"epoch{x+1}\n")<br>
train_loop(train_dataloader, model, loss_fn, optimizer)<br>
test_loop(test_dataloader, model, loss_fn, optimizer)<br>
plt.plot(train_loss, label = “train loss”)<br>
plt.plot(test_loss_list, label = “test loss”)<br>
plt.plot(vali_loss, label = “vali loss”)<br>
plt.xlabel(“epoch”)<br>
plt.ylabel(“loss”)<br>
plt.title(“learning curve”)<br>
plt.legend()<br>
plt.show()</p>