Skip to content

Commit

Permalink
Merge 295ca08 into e101ebe
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuacwnewton committed Dec 1, 2023
2 parents e101ebe + 295ca08 commit 96ba20c
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ jobs:
fail-fast: false

matrix:
os: [ "macos-latest", "windows-latest", "ubuntu-20.04", "ubuntu-18.04" ]
python-version: [ '3.7', '3.8', '3.9', '3.10' ]
os: [ "macos-latest", "windows-latest", "ubuntu-20.04" ]
python-version: [ '3.8', '3.9', '3.10' ]
test-name:
- integration-test

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_tests_dummy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
matrix:
# This list must be kept **in sync** with the Required Statuses in https://github.com/ivadomed/ivadomed/settings/branch_protection_rules/5051948
os: [ "macos-latest", "windows-latest", "ubuntu-20.04", "ubuntu-18.04" ]
os: [ "macos-latest", "ubuntu-20.04" ]
python-version: [ 3.8 ]
test-name:
- integration-test
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sphinx:
configuration: docs/source/conf.py

python:
version: 3.7
version: 3.10
install:
# Install IvadoMed package via setup.py content
- method: pip
Expand Down
3 changes: 2 additions & 1 deletion ivadomed/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ def pred_to_png(pred_list: list, target_list: list, subj_path: str, suffix: str
for pred, target in zip(pred_list, target_list):
filename = subj_path + target + suffix
data = pred.get_fdata()
imageio.imwrite(filename, (data*255/max_value).astype(np.uint8), format='png')
_img = (data*255/max_value).astype(np.uint8).squeeze()
imageio.v3.imwrite(filename, _img, extension='.png')


def process_transformations(context: dict, fname_roi: str, fname_prior: str, metadata: dict, slice_axis: int,
Expand Down
28 changes: 22 additions & 6 deletions ivadomed/loader/segmentation_pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,28 @@ def convert_file_to_nifti(self, filename: str, extension: str, is_gt: bool = Fal
"""
# For '.png', '.tif', '.tiff', '.jpg' and 'jpeg' extentions
# Read image as 8 bit grayscale in numpy array (behavior TBD in ivadomed for RGB, RBGA or higher bit depth)
if "tif" in extension:
img = np.expand_dims(imageio.v2.imread(filename, format='tiff-pil'), axis=-1).astype(np.uint8)
if len(img.shape) > 3:
img = np.expand_dims(imageio.v2.imread(filename, format='tiff-pil', as_gray=True), axis=-1).astype(np.uint8)
else:
img = np.expand_dims(imageio.v2.imread(filename, as_gray=True), axis=-1).astype(np.uint8)
props = imageio.v3.improps(filename) # new in v3 - standardized metadata
_img = imageio.v3.imread(filename)

# TIFF is a "wild" format. A few assumptions greatly simplify the code below:
# 1. the image is interleaved/channel-last (not planar)
# 2. the colorspace is one of: binary, gray, RGB, RGBA (not aliasing ones like YUV or CMYK)
# 3. the image is flat (not a volume or time-series)
# Note: All of these are trivially true for JPEG and PNG due to limitations of these formats.

# make grayscale (treats binary as 1-bit grayscale)
colorspace_idx = 2 + int(props.is_batch)
if _img.ndim <= colorspace_idx: # binary or gray
pass # nothing to do
elif _img.shape[colorspace_idx] == 3: # RGB
_img = np.sum(_img * (.299, .587, .114), axis=-1)
else: # RGBA
# discards alpha
_img = np.sum(_img * (.299, .587, .114, 0), axis=-1)
if len(_img.shape) < 3:
_img = np.expand_dims(_img, axis=-1)

img = imageio.core.image_as_uint(_img, bitdepth=8)

# Binarize ground-truth values (0-255) to 0 and 1 in uint8 with threshold 0.5
if is_gt:
Expand Down
3 changes: 1 addition & 2 deletions ivadomed/loader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import torch
from loguru import logger
from sklearn.model_selection import train_test_split
from torch._six import string_classes
from ivadomed import utils as imed_utils
from ivadomed.keywords import SplitDatasetKW, LoaderParamsKW, ROIParamsKW, ContrastParamsKW
import nibabel as nib
Expand Down Expand Up @@ -270,7 +269,7 @@ def imed_collate(batch: dict) -> dict | list | str | torch.Tensor:
return torch.LongTensor(batch)
elif isinstance(batch[0], float):
return torch.DoubleTensor(batch)
elif isinstance(batch[0], string_classes):
elif isinstance(batch[0], str):
return batch
elif isinstance(batch[0], collections.abc.Mapping):
return {key: imed_collate([d[key] for d in batch]) for key in batch[0]}
Expand Down
10 changes: 6 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ imageio~=2.19
joblib~=1.0
matplotlib>=3.3.0
nibabel~=3.2
onnxruntime~=1.7
onnx
onnxruntime>=1.7.0,<1.16.0
pandas>=1.1,<1.5.0
pybids>=0.14.0
Pillow<10.0.0
pybids>=0.14.0,<0.15.6
scikit-learn>=0.20.3
scikit-image~=0.17
seaborn~=0.11
tensorboard>=1.15.0
tqdm>=4.30
scipy
torchio>=0.18.68
torch>=1.8.1,<=1.11.0
torchvision>=0.9.1,<=0.12.0
torch==2.0.0
torchvision>=0.9.1
wandb>=0.12.11
9 changes: 6 additions & 3 deletions testing/unit_tests/test_tensorboard_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ def test_tensorboard_save():
summary_iterators = [EventAccumulator(str(dname)).Reload() for dname in dpath.iterdir()]
for i in range(len(summary_iterators)):
if summary_iterators[i].Tags()['images'] == ['Training/Input', 'Training/Predictions', 'Training/Ground Truth']:
input_retrieve = np.array(Image.open(io.BytesIO(summary_iterators[i].Images('Training/Input')[0][2])))
pred_retrieve = np.array(Image.open(io.BytesIO(summary_iterators[i].Images('Training/Predictions')[0][2])))
gt_retrieve = np.array(Image.open(io.BytesIO(summary_iterators[i].Images('Training/Ground Truth')[0][2])))
input_retrieve = np.array(Image.open(io.BytesIO(
summary_iterators[i].Images('Training/Input')[0].encoded_image_string)))
pred_retrieve = np.array(Image.open(io.BytesIO(
summary_iterators[i].Images('Training/Predictions')[0].encoded_image_string)))
gt_retrieve = np.array(Image.open(io.BytesIO(
summary_iterators[i].Images('Training/Ground Truth')[0].encoded_image_string)))

assert np.allclose(imed_math.rescale_values_array(input_retrieve[:, :, 0], 0, 1), inp[0, 0, :, :])
assert np.allclose(imed_math.rescale_values_array(pred_retrieve[:, :, 0], 0, 1), pred[0, 0, :, :])
Expand Down

0 comments on commit 96ba20c

Please sign in to comment.