Ejemplo n.º 1
0
train_set = torchvision.datasets.MNIST(root=data_folder,
                                       train=True,
                                       download=False,
                                       transform=transform)

train_loader = torch.utils.data.DataLoader(train_set,
                                           batch_size=batch_size,
                                           shuffle=True,
                                           num_workers=0)

# testset = torchvision.datasets.MNIST(root=data_folder, train=False,
#                                        download=True, transform=transform)
# testloader = torch.utils.data.DataLoader(testset, batch_size=4,
#                                          shuffle=False, num_workers=2)

featsModel = featuresModel(pretrained=pretrained)
distModel = distanceModel(pretrained=pretrained)
if trainstep <= 1:
    if not pretrained:
        model_weights_init(featsModel)
        model_weights_init(distModel)
else:
    featsModelfilename = '%s/featsModel%s_Iter%i.state' % (model_folder, name,
                                                           trainstep - 1)
    distModelfilename = '%s/distModel%s_Iter%i.state' % (model_folder, name,
                                                         trainstep - 1)
    featsModelfile = torch.load(featsModelfilename)
    distModelfile = torch.load(distModelfilename)
    featsModel.load_state_dict(featsModelfile)
    distModel.load_state_dict(distModelfile)
Ejemplo n.º 2
0
sys.path.insert(0, '../../trainModels')
import lenet

trainstep = 1
delta = 100
lamda = 1
batch_size = 500
learningRate = 1e-3
modelName = "LearnDistanceNoPretrainDistAlexNetAugmentationDelta%iLamda%iBatch%iLR%f" % (
    delta, lamda, batch_size, learningRate)

modelfolder = "trainedModels"

modelfilename = '%s/featsModel%s_Iter%i' % (modelfolder, modelName, trainstep)
modelfile = torch.load(modelfilename + ".state")
model = featuresModel()
model.load_state_dict(modelfile)

Nsamples = 1000
Niter = 1

transform = transforms.Compose(
    [transforms.ToTensor(),
     transforms.Normalize((0.1307, ), (0.3081, ))])

if torch.cuda.is_available():
    datafolder = "/var/tmp/ioannis/data"
else:
    datafolder = "../../data"

trainset = torchvision.datasets.MNIST(root=datafolder,
Ejemplo n.º 3
0
train_set = torchvision.datasets.MNIST(root=data_folder,
                                       train=True,
                                       download=False,
                                       transform=transform)

train_loader = torch.utils.data.DataLoader(train_set,
                                           batch_size=batch_size,
                                           shuffle=True,
                                           num_workers=0)

# testset = torchvision.datasets.MNIST(root=data_folder, train=False,
#                                        download=True, transform=transform)
# testloader = torch.utils.data.DataLoader(testset, batch_size=4,
#                                          shuffle=False, num_workers=2)

featsModel = featuresModel(pretrained=True)
distModel = distanceModel(pretrained=False)
if trainstep <= 1:
    if not pretrained:
        model_weights_init(featsModel)
        model_weights_init(distModel)
else:
    featsModelfilename = '%s/featsModel%s_Iter%i.state' % (model_folder, name,
                                                           trainstep - 1)
    distModelfilename = '%s/distModel%s_Iter%i.state' % (model_folder, name,
                                                         trainstep - 1)
    featsModelfile = torch.load(featsModelfilename)
    distModelfile = torch.load(distModelfilename)
    featsModel.load_state_dict(featsModelfile)
    distModel.load_state_dict(distModelfile)