return 1 length = max - min num_repeat = (weight - min) * (range_right - 1) / length + 1 return num_repeat trainset = torchvision.datasets.MNIST('./data', train=True, download=True, transform=transforms.ToTensor()) trainloader = torch.utils.data.DataLoader(dataset=trainset, shuffle=False) CLASSIFIER_NUM = 9 classifier = AdaBoostClassifier(mlpClassifier) classifier.train(trainloader, classifier_num=CLASSIFIER_NUM) test_dataset = torchvision.datasets.MNIST(root='./data', train=False, download=True, transform=transforms.ToTensor()) test_dataloader = torch.utils.data.DataLoader(test_dataset, shuffle=False) # Test the AdaBoostClassifier correct = 0 for batch_index, (data, target) in enumerate(test_dataloader): # Copy data to GPU if needed data = data.to(device) target = target.to(device) category = classifier.predict(data)
]) trainset = torchvision.datasets.CIFAR10(root='./data', train=True, download=True, transform=transform_train) train_dataloader = torch.utils.data.DataLoader(trainset, batch_size=BATCH_SIZE, shuffle=False) validation_dataloader = torch.utils.data.DataLoader(trainset, batch_size=1, shuffle=False) # Define and train the AdaBoostClassifier classifier = AdaBoostClassifier(ResNetBibdGcClassifier) classifier.train(train_dataloader, validation_dataloader, classifier_num=CLASSIFIER_NUM) transform_test = transforms.Compose([ transforms.ToTensor(), transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2023, 0.1994, 0.2010)), ]) test_dataset = torchvision.datasets.CIFAR10(root='./data', train=False, download=True, transform=transform_test) test_dataloader = torch.utils.data.DataLoader(test_dataset, batch_size=1, shuffle=False) # Test the AdaBoostClassifier