def distill_model(distillation_box, data_loader, optimizer, log_freq, device, epoch):
    metric_logger = misc_util.MetricLogger(delimiter='  ')
    metric_logger.add_meter('lr', misc_util.SmoothedValue(window_size=1, fmt='{value:.6f}'))
    header = 'Epoch: [{}]'.format(epoch)
    lr_scheduler = None
    if (epoch == 0):
        warmup_factor = (1.0 / 1000.0)
        warmup_iters = min(1000, (len(data_loader) - 1))
        lr_scheduler = main_util.warmup_lr_scheduler(optimizer, warmup_iters, warmup_factor)
    for (images, targets) in metric_logger.log_every(data_loader, log_freq, header):
        images = list((image.to(device) for image in images))
        targets = [{k: v.to(device) for (k, v) in t.items()} for t in targets]
        optimizer.zero_grad()
        loss = distillation_box(images, targets)
        loss.backward()
        optimizer.step()
        if (lr_scheduler is not None):
            lr_scheduler.step()
        metric_logger.update(loss=loss)
        metric_logger.update(lr=optimizer.param_groups[0]['lr'])
def distill_model(distillation_box, data_loader, optimizer, log_freq, device, epoch):
    metric_logger = misc_util.MetricLogger(delimiter='  ')
    metric_logger.add_meter('lr', misc_util.SmoothedValue(window_size=1, fmt='{value:.6f}'))
    header = 'Epoch: [{}]'.format(epoch)
    lr_scheduler = None
    if (epoch == 0):
        warmup_factor = (1.0 / 1000.0)
        warmup_iters = min(1000, (len(data_loader) - 1))
        lr_scheduler = main_util.warmup_lr_scheduler(optimizer, warmup_iters, warmup_factor)
    for (images, targets) in metric_logger.log_every(data_loader, log_freq, header):
        images = list((image.to(device) for image in images))
        targets = [{k: v.to(device) for (k, v) in t.items()} for t in targets]
        optimizer.zero_grad()
        loss = distillation_box(images, targets)
        loss.backward()
        optimizer.step()
        if (lr_scheduler is not None):
            lr_scheduler.step()
        metric_logger.update(loss=loss)
        metric_logger.update(lr=optimizer.param_groups[0]['lr'])