Ejemplo n.º 1
0
test_transform = transforms.Compose([
    transforms.Resize((256, 256)),
    transforms.CenterCrop(224),
    transforms.ToTensor(),
    normalize
])

dataset_train = opts.dataset(opts.data, train=True, transform=train_transform, download=True)
dataset_train_eval = opts.dataset(opts.data, train=True, transform=test_transform, download=True)
dataset_eval = opts.dataset(opts.data, train=False, transform=test_transform, download=True)

print("Number of images in Training Set: %d" % len(dataset_train))
print("Number of images in Test set: %d" % len(dataset_eval))

loader_train_sample = DataLoader(dataset_train, batch_sampler=NPairs(dataset_train,
                                                                     opts.batch,
                                                                     m=opts.num_image_per_class,
                                                                     iter_per_epoch=opts.iter_per_epoch),
                                 pin_memory=True, num_workers=opts.num_workers)
loader_train_eval = DataLoader(dataset_train_eval, shuffle=False, batch_size=opts.batch, drop_last=False,
                               pin_memory=False, num_workers=opts.num_workers)
loader_eval = DataLoader(dataset_eval, shuffle=False, batch_size=opts.batch, drop_last=False,
                         pin_memory=True, num_workers=opts.num_workers)

model = LinearEmbedding(base_model,
                        output_size=base_model.output_size,
                        embedding_size=opts.embedding_size,
                        normalize=not opts.no_normalize).cuda()


if opts.load is not None:
    model.load_state_dict(torch.load(opts.load))
Ejemplo n.º 2
0
dataset_train_eval = opts.dataset(opts.data,
                                  train=True,
                                  transform=test_transform,
                                  download=True)
dataset_eval = opts.dataset(opts.data,
                            train=False,
                            transform=test_transform,
                            download=True)

print(len(dataset_train))
print(len(dataset_eval))

loader_train_sample = DataLoader(dataset_train,
                                 batch_sampler=NPairs(
                                     dataset_train,
                                     opts.batch,
                                     m=5,
                                     iter_per_epoch=opts.iter_per_epoch),
                                 pin_memory=True,
                                 num_workers=opts.num_workers)
loader_train = DataLoader(dataset_train_eval,
                          shuffle=False,
                          batch_size=opts.batch,
                          drop_last=False,
                          pin_memory=False,
                          num_workers=opts.num_workers)

loader_eval_sample = DataLoader(dataset_eval,
                                batch_sampler=NPairs(
                                    dataset_train,
                                    opts.batch,
Ejemplo n.º 3
0
])

dataset_train = opts.dataset(opts.data,
                             train=True,
                             transform=train_transform,
                             download=True)
dataset_eval = opts.dataset(opts.data,
                            train=False,
                            transform=test_transform,
                            download=True)

print(len(dataset_train))
print(len(dataset_eval))

loader_train = DataLoader(dataset_train,
                          batch_sampler=NPairs(dataset_train, opts.batch, m=5),
                          num_workers=1,
                          pin_memory=True)
loader_eval = DataLoader(dataset_eval,
                         shuffle=False,
                         batch_size=opts.batch,
                         drop_last=False,
                         num_workers=1,
                         pin_memory=True)

if opts.no_embedding:
    model = NoEmbedding(base_model, normalize=not opts.no_normalize).cuda()
else:
    model = LinearEmbedding(base_model,
                            output_size=base_model.output_size,
                            embedding_size=opts.embedding_size,