예제 #1
0
if cfg.loss == "ce":
    criterion = nn.CrossEntropyLoss(reduction='mean')
elif cfg.loss == "sce":
    criterion = SymmetricCrossEntropyLoss(alpha=cfg.loss_cfg['sce']['alpha'],
                                          beta=cfg.loss_cfg['sce']['beta'],
                                          num_classes=cfg.n_class)
    # criterion4 = NormalizedSymmetricCrossEntropyLoss(alpha=cfg.alpha, beta=cfg.beta, num_classes=cfg.n_class)
elif cfg.loss == "focal":
    criterion = FocalLoss(gamma=cfg.loss_cfg['focal']['gamma'])
elif cfg.loss == "ce-dice":
    criterion = nn.CrossEntropyLoss(reduction='mean')
elif cfg.loss == 'decouple-v1':
    criterion = DecoupledSegLoss_v1(alpha=cfg.loss_cfg['sce']['alpha'],
                                    beta=cfg.loss_cfg['sce']['beta'],
                                    num_classes=cfg.n_class)
elif cfg.loss == 'decouple-v2':
    criterion = DecoupledSegLoss_v2(alpha=cfg.loss_cfg['sce']['alpha'],
                                    beta=cfg.loss_cfg['sce']['beta'],
                                    gamma=cfg.loss_cfg['focal']['gamma'],
                                    num_classes=cfg.n_class)

runner.train(dataset_train,
             dataset_val,
             criterion,
             get_optimizer,
             Trainer,
             Evaluator,
             collate,
             dataset_test=dataset_test,
             tester_func=SlideInference)
예제 #2
0
transformer_val = TransformerVal()
dataset_val = OralDataset(valset_cfg["img_dir"],
                          valset_cfg["mask_dir"],
                          valset_cfg["meta_file"],
                          label=valset_cfg["label"],
                          transform=transformer_val)

if cfg.loss == "ce":
    criterion = nn.CrossEntropyLoss(reduction='mean')
elif cfg.loss == "sce":
    criterion = SymmetricCrossEntropyLoss(alpha=cfg.loss_cfg['sce']['alpha'],
                                          beta=cfg.loss_cfg['sce']['beta'],
                                          num_classes=cfg.n_class)
    # criterion4 = NormalizedSymmetricCrossEntropyLoss(alpha=cfg.alpha, beta=cfg.beta, num_classes=cfg.n_class)
elif cfg.loss == "focal":
    criterion = FocalLoss(gamma=cfg.loss_cfg['focal']['gamma'])
elif cfg.loss == "ce-dice":
    criterion = nn.CrossEntropyLoss(reduction='mean')
elif cfg.loss == 'decouple-v1':
    criterion = DecoupledSegLoss_v1(alpha=cfg.loss_cfg['sce']['alpha'],
                                    beta=cfg.loss_cfg['sce']['beta'],
                                    num_classes=cfg.n_class)
elif cfg.loss == 'decouple-v2':
    criterion = DecoupledSegLoss_v2(alpha=cfg.loss_cfg['sce']['alpha'],
                                    beta=cfg.loss_cfg['sce']['beta'],
                                    gamma=cfg.loss_cfg['focal']['gamma'],
                                    num_classes=cfg.n_class)

runner.train(dataset_train, dataset_val, criterion, get_optimizer, Trainer,
             Evaluator, collate)