Clarification for the Mask RCNN tutorial

Hi,
In this tutorial: https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html

There is a code line that has an error:

        if self.transforms is not None:
            img, target = self.transforms(img, target)

According to the definition in the previous code section, self.transforms is a Compose object, so it accepts only one argument:

def get_transform(train):
    transforms = []
    transforms.append(T.ToTensor())
    if train:
        transforms.append(T.RandomHorizontalFlip(0.5))
    return T.Compose(transforms)

Can you please clarify what’s the correct syntax that one should use?

Also, I think the ToTensor should come after RandomHorizontalFlip, because RandomHorizontalFlip accepts PIL images.

You had me looking there, too! :slight_smile:

What happens is that the tutorial ships with its own little transforms module to bridge that gap.

Best regards

Thomas

Yep,thanks.I already requested to delete this thread. Will read more carefully next time

Oh, the next person with the question might find it useful. :slight_smile:

1 Like

Thanks @tom
Do you know how to save the model after training? It’s a JIT ScriptModule, and it doesn’t support pickle.dump or torch.save . There are open GitHub issues on it. I wonder if you know of a workaround.

It is considered best practice to save the state_dict, i.e. the parameters, rather than the full model. (You need the source anyway to re-instantiate the model.) This is what all pre-trained torchvision models do, too.
The obvious alternative is to trace the model to get a JIT model and save that.

Best regards

Thomas