Skip to content
Snippets Groups Projects

Fix Issues when running tests on the CI

Merged Daniel CARRON requested to merge ci-db-paths into update-tests
2 files
+ 19
17
Compare changes
  • Side-by-side
  • Inline
Files
2
  • ab524a4e
    Histograms comme be compared directly due to differences in how the
    torch.resize transform is applied depending on the environment.
    A statistical approach using pearson coefficients is used instead.
    Testing of alexnet and densenet transforms have been temporarily
    disabled as histograms or RGB images need to be handled differently.
+ 17
15
@@ -5,11 +5,10 @@
import pathlib
import typing
import numpy
import pytest
import torch
from torchvision.transforms.functional import to_pil_image
from mednet.data.split import JSONDatabaseSplit
from mednet.data.typing import DatabaseSplit
@@ -204,7 +203,7 @@ class DatabaseCheckers:
@staticmethod
def check_image_quality(
datamodule, reference_histogram_file, histogram_edges_threshold=2
datamodule, reference_histogram_file, pearson_coeff_threshold=0.005
):
ref_histogram_splits = JSONDatabaseSplit(reference_histogram_file)
@@ -226,19 +225,22 @@ class DatabaseCheckers:
image_tensor = datamodule._datasets[split_name][
dataset_sample_index
][0]
img = to_pil_image(image_tensor)
histogram = img.histogram()
# The histograms do not exacly match due to the torch resize transform
# acting differently depending on the environment.
assert (
histogram[
histogram_edges_threshold:-histogram_edges_threshold
]
== ref_hist_data[
histogram_edges_threshold:-histogram_edges_threshold
]
image_tensor = numpy.multiply(image_tensor.numpy(), 255).astype(
int
)
histogram = numpy.histogram(
image_tensor, bins=256, range=(0, 256)
)[0].tolist()
# We cannot test if histograms are exactly equal because
# the torch.resize transform is inconsistent depending on the environment.
# assert histogram == ref_hist_data
# Compute pearson coefficients between histogram and reference
# and check the similarity within a certain threshold
pearson_coeffs = numpy.corrcoef(histogram, ref_hist_data)
assert 1 - pearson_coeff_threshold <= pearson_coeffs[0][1] <= 1
@pytest.fixture
Loading