Esempio n. 1
0
extractor = Extractor()
s1_classifier = Classifier(num_classes=num_classes)
s2_classifier = Classifier(num_classes=num_classes)
s3_classifier = Classifier(num_classes=num_classes)
s1_t_discriminator = Discriminator()
s2_t_discriminator = Discriminator()
s3_t_discriminator = Discriminator()

extractor.load_state_dict(
    torch.load(
        osp.join(
            MAIN_DIR,
            "MSDA/A_W_2_D_Open/bvlc_A_W_2_D/pretrain/bvlc_extractor.pth")))
extractor = nn.DataParallel(extractor)
extractor = extractor.cuda()

s1_classifier.load_state_dict(
    torch.load(
        osp.join(
            MAIN_DIR,
            "MSDA/A_W_2_D_Open/bvlc_A_W_2_D/pretrain/office-home/bvlc_s1_cls.pth"
        )))
s2_classifier.load_state_dict(
    torch.load(
        osp.join(
            MAIN_DIR,
            "MSDA/A_W_2_D_Open/bvlc_A_W_2_D/pretrain/office-home/bvlc_s2_cls.pth"
        )))
s3_classifier.load_state_dict(
    torch.load(
Esempio n. 2
0
        pbar.update(1)
        im, ann, im_fns = data[0], data[1], data[2]
        im = im.cuda()
        feat = model(im)
        x = feat.cpu().numpy()
        y = ann.numpy()

        precision = precision + clf.score(x, y)
    pbar.close()

    print("\nAverage Precision is {}".format(precision / len(loader)))


if __name__ == '__main__':

    icdar_patches = "./data/icdar2015/patches"

    dataset = ImageFolder(root=icdar_patches, transform=transforms)
    loader = torch.utils.data.DataLoader(dataset, batch_size=20, shuffle=True)

    # extractor for deep features
    model = Extractor()
    model = model.cuda()
    for params in model.parameters():
        params.requires_grad = False

    # vanilla svm
    clf = svm.SVC(kernel="rbf", gamma=10)

    train(loader=loader, model=model, clf=clf)