question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Mapper tutorial does not work

See original GitHub issue

📚 Documentation Issue or not clear

Hello, I am following this in order to replycate how to use a custom mapper.

So if I just copy the example in the documentation

def custom_mapper(dataset_dict):
    dataset_dict = copy.deepcopy(dataset_dict)  # it will be modified by code below
    # can use other ways to read image
    image = utils.read_image(dataset_dict["file_name"], format="BGR")
    # See "Data Augmentation" tutorial for details usage
    auginput = T.AugInput(image)
    transform = T.Resize((800, 800))(auginput)
    image = torch.from_numpy(auginput.image.transpose(2, 0, 1))
    annos = [
        utils.transform_instance_annotations(annotation, [transform], image.shape[1:])
        for annotation in dataset_dict.pop("annotations")
    ]
    return {
        # create the format that the model expects
        "image": image,
        "instances": utils.annotations_to_instances(annos, image.shape[1:])
    }

And then, follwing this i overwrited the build_{train,test}_loader method

class MyTrainer(DefaultTrainer):
    @classmethod
    def build_train_loader(cls, cfg):
        train_dataloader =  build_detection_train_loader(cfg, mapper=custom_mapper)
        return train_dataloader

    @classmethod
    def build_test_loader(cls, cfg):
        test_dataloader = build_detection_train_loader(cfg, mapper=custom_mapper)
        return test_dataloader

I get this error when start to train

w, h = d["width"], d["height"]
KeyError: 'width'

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
mjack3commented, Sep 14, 2021

@narenakash

Yes, if you check the documentation, it says

# create the format that the model expects In my case, it is faster 50, so the input model format acording to the documentation also needs:

“height”, “width”:

1reaction
narenakashcommented, Sep 11, 2021

@mjack3 I’m also facing the same issue. Could you share how you solved it?

Thanks in advance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Mapper with MapStruct
In this article, we'll learn how to use custom mapper with the MapStruct library. The MapStruct library is used for mapping between Java...
Read more >
MapStruct - Custom Mapping
MapStruct - Custom Mapping, We can add custom methods as well to the Mapper created ... Open project mapping as updated in Basic...
Read more >
One-Stop Guide to Mapping with MapStruct
Sometimes we would like to implement a specific mapping manually by defining our logic while transforming from one object to another. For that, ......
Read more >
Guide to MapStruct in Java - Advanced Mapping Library
In this article, we'll go through many examples of using MapStruct for Advanced Java Mapping, exception handling and MapStruct annotations.
Read more >
Custom Mappers - Legion Programming System
A common problem encountered when writing code for large distributed and ... Custom mappers can either extend the DefaultMapper class or implement the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found