In order to classify images with pytorch, I modified my local data while using ImageFolder based on the following URL
https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html 104
However,”RuntimeError: shape ‘[-1, 400]’ is invalid for input of size” is displayed and I do not know the cause.
I asked you because I do not know how to fix it,please.

import torch
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
transform = transforms.Compose(
[transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
data_transform = transforms.Compose([
transforms.RandomResizedCrop(224),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
#transforms.Normalize(mean=[0.485, 0.456, 0.406],
#                  std=[0.229, 0.224, 0.225])
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
] )
#rootはローカルのアドレスがあると考えてください
trainset = torchvision.datasets.ImageFolder(root=‘my local dataset’, transform=data_transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=4,
shuffle=False, num_workers=2)
testset = torchvision.datasets.ImageFolder(root=‘my local dataset’, transform=data_transform)
testloader = torch.utils.data.DataLoader(testset, batch_size=4,
shuffle=False, num_workers=2)
classes = (‘１’, ‘２’, ‘３’, ‘４’,
‘５’, ‘６’, ‘７’, ‘８’, ‘９’)
class Net(nn.Module):
def init(self):
super(Net, self).init()
self.conv1 = nn.Conv2d(3, 6, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16 * 5 * 5, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 10)
def forward(self, x):
    x = self.pool(F.relu(self.conv1(x)))
    x = self.pool(F.relu(self.conv2(x)))
    x = x.view(-1, 16 * 5 * 5)
    x = F.relu(self.fc1(x))
    x = F.relu(self.fc2(x))
    x = self.fc3(x)
    return x

net = Net()
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9)
for epoch in range(2):  # loop over the dataset multiple times
running_loss = 0.0
for i, data in enumerate(trainloader, 0):
    # get the inputs
    inputs, labels = data

    # zero the parameter gradients
    optimizer.zero_grad()

    # forward + backward + optimize
    outputs = net(inputs)
    loss = criterion(outputs, labels)
    loss.backward()
    optimizer.step()

    # print statistics
    running_loss += loss.item()
    if i % 2000 == 1999:    # print every 2000 mini-batches
        print('[%d, %5d] loss: %.3f' %
              (epoch + 1, i + 1, running_loss / 2000))
        running_loss = 0.0

print(‘Finished Training’)

RuntimeError                              Traceback (most recent call last)
 in ()
11
12         # forward + backward + optimize
—> 13         outputs = net(inputs)
14         loss = criterion(outputs, labels)
15
~/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
487             result = self._slow_forward(*input, **kwargs)
488         else:
–> 489             result = self.forward(*input, **kwargs)
490         for hook in self._forward_hooks.values():
491             hook_result = hook(self, input, result)
 in forward(self, x)
14         x = self.pool(F.relu(self.conv2(x)))
15         x = x.contiguous()
—> 16         x = x.view(-1, 16 * 5 * 5)
17         x = F.relu(self.fc1(x))
18         x = F.relu(self.fc2(x))
RuntimeError: shape ‘[-1, 400]’ is invalid for input of size 87616