def build_train_dataset(self):
     transform = transforms.Compose([
         transforms.Resize(240),
         transforms.RandomCrop(224),
         transforms.RandomHorizontalFlip(),
         transforms.ToTensor(),
         transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
     ])
     ds = CatDogDataset(self.data_dir, train=True, transform=transform)
     return ds
Example #2
0
mean = [0.485, 0.456, 0.406]
std = [0.229, 0.224, 0.225]
transform = transforms.Compose([
    transforms.Resize(image_size),
    # transforms.Grayscale(),
    transforms.ToTensor(),
    transforms.Normalize(mean, std)
])

path = '/home/aims/Documents/Pytorch/pytorch_exercise/data'

net = Classification()
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9)

train_data = CatDogDataset(path + "/" + 'train', transform=transform)
test_data = CatDogDataset(path + "/" + 'val', transform=transform)

trainloader = torch.utils.data.DataLoader(test_data,
                                          batch_size=64,
                                          shuffle=True,
                                          num_workers=4)
testloader = torch.utils.data.DataLoader(test_data,
                                         batch_size=64,
                                         shuffle=True,
                                         num_workers=4)
#Training

for epoch in range(10):  # loop over the dataset multiple times

    running_loss = 0.0
 def build_test_dataset(self):
     ds = CatDogDataset(self.data_dir, train=False, transform=self.test_transform)
     return ds