question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FileNotFoundError: File not found: "affine"

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Problem summary

Hi,

I am trying to apply the Torchio tutorial on a different dataset (Promise12 data set), first I converted the data into NiFti (.mhd)—>(.nii), then I followed the steps found on the google colab but after I applied the # Visualize axial slices of one batch step I got this error “FileNotFoundError: File not found: “affine””

Code for reproduction

images_dir = Path("TargetImage")
labels_dir = Path("Targetlabel")
image_paths = sorted(images_dir.glob('*.nii'))
label_paths = sorted(labels_dir.glob('*.nii'))
assert len(image_paths) == len(label_paths)

subjects = []
for (image_path, label_path) in zip(image_paths, label_paths):
    subject = tio.Subject(
        prostate=tio.ScalarImage(image_path),
        mask=tio.LabelMap(label_path),
    )
    subjects.append(subject)
dataset = tio.SubjectsDataset(subjects)
print('Dataset size:', len(dataset), 'subjects')

#Patch-based:
training_batch_size = 32
validation_batch_size = 2 * training_batch_size

patch_size = 24
samples_per_volume = 5
max_queue_length = 300
sampler = tio.data.UniformSampler(patch_size)

patches_training_set = tio.Queue(
    subjects_dataset=training_set,
    max_length=max_queue_length,
    samples_per_volume=samples_per_volume,
    sampler=sampler,
    num_workers=num_workers,
    shuffle_subjects=True,
    shuffle_patches=True,
)
print (patches_training_set)

patches_validation_set = tio.Queue(
    subjects_dataset=validation_set,
    max_length=max_queue_length,
    samples_per_volume=samples_per_volume,
    sampler=sampler,
    num_workers=num_workers,
    shuffle_subjects=False,
    shuffle_patches=False,
)
training_loader_patches = torch.utils.data.DataLoader(patches_training_set, batch_size=training_batch_size)

validation_loader_patches = torch.utils.data.DataLoader(patches_validation_set, batch_size=validation_batch_size)
# Visualize axial slices of one batch
one_batch = next(iter(training_loader_patches))
k = int(patch_size // 4)
batch_mri = one_batch['prostate'][tio.DATA][..., k]
batch_label = one_batch['mask'][tio.DATA][:, 1:, ..., k]
slices = torch.cat((batch_mri, batch_label))
image_path = 'batch_patches.png'
torchvision.utils.save_image(
    slices,
    image_path,
    nrow=training_batch_size,
    normalize=True,
    scale_each=True,
)
display.Image(image_path)

Actual outcome

It should appear the training result

Error messages

FileNotFoundError: File not found: "affine"

Expected outcome

It should appear the training result

System info

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
shathaa1983commented, Oct 9, 2022

Hi, Thank you, the code is working fine after I update the Torchio version.

0reactions
fepegarcommented, Oct 9, 2022

Also, can you please upgrade TorchIO and see if that solves your issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Source code for torchio.data.image
If the affine matrix is ``None``, an identity matrix will be used. **kwargs: Items that will be added to the image dictionary, e.g....
Read more >
Discussions · Q A · fepegar/torchio - GitHub
Applying Transforms to both Image and Label without SubjectDataset ... in patch_loader report errors, FileNotFoundError: File not found: "affine".
Read more >
Python3 - Cannot import local module due to FileNotFoundError
Within my code I am attempting to import modules written by myself. Said modules interact with files on the system, either encrypting, ...
Read more >
Inverse affine transformation from .xml after RVSS
I want to find inverse affine transformations and save them to .xml files. I used RVSS tool in FIJI and saved transformations in...
Read more >
Source code for monai.data.image_reader
This function must return two objects, the first is a numpy array of image data, the second is a dictionary of metadata. Args:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found