當前位置: 首頁>>代碼示例>>Python>>正文


Python optimizers.get_optimizer方法代碼示例

本文整理匯總了Python中optimizers.get_optimizer方法的典型用法代碼示例。如果您正苦於以下問題:Python optimizers.get_optimizer方法的具體用法?Python optimizers.get_optimizer怎麽用?Python optimizers.get_optimizer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在optimizers的用法示例。


在下文中一共展示了optimizers.get_optimizer方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: import optimizers [as 別名]
# 或者: from optimizers import get_optimizer [as 別名]
def run(config):
    train_dir = config.train.dir

    model = get_model(config).cuda()
    criterion = get_loss(config)
    optimizer = get_optimizer(config, model.parameters())

    checkpoint = utils.checkpoint.get_initial_checkpoint(config)
    if checkpoint is not None:
        last_epoch, step = utils.checkpoint.load_checkpoint(model, optimizer, checkpoint)
    else:
        last_epoch, step = -1, -1

    print('from checkpoint: {} last epoch:{}'.format(checkpoint, last_epoch))
    scheduler = get_scheduler(config, optimizer, last_epoch)

    dataloaders = {split:get_dataloader(config, split, get_transform(config, split))
                   for split in ['train', 'val']}

    writer = SummaryWriter(config.train.dir)
    train(config, model, dataloaders, criterion, optimizer, scheduler,
          writer, last_epoch+1) 
開發者ID:pudae,項目名稱:kaggle-hpa,代碼行數:24,代碼來源:train.py

示例2: run

# 需要導入模塊: import optimizers [as 別名]
# 或者: from optimizers import get_optimizer [as 別名]
def run(config):
    train_dir = config.train.dir

    task = get_task(config)
    optimizer = get_optimizer(config, task.get_model().parameters())

    checkpoint = utils.checkpoint.get_initial_checkpoint(config)
    if checkpoint is not None:
        last_epoch, step = utils.checkpoint.load_checkpoint(task.get_model(),
                                                            optimizer,
                                                            checkpoint)
    else:
        last_epoch, step = -1, -1

    print('from checkpoint: {} last epoch:{}'.format(checkpoint, last_epoch))
    scheduler = get_scheduler(config, optimizer, last_epoch)

    preprocess_opt = task.get_preprocess_opt()
    dataloaders = {split:get_dataloader(config, split,
                                        get_transform(config, split,
                                                      **preprocess_opt))
                   for split in ['train', 'dev']}

    writer = SummaryWriter(config.train.dir)
    train(config, task, dataloaders, optimizer, scheduler,
          writer, last_epoch+1) 
開發者ID:pudae,項目名稱:kaggle-humpback,代碼行數:28,代碼來源:train.py

示例3: __init__

# 需要導入模塊: import optimizers [as 別名]
# 或者: from optimizers import get_optimizer [as 別名]
def __init__(self, args, logger):
        self.args = args
        self.logger = logger
        self.writer = SummaryWriter(args.log_dir)
        cudnn.enabled = True

        # set up model
        self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
        self.model = get_aux_net(args.network.arch)(aux_classes=args.aux_classes + 1, classes=args.n_classes)
        self.model = self.model.to(self.device)

        if args.mode == 'train':
            # set up optimizer, lr scheduler and loss functions
            optimizer = get_optimizer(self.args.training.optimizer)
            optimizer_params = {k: v for k, v in self.args.training.optimizer.items() if k != "name"}
            self.optimizer = optimizer(self.model.parameters(), **optimizer_params)
            self.scheduler = get_scheduler(self.optimizer, self.args.training.lr_scheduler)

            self.class_loss_func = nn.CrossEntropyLoss()

            self.start_iter = 0

            # resume
            if args.training.resume:
                self.load(args.model_dir + '/' + args.training.resume)

            cudnn.benchmark = True

        elif args.mode == 'val':
            self.load(os.path.join(args.model_dir, args.validation.model))
        else:
            self.load(os.path.join(args.model_dir, args.testing.model)) 
開發者ID:Jiaolong,項目名稱:self-supervised-da,代碼行數:34,代碼來源:aux_model.py

示例4: search_once

# 需要導入模塊: import optimizers [as 別名]
# 或者: from optimizers import get_optimizer [as 別名]
def search_once(config, policy):
    model = get_model(config).cuda()
    criterion = get_loss(config)
    optimizer = get_optimizer(config, model.parameters())
    scheduler = get_scheduler(config, optimizer, -1)

    transforms = {'train': get_transform(config, 'train', params={'policies': policy}),
                  'val': get_transform(config, 'val')}
    dataloaders = {split:get_dataloader(config, split, transforms[split])
                   for split in ['train', 'val']}

    score_dict = train(config, model, dataloaders, criterion, optimizer, scheduler, None, 0)
    return score_dict['f1_mavg'] 
開發者ID:pudae,項目名稱:kaggle-hpa,代碼行數:15,代碼來源:augmentation_search.py


注:本文中的optimizers.get_optimizer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。