-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MetaTensor: re-enable full tests #4462
Comments
(update: this is addressed by #4506)
import shutil
import os
from glob import glob
import time
import nibabel as nib
import tempfile
import unittest
import numpy as np
import torch
import monai
from monai.data import CacheDataset, ThreadDataLoader, create_test_image_3d
from monai.networks.nets import UNet
from monai.transforms import (
Compose,
EnsureChannelFirstd,
LoadImaged,
ToDeviced,
)
from monai.utils import set_determinism
from tests.utils import skip_if_no_cuda
@skip_if_no_cuda
class IntegrationFastTrain(unittest.TestCase):
def setUp(self):
set_determinism(seed=0)
monai.config.print_config()
self.data_dir = tempfile.mkdtemp()
for i in range(10):
im, seg = create_test_image_3d(64, 64, 64, num_seg_classes=1, channel_dim=-1)
n = nib.Nifti1Image(im, np.eye(4))
nib.save(n, os.path.join(self.data_dir, f"img{i:d}.nii.gz"))
n = nib.Nifti1Image(seg, np.eye(4))
nib.save(n, os.path.join(self.data_dir, f"seg{i:d}.nii.gz"))
def tearDown(self):
set_determinism(seed=None)
shutil.rmtree(self.data_dir)
def test_train_timing(self, use_metatensor=False):
images = sorted(glob(os.path.join(self.data_dir, "img*.nii.gz")))
segs = sorted(glob(os.path.join(self.data_dir, "seg*.nii.gz")))
train_files = [{"image": img, "label": seg} for img, seg in zip(images, segs)]
device = torch.device("cuda:0")
train_transforms = Compose(
[
LoadImaged(keys=["image", "label"]),
EnsureChannelFirstd(keys=["image", "label"]),
ToDeviced(keys=["image", "label"], device=device),
]
)
train_ds = CacheDataset(data=train_files, transform=train_transforms, cache_rate=1.0, num_workers=0)
train_loader = ThreadDataLoader(train_ds, num_workers=0, batch_size=10, shuffle=True)
model = UNet(
spatial_dims=3,
in_channels=1,
out_channels=2,
channels=(16, 32, 64, 128, 256),
strides=(2, 2, 2, 2),
).to(device)
for _ in range(5):
for batch_data in train_loader:
image = batch_data['image']
if not use_metatensor:
image = image.as_tensor()
step_start = time.time()
outputs = model(image)
xx = time.time()
print(outputs.shape, 'iter forward', xx - step_start)
if __name__ == "__main__":
unittest.main() log with
log with
|
the inverse operation of "crop samples" transforms are currently dropped and need some discussions (#4548 (comment)) |
idea from discussions introduce "strict" and "dev" modes to control manual modifications of the metadata |
Is your feature request related to a problem? Please describe.
Follow-up of prototype #4371
This ticket is to track the necessary breaking changes on branch feature/MetaTensor when rolling out the MetaTensor support for all the
monai.transforms.croppad
.These tests/checks are temporarily muted and should be re-enabled before merging the new features to the
dev
branch:ZoomBoxd
get_mask_edges
Zoom
Zoomd
test_slice_calculation
)cc @rijobro
(latest successful build is at 60a22ff)
The text was updated successfully, but these errors were encountered: