examples/train_tnbc.py
def run(model_dict, dataloader, device, mode):
    """Runs one epoch of training/evaluation through the dataloader"""
    dice = []
    losses = []
    for _, batch in enumerate(dataloader):
        imgs = batch["img"].to(device)
        targets = batch["mask"].to(device)
        if mode == "train":
            model_dict["opt"].zero_grad()
        preds = model_dict["model"](imgs)

        loss = get_loss(preds, targets, model_dict)
        if mode == "train":
            propagate_loss(loss, model_dict)

        losses.append(loss.detach().cpu().numpy())
        dice.append(get_segmentation_dice(preds.detach(), targets.detach()))
    return np.mean(dice), np.mean(losses)
Runs one epoch of training/evaluation through the dataloader
Runs one epoch of training/evaluation through the dataloader
Runs one epoch of training / evaluation through the dataloader
def run(model_dict, dataloader, device, mode):
    dice = []
    losses = []
    for _, batch in enumerate(dataloader):
        imgs = batch["img"].to(device)
        targets = batch["mask"].to(device)
        if mode == "train":
            model_dict["opt"].zero_grad()
        preds = model_dict["model"](imgs)
        loss = get_loss(preds, targets, model_dict)
        if mode == "train":
            propagate_loss(loss, model_dict)
        losses.append(loss.detach().cpu().numpy())
        dice.append(get_segmentation_dice(preds.detach(), targets.detach()))
    return np.mean(dice), np.mean(losses)
def run ( model_dict , dataloader , device , mode ) : dice = [ ] losses = [ ] for _ , batch in enumerate ( dataloader ) : imgs = batch [ "img" ] . to ( device ) targets = batch [ "mask" ] . to ( device ) if mode == "train" : model_dict [ "opt" ] . zero_grad ( ) preds = model_dict [ "model" ] ( imgs ) loss = get_loss ( preds , targets , model_dict ) if mode == "train" : propagate_loss ( loss , model_dict ) losses . append ( loss . detach ( ) . cpu ( ) . numpy ( ) ) dice . append ( get_segmentation_dice ( preds . detach ( ) , targets . detach ( ) ) ) return np . mean ( dice ) , np . mean ( losses )
Runs one epoch of training/evaluation through the dataloader
Runs one epoch of training / evaluation through the dataloader
"""Runs one epoch of training/evaluation through the dataloader"""
model_dict
dataloader
device
mode