예제 #1
0
 def create_and_check_for_image_classification(self, config, pixel_values, labels):
     config.num_labels = self.type_sequence_label_size
     model = BeitForImageClassification(config)
     model.to(torch_device)
     model.eval()
     result = model(pixel_values, labels=labels)
     self.parent.assertEqual(result.logits.shape, (self.batch_size, self.type_sequence_label_size))
    def create_and_check_for_image_classification(self, config, pixel_values,
                                                  labels, pixel_labels):
        config.num_labels = self.type_sequence_label_size
        model = BeitForImageClassification(config)
        model.to(torch_device)
        model.eval()
        result = model(pixel_values, labels=labels)
        self.parent.assertEqual(
            result.logits.shape,
            (self.batch_size, self.type_sequence_label_size))

        # test greyscale images
        config.num_channels = 1
        model = BeitForImageClassification(config)
        model.to(torch_device)
        model.eval()

        pixel_values = floats_tensor(
            [self.batch_size, 1, self.image_size, self.image_size])
        result = model(pixel_values, labels=labels)
        self.parent.assertEqual(
            result.logits.shape,
            (self.batch_size, self.type_sequence_label_size))