Giter VIP home page Giter VIP logo

Comments (1)

hellbell avatar hellbell commented on July 26, 2024

@rtaori
Unfortunately, we don't have a plan to update our codebase now.
I can share the label map extraction code snippet, but I'm not sure whether this is the right and valid code.
I hope you can understand how the label maps were extracted through this code, but if you want fully-working codes, please wait for our next codebase update.

normalize = torchvision.transforms.Normalize(
    mean=[0.485, 0.456, 0.406],
    std=[0.229, 0.224, 0.225]
)
train_root = os.path.join(data_path, 'train')
train_dataset = ImageFolderWithPath(
    root=train_root,
    transform=torchvision.transforms.Compose([
        torchvision.transforms.Resize((machine_annotator_image_size,
                                       machine_annotator_image_size)),
        torchvision.transforms.ToTensor(),
        normalize,
    ]))

train_sampler = torch.utils.data.distributed.DistributedSampler(
    train_dataset)

train_loader = torch.utils.data.DataLoader(
    train_dataset,
    batch_sizebatch_size,
    shuffle=False,
    num_workers=machine_annotator_num_workers,
    pin_memory=True,
    sampler=train_sampler
)

score_maps = {}

print('Train loader size: {}'.format(len(train_loader)))
for iteration, batch in enumerate(train_loader):
    start_time = time.time()

    input, target, img_names = batch
    target = target.cuda()

    with torch.no_grad():
        # get score_map by removing GlobalAvergaPool. (See Appendix)
        output_map = machine_annotator_model(input, score_map=True) 

    output_topk = output_map.topk(k=machine_annotator_topk, dim=1)

    for idx, (t0, t1) in enumerate(zip(output_topk[0], output_topk[1])):
        img_name = img_names[idx].split('/')[-1].split('.')[0]
        t = torch.cat([t0.unsqueeze(0), t1.unsqueeze(0).float()],
                      dim=0)

        score_maps[img_name] = t.cpu()

score_map_path = '{}_{}_sz{}_top{}_score_maps.pt'.format(
    data.dataset,
    machine_annotator_arch,
    machine_annotator_image_size,
    machine_annotator_topk)

from relabel_imagenet.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.