INNER CODE UNIT · Python

get_scores_targets

aangelopoulos/conformal-prediction · generation-scripts/generate-coco.py:20

def get_scores_targets(model, loader):
    scores = torch.zeros((len(loader.dataset), 80))
    labels = torch.zeros((len(loader.dataset), 80))
    paths = []
    i = 0
    print(f'Computing sigmoid scores for model (only happens once).')
    with torch.no_grad():
        for x, batch_labels, path in tqdm(loader):
            paths += list(path)

            batch_scores = torch.sigmoid(model(x.cuda())).detach().cpu()
            scores[i:(i+x.shape[0]), :] = batch_scores

            labels[i:(i+x.shape[0]),:] = batch_labels 
            i = i + x.shape[0]

    keep = labels.sum(dim=1) > 0
    scores = scores[keep].numpy()

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…