def test_compute_feats_cuda() -> None: try: dataset = TestDataset() loader = torch.utils.data.DataLoader( dataset, batch_size=3, num_workers=2, ) metric = MSID() model = InceptionV3() metric.compute_feats(loader, model, device='cuda') except Exception as e: pytest.fail(f"Unexpected error occurred: {e}")
def test_compute_msid_works_for_different_number_of_images_in_stack( features_target_normal: torch.Tensor) -> None: features_prediction_normal = torch.rand(1001, 20) metric = MSID() try: metric(features_target_normal, features_prediction_normal) except Exception as e: pytest.fail(f"Unexpected error occurred: {e}")
def test_msid_is_smaller_for_equal_tensors(features_y_normal, features_x_normal, features_x_constant) -> None: metric = MSID() measure = metric(features_y_normal, features_x_normal) measure_constant = metric(features_y_normal, features_x_normal) assert measure <= measure_constant, \ f'MSID should be smaller for samples from the same distribution, got {measure} and {measure_constant}'
def test_forward( features_target_normal: torch.Tensor, features_prediction_normal: torch.Tensor, ) -> None: try: metric = MSID() metric(features_target_normal, features_prediction_normal) except Exception as e: pytest.fail(f"Unexpected error occurred: {e}")
def test_forward( features_y_normal, features_x_normal, ) -> None: try: metric = MSID() metric(features_y_normal, features_x_normal) except Exception as e: pytest.fail(f"Unexpected error occurred: {e}")
def test_msid_is_smaller_for_equal_tensors( features_target_normal: torch.Tensor, features_prediction_normal: torch.Tensor, features_prediction_constant: torch.Tensor) -> None: metric = MSID() measure = metric(features_target_normal, features_prediction_normal) measure_constant = metric(features_target_normal, features_prediction_normal) assert measure <= measure_constant, \ f'MSID should be smaller for samples from the same distribution, got {measure} and {measure_constant}'
def test_initialization() -> None: try: MSID() except Exception as e: pytest.fail(f"Unexpected error occurred: {e}")
def test_fails_for_different_dimensions( features_target_normal: torch.Tensor) -> None: features_prediction_normal = torch.rand(1000, 21) metric = MSID() with pytest.raises(AssertionError): metric(features_target_normal, features_prediction_normal)
def test_fails_for_different_dimensions(features_y_normal) -> None: features_x_normal = torch.rand(1000, 21) metric = MSID() with pytest.raises(AssertionError): metric(features_y_normal, features_x_normal)