pytorch maskrcnn reported an error.

Today, it can be run with the maskrcnn version officially provided by torchvision. It
can be run alone, but it will not run after being merged into my system. The following error is reported. It took more than 2 hours.

class Compose(object):
    def __init__(self, transforms):
        self.transforms = transforms

    def __call__(self, image, target):
        for t in self.transforms: 
            image, target = t(image, target) # 在这里报错
        return image, target


The error content is as follows
call takes 2 positional arguments but 3 were given

Later, after continuous tracking and investigation, it turned out to be. The
Compose class was defined again in the transforms.py file.
I thought this class is the same as the Compose defined in torchvision.transforms.
So in my code,
Just changed the reference of transforms to torchvision.transforms and the result was an error
. The Compose class in the two files is different.
Torchvision. The Compose class call method in transforms has 2 parameters, and the Compose in the example is rewritten. The parameter of the call method is 1. So the above error is prompted... The
elimination method is also very simple, just change
import torchvision.transforms
to
import maskrcnn.transforms
.
Maskrcnn is the folder name and module name on my side.

Guess you like

Origin blog.csdn.net/phker/article/details/109597776