Пример #1
0
    def process_support_set(
        self,
        support_images: torch.Tensor,
        support_labels: torch.Tensor,
    ):
        """
        Overrides process_support_set of AbstractMetaLearner.
        Extract feature vectors from the support set and store class prototypes.

        Args:
            support_images: images of the support set
            support_labels: labels of support set images
        """

        support_features = self.backbone.forward(support_images)
        self.prototypes = compute_prototypes(support_features, support_labels)
 def store_support_set_data(
     self,
     support_images: Tensor,
     support_labels: Tensor,
 ):
     """
     Extract support features, compute prototypes,
         and store support labels, features, and prototypes
     Args:
         support_images: images of the support set
         support_labels: labels of support set images
     """
     self.support_labels = support_labels
     self.support_features = self.backbone(support_images)
     self.prototypes = compute_prototypes(self.support_features,
                                          support_labels)
Пример #3
0
    def process_support_set(
        self,
        support_images: Tensor,
        support_labels: Tensor,
    ):
        """
        Overrides process_support_set of FewShotClassifier.
        Extract feature maps from the support set and store class prototypes.

        Args:
            support_images: images of the support set
            support_labels: labels of support set images
        """

        support_features = self.backbone(support_images)
        self.prototypes = compute_prototypes(support_features, support_labels)
Пример #4
0
 def test_compute_prototypes_returns_correct_prototypes(
         features, labels, expected_prototypes):
     assert torch.equal(compute_prototypes(features, labels),
                        expected_prototypes)