Пример #1
0
 def testTrainingSize(self):
     batch_size = 50
     problem = STL10Problem(mini_batch_size=batch_size)
     self.assertEqual(5000, len(problem._trainset))
     with open("./data/stl10_binary/fold_indices.txt") as folds:
         fold_definitions = folds.readlines()
         fold = fold_definitions[0]
         splitted = fold.split(sep=" ")
         splitted.remove("\n")
         self.assertEqual(1000, len(splitted))
         train_indices = [int(index) for index in splitted]
         reduced_problem = CrossValidatedProblem(problem, train_indices)
         self.assertEqual(1000,
                          len(reduced_problem.train_loader()) * batch_size)
         self.assertEqual(4000,
                          len(reduced_problem.test_loader()) * batch_size)
Пример #2
0
    parser.add_argument('--problem',
                        default="CIFAR10",
                        type=str,
                        help='The problem, either CIFAR10 or STL10')
    args = parser.parse_args()
    if args.checkpoint_key is None:
        print("You must specify a checkpoint key.")
        exit(1)

    print("Loading pre-trained model " + args.checkpoint_key)
    use_cuda = torch.cuda.is_available()
    if use_cuda:
        print("With CUDA")
    else:
        print("With CPU")

    if args.problem == "CIFAR10":
        problem = Cifar10Problem(1)
    elif args.problem == "STL10":
        problem = STL10Problem(1)
    else:
        print("Unsupported problem: " + args.problem)
        exit(1)

    model_trainer = TrainModelSplit(args=args,
                                    problem=problem,
                                    use_cuda=use_cuda)
    model_trainer.net = model_trainer.load_pretrained_model()
    model_trainer.net.cpu()
    model_trainer.save_pretrained_model()
    print("Model converted to CPU.")
Пример #3
0
            confusion_data += [Confusion(bool(trained_with == "True"), int(example_index), int(epoch), \
                                             float(train_loss), int(predicted_label), int(true_label), float(val_loss))]
    distinct_validation_losses = list(set([cd.val_loss for cd in confusion_data]))
    distinct_validation_losses.sort()
    distinct_validation_losses.reverse()
    print("Read the following validation losses: " + " ".join(map(str, distinct_validation_losses)))

    use_cuda = torch.cuda.is_available()
    is_parallel = False
    best_acc = 0  # best test accuracy
    start_epoch = 0  # start from epoch 0 or last checkpoint epoch
    problem = None
    if args.problem == "CIFAR10":
        problem = Cifar10Problem(args.mini_batch_size)
    elif args.problem == "STL10":
        problem = STL10Problem(args.mini_batch_size)
    else:
        print("Unsupported problem: " + args.problem)
        exit(1)

    if args.score_threshold is not None:
        confusion_data=[c for c in confusion_data if c.val_loss<=args.score_threshold]

    use_cuda = torch.cuda.is_available()
    print("Loaded {} lines of confusion data".format(len(confusion_data)))

    print("Loading pre-trained image model from {}".format(args.checkpoint_key))
    image_model = TrainModelSplit(args, problem, use_cuda).load_checkpoint()

    helper = ConfusionTrainingHelper(image_model, problem, args, use_cuda)
    random.shuffle(confusion_data)