Esempio n. 1
0
def train_PEM(data_loader,model,optimizer,epoch,writer,opt):
    model.train()
    epoch_iou_loss = 0
    
    for n_iter,(input_data,label_iou,is_whole_lenght) in enumerate(data_loader):
        PEM_output = model(input_data)
        iou_loss = PEM_loss_function(PEM_output,[label_iou, is_whole_lenght],model,opt)
        optimizer.zero_grad()
        iou_loss.backward()
        optimizer.step()
        epoch_iou_loss += iou_loss.cpu().detach().numpy()

    writer.add_scalars('data/iou_loss', {'train': epoch_iou_loss/(n_iter+1)}, epoch)
    
    print "PEM training loss(epoch %d): iou - %.04f" %(epoch,epoch_iou_loss/(n_iter+1))
Esempio n. 2
0
def train_PEM(data_loader, model, optimizer, epoch, writer, opt):
    model.train()
    epoch_iou_loss = 0
    losses = AverageMeter()
    for n_iter, (input_data, label_iou) in enumerate(data_loader):
        PEM_output = model(input_data)
        iou_loss = PEM_loss_function(PEM_output, label_iou, model, opt)
        optimizer.zero_grad()
        iou_loss.backward()
        optimizer.step()
        epoch_iou_loss += iou_loss.cpu().detach().numpy()

        losses.update(iou_loss.item())
        if (n_iter + 1) % opt['print_freq'] == 0:
            print('[TRAIN] Epoch {}, iter {} / {}, loss: {}'.format(
                epoch, n_iter + 1, len(data_loader), losses.avg))

    writer.add_scalars('data/iou_loss',
                       {'train': epoch_iou_loss / (n_iter + 1)}, epoch)

    print("PEM training loss(epoch %d): iou - %.04f" % (epoch, epoch_iou_loss /
                                                        (n_iter + 1)))