weiaicunzai / pytorch-cifar100

Practice on cifar100(ResNet, DenseNet, VGG, GoogleNet, InceptionV3, InceptionV4, Inception-ResNetv2, Xception, Resnet In Resnet, ResNext,ShuffleNet, ShuffleNetv2, MobileNet, MobileNetv2, SqueezeNet, NasNet, Residual Attention Network, SENet, WideResNet)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I change to my own data set

6sz opened this issue · comments

My data set has three categories in three folders. How can I change the code that reads the data

If your dataset is a image classification dataset, you could implement your own dataset class to read your data.

see more details here:
https://pytorch.org/docs/stable/data.html#torch.utils.data.Dataset

If your dataset is a image classification dataset, you could implement your own dataset class to read your data.

see more details here:
https://pytorch.org/docs/stable/data.html#torch.utils.data.Dataset

I tried implement my dataset class, seems like loading goes well but there was an error when I trained, not sure whether you met this before, thanks in advance, here the message:

Traceback (most recent call last):
File "train.py", line 209, in
train(epoch)
File "train.py", line 44, in train
outputs = net(images)
File "\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
result = self.forward(input, **kwargs)
File "
\pytorch-cifar100\pytorch-cifar100\models\vgg.py", line 40, in forward
output = self.classifier(output)
File "
\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
result = self.forward(input, **kwargs)
File "
\lib\site-packages\torch\nn\modules\container.py", line 117, in forward
input = module(input)
File \lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
result = self.forward(input, **kwargs)
File "
\lib\site-packages\torch\nn\modules\linear.py", line 93, in forward
return F.linear(input, self.weight, self.bias)
File "
************\lib\site-packages\torch\nn\functional.py", line 1690, in linear
ret = torch.addmm(bias, input, weight.t())
RuntimeError: mat1 dim 1 must match mat2 dim 0

If your dataset is a image classification dataset, you could implement your own dataset class to read your data.
see more details here:
https://pytorch.org/docs/stable/data.html#torch.utils.data.Dataset

I tried implement my dataset class, seems like loading goes well but there was an error when I trained, not sure whether you met this before, thanks in advance, here the message:

Traceback (most recent call last):
File "train.py", line 209, in
train(epoch)
File "train.py", line 44, in train
outputs = net(images)
File "\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl result = self.forward(input, **kwargs) File "\pytorch-cifar100\pytorch-cifar100\models\vgg.py", line 40, in forward output = self.classifier(output) File "\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl result = self.forward(input, **kwargs) File "\lib\site-packages\torch\nn\modules\container.py", line 117, in forward
input = module(input)
File \lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl result = self.forward(input, **kwargs) File "\lib\site-packages\torch\nn\modules\linear.py", line 93, in forward return F.linear(input, self.weight, self.bias) File "************\lib\site-packages\torch\nn\functional.py", line 1690, in linear
ret = torch.addmm(bias, input, weight.t())
RuntimeError: mat1 dim 1 must match mat2 dim 0

请检查一下你的output = self.classifier(output)前后,是否tensor的size发生了改变,tensor的形状要对齐

use function "torchvision.datasets.ImageFolder(root='path to your dir')" instead of function "torchvision.datasets.CIFAR100" in utils.py

commented

the cifar100 train image size:80x80, but when load train data only crop 32x32,
transform_train = transforms.Compose([
#transforms.ToPILImage(),
transforms.RandomCrop(32, padding=4),
transforms.RandomHorizontalFlip(),
transforms.RandomRotation(15),
transforms.ToTensor(),
transforms.Normalize(mean, std)
])
test image size:32x32, didn't need to crop image;
change FC layer depend on your input image size
self.classifier = nn.Sequential(
# nn.Linear(512, 4096), # modify fc connect layer input size
nn.Linear(51277, 4096),
When train your own datasets,you must keep train and test size equality, use the same transform!!! #36

How should we change if input image size is 100*100? Thanks!

My dataset is a csv file. How to change it