def __init__(self, model, dataset, device, gpus, objective, multiprocess=False, epochs=600, batch_size=96, optimizer_type='SGD', optimizer_kwargs=None, learning_rate=0.025, momentum=0.9, warmup_epochs=0, optimizer_scheduler={'type': 'CosineAnnealingLR', 'T_max': 600, 'eta_min': 0.001}, weight_decay=0.0003, no_bias_decay=False, grad_clip=5.0, auxiliary_head=False, auxiliary_weight=0.4, add_regularization=False, save_as_state_dict=False, workers_per_queue=2, eval_no_grad=True, eval_every=1, eval_batch_size=1, calib_bn_setup=False, seed=None, schedule_cfg=None):
    super(CNNFinalTrainer, self).__init__(schedule_cfg)
    self.model = model
    self.parallel_model = None
    self.dataset = dataset
    self.device = device
    self.gpus = gpus
    self.multiprocess = multiprocess
    self.objective = objective
    self._perf_func = self.objective.get_perfs
    self._perf_names = self.objective.perf_names()
    self._obj_loss = self.objective.get_loss
    self.epochs = epochs
    self.warmup_epochs = warmup_epochs
    self.optimizer_type = optimizer_type
    self.optimizer_kwargs = optimizer_kwargs
    self.learning_rate = learning_rate
    self.grad_clip = grad_clip
    self.auxiliary_head = auxiliary_head
    self.auxiliary_weight = auxiliary_weight
    self.add_regularization = add_regularization
    self.save_as_state_dict = save_as_state_dict
    self.eval_no_grad = eval_no_grad
    self.eval_every = eval_every
    self.calib_bn_setup = calib_bn_setup
    self.weight_decay = weight_decay
    self.no_bias_decay = no_bias_decay
    self.learning_rate = learning_rate
    self.momentum = momentum
    self.optimizer_scheduler_cfg = optimizer_scheduler
    self._criterion = nn.CrossEntropyLoss().to(self.device)
    _splits = self.dataset.splits()
    train_kwargs = getattr(_splits['train'], 'kwargs', {})
    test_kwargs = getattr(_splits['test'], 'kwargs', train_kwargs)
    '\n        GroupSampler is needed when `keep_ratio` in dataset is set True.\n        It makes two group of images: aspect ratio > 1 , and aspect ratio < 1.\n\n        `shuffle` is invalid when using GroupSampler because it cannot\n        guarantee the original order of images.\n        '
    group = train_kwargs.pop('group_sample', False)
    test_kwargs['shuffle'] = False
    if self.multiprocess:
        sampler = (DistributedGroupSampler(_splits['train'], None, batch_size) if group else DistributedSampler(_splits['train'], shuffle=True))
        test_kwargs['sampler'] = DistributedSampler(_splits['test'], shuffle=False)
    else:
        sampler = (GroupSampler(_splits['train'], None, batch_size) if group else None)
    if (sampler is None):
        train_kwargs['shuffle'] = True
    else:
        train_kwargs.pop('shuffle', None)
        train_kwargs['sampler'] = sampler
    (rank, world_size) = get_dist_info()
    init_fn = (functools.partial(worker_init_fn, num_workers=workers_per_queue, rank=rank, seed=seed) if (seed is not None) else None)
    self.train_queue = torch.utils.data.DataLoader(_splits['train'], batch_size=batch_size, pin_memory=False, num_workers=workers_per_queue, worker_init_fn=init_fn, **train_kwargs)
    self.valid_queue = torch.utils.data.DataLoader(_splits['test'], batch_size=eval_batch_size, pin_memory=False, num_workers=workers_per_queue, **test_kwargs)
    if self.calib_bn_setup:
        self.model = calib_bn(self.model, self.train_queue)
    self.optimizer = None
    self.scheduler = None
    self.last_epoch = 0
    self.epoch = 0
    self.save_every = None
    self.report_every = None
    self.train_dir = None
    self._is_setup = False
def __init__(self, model, dataset, device, gpus, objective, multiprocess=False, epochs=600, batch_size=96, optimizer_type='SGD', optimizer_kwargs=None, learning_rate=0.025, momentum=0.9, warmup_epochs=0, optimizer_scheduler={'type': 'CosineAnnealingLR', 'T_max': 600, 'eta_min': 0.001}, weight_decay=0.0003, no_bias_decay=False, grad_clip=5.0, auxiliary_head=False, auxiliary_weight=0.4, add_regularization=False, save_as_state_dict=False, workers_per_queue=2, eval_no_grad=True, eval_every=1, eval_batch_size=1, calib_bn_setup=False, seed=None, schedule_cfg=None):
    super(CNNFinalTrainer, self).__init__(schedule_cfg)
    self.model = model
    self.parallel_model = None
    self.dataset = dataset
    self.device = device
    self.gpus = gpus
    self.multiprocess = multiprocess
    self.objective = objective
    self._perf_func = self.objective.get_perfs
    self._perf_names = self.objective.perf_names()
    self._obj_loss = self.objective.get_loss
    self.epochs = epochs
    self.warmup_epochs = warmup_epochs
    self.optimizer_type = optimizer_type
    self.optimizer_kwargs = optimizer_kwargs
    self.learning_rate = learning_rate
    self.grad_clip = grad_clip
    self.auxiliary_head = auxiliary_head
    self.auxiliary_weight = auxiliary_weight
    self.add_regularization = add_regularization
    self.save_as_state_dict = save_as_state_dict
    self.eval_no_grad = eval_no_grad
    self.eval_every = eval_every
    self.calib_bn_setup = calib_bn_setup
    self.weight_decay = weight_decay
    self.no_bias_decay = no_bias_decay
    self.learning_rate = learning_rate
    self.momentum = momentum
    self.optimizer_scheduler_cfg = optimizer_scheduler
    self._criterion = nn.CrossEntropyLoss().to(self.device)
    _splits = self.dataset.splits()
    train_kwargs = getattr(_splits['train'], 'kwargs', {})
    test_kwargs = getattr(_splits['test'], 'kwargs', train_kwargs)
    '\n        GroupSampler is needed when `keep_ratio` in dataset is set True.\n        It makes two group of images: aspect ratio > 1 , and aspect ratio < 1.\n\n        `shuffle` is invalid when using GroupSampler because it cannot\n        guarantee the original order of images.\n        '
    group = train_kwargs.pop('group_sample', False)
    test_kwargs['shuffle'] = False
    if self.multiprocess:
        sampler = (DistributedGroupSampler(_splits['train'], None, batch_size) if group else DistributedSampler(_splits['train'], shuffle=True))
        test_kwargs['sampler'] = DistributedSampler(_splits['test'], shuffle=False)
    else:
        sampler = (GroupSampler(_splits['train'], None, batch_size) if group else None)
    if (sampler is None):
        train_kwargs['shuffle'] = True
    else:
        train_kwargs.pop('shuffle', None)
        train_kwargs['sampler'] = sampler
    (rank, world_size) = get_dist_info()
    init_fn = (functools.partial(worker_init_fn, num_workers=workers_per_queue, rank=rank, seed=seed) if (seed is not None) else None)
    self.train_queue = torch.utils.data.DataLoader(_splits['train'], batch_size=batch_size, pin_memory=False, num_workers=workers_per_queue, worker_init_fn=init_fn, **train_kwargs)
    self.valid_queue = torch.utils.data.DataLoader(_splits['test'], batch_size=eval_batch_size, pin_memory=False, num_workers=workers_per_queue, **test_kwargs)
    if self.calib_bn_setup:
        self.model = calib_bn(self.model, self.train_queue)
    self.optimizer = None
    self.scheduler = None
    self.last_epoch = 0
    self.epoch = 0
    self.save_every = None
    self.report_every = None
    self.train_dir = None
    self._is_setup = False