For the model definition, I followed the function from the tutorial:
def get_model_instance_segmentation(num_classes):
    # load an instance segmentation model pre-trained pre-trained on COCO
    model = torchvision.models.detection.maskrcnn_resnet50_fpn(pretrained=True)

    # get number of input features for the classifier
    in_features = model.roi_heads.box_predictor.cls_score.in_features
    # replace the pre-trained head with a new one
    model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)

    # now get the number of input features for the mask classifier
    in_features_mask = model.roi_heads.mask_predictor.conv5_mask.in_channels
    hidden_layer = 256
    # and replace the mask predictor with a new one
    model.roi_heads.mask_predictor = MaskRCNNPredictor(in_features_mask,
                                                       hidden_layer,
                                                       num_classes)

    return model

after training the model I save it using :
torch.save(model, 'faster_rcnn_'+str(len(train_dataset))+'.pt')
I need to add another note now: after training the model with less data or less num. of epochs it might work - as I tried to save and use the model after each epoch - in the first epochs it works and outputs a prediction - it’s bad accuracy of course -  but after increasing number of epochs or num of dataset its rais the same error