Ejemplo n.º 1
0
	def _init_model(self):

		"""
		model definition
		"""	
		self.encoder, self.decoder, self.prediction_model = load_model(self.opt)



		print("LEARNING RATE: ",self.opt.base_learning_rate)

		self.X = torch.FloatTensor(self.opt.batch_size, self.opt.num_channels, self.opt.image_size, self.opt.image_size)

		self.style_latent_space = torch.FloatTensor(self.opt.batch_size, self.opt.style_dim)


		if self.use_gpu:
			self.device = torch.device('cuda')

			self.encoder.cuda()
			self.prediction_model.cuda()

			self.decoder.cuda()

			self.X = self.X.cuda()

			self.style_latent_space = self.style_latent_space.cuda()


		self.load_encoder()
		self.load_decoder()
    def _init_model(self):

        self.encoder, self.classifier_model = load_model(self.opt)

        print("LEARNING RATE: ", self.opt.base_learning_rate)

        self.X_1 = torch.FloatTensor(self.opt.batch_size,
                                     self.opt.num_channels,
                                     self.opt.image_size, self.opt.image_size)
        self.X_2 = torch.FloatTensor(self.opt.batch_size,
                                     self.opt.num_channels,
                                     self.opt.image_size, self.opt.image_size)
        self.X_3 = torch.FloatTensor(self.opt.batch_size,
                                     self.opt.num_channels,
                                     self.opt.image_size, self.opt.image_size)

        self.style_latent_space = torch.FloatTensor(self.opt.batch_size,
                                                    self.opt.style_dim)

        if self.use_gpu:
            self.device = torch.device('cuda')

            self.encoder.cuda()
            self.classifier_model.cuda()

            self.X_1 = self.X_1.cuda()
            self.X_2 = self.X_2.cuda()
            self.X_3 = self.X_3.cuda()

            self.style_latent_space = self.style_latent_space.cuda()

        self.load_encoder()
Ejemplo n.º 3
0
    def _initialize_model(self):

        self.model_g, self.model_d = load_model(self.opt)

        if (self.use_gpu):
            self.model_g = self.model_g.cuda()
            self.model_d = self.model_d.cuda()
Ejemplo n.º 4
0
    def _initialize_model(self):

        self.model_g, self.model_d = load_model(self.opt)

        if (self.use_gpu):
            self.model_g = self.model_g.cuda()
            self.model_d = self.model_d.cuda()

        self.load_pretrained_weights()
def initialization(configs):
    configs.loader, configs.labels = load_cifar10_dataset(configs)

    model = load_model(configs)

    if torch.cuda.is_available() == True:
        model = nn.DataParallel(model)
        configs.model = model
    else:
        print("Please run the experiment in gpu")
        exit(1)

    configs.criterion = cross_entropy_loss()
    configs.optimizer = get_optimizer(configs)

    train(configs)

    if configs.test:
        test(configs)
def run_experiment(epochs, model_name, training_type, configs):
    """ Runs the basic experiment"""

    print(epochs, "CONFIGS: ", configs)

    # set seed for reproducibility.
    seed = configs.seed
    random.seed(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    # gpu training specific seed settings.
    torch.backends.cudnn.deterministic = True
    torch.backends.cudnn.benchmark = False

    # load data
    loaders = load_dataset(configs)

    # load model
    model = load_model(model_name, training_type, configs)

    # loss
    criterion = nn.CrossEntropyLoss().cuda()

    # optimizer
    # optimizer = optim.SGD(model.parameters(), configs.lr,
    #                       momentum=configs.momentum,
    #                       weight_decay=configs.weight_decay)
    optimizer = optim.Adam(model.parameters(), configs.lr)

    # get tracking dictionaries
    model_weights, layer_dict = setup_delta_tracking(model)

    # train model
    rmae_delta_dict, train_acc_arr, test_acc_arr = training(
        epochs, loaders, model, optimizer, criterion, model_weights,
        layer_dict, configs)

    return rmae_delta_dict, train_acc_arr, test_acc_arr
Ejemplo n.º 7
0
"""
# os.environ["CUDA_VISIBLE_DEVICES"] = "0"
dev = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
logging.info('GPU AVAILABLE? ' + str(torch.cuda.is_available()))

if torch.cuda.is_available():
    torch.cuda.manual_seed(108)
else:
    torch.manual_seed(108)

train_loader, val_loader = get_loaders(opt)
"""
Load Model then define other aspects of the model
"""
logging.info('LOADING Model')
model = load_model(opt, dev)

criterion = get_criterion(opt)
# optimizer = optim.AdamW(model.parameters(), lr=opt.learning_rate)
optimizer = AdamW(model.parameters(), lr=opt.learning_rate)
scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=8, gamma=0.5)
"""
 Set starting values
"""
best_metrics = {'cd_f1scores': -1, 'cd_recalls': -1, 'cd_precisions': -1}
logging.info('STARTING training')
best_pre, best_recall, best_f1 = [-1, -1], [-1, -1], [-1, -1]
total_step = -1

for epoch in range(opt.epochs):
    train_metrics = initialize_metrics()