facebookresearch / fastMRI

A large-scale dataset of both raw MRI measurements and clinical MRI images.
https://fastmri.org
MIT License
1.35k stars 375 forks source link

Variational Network Implementation Problem in Dataset Loading Images #180

Closed mattnsoleil closed 3 years ago

mattnsoleil commented 3 years ago

Hi,

In test dataset, It gives TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'NoneType'>. There is a problem in dataset loading images with the PIL library and does not convert them into necessary types like list or Tensor. Is there anyone who overcome this problem? Because I could not overcome with editting transform = transforms.Compose([ transforms.ToTensor() ]).

mmuckley commented 3 years ago

Hello @mattnsoleil, we actually don't use PIL at all. As you can see in mri_data.py, we return a tuple with several different data types, the first of which should be a numpy array.

https://github.com/facebookresearch/fastMRI/blob/dc90301218c70ee70f8b155aa240d6ece5639249/fastmri/data/mri_data.py#L356

We provide examples of transforms you can use for this tuple for both the U-Net and the VarNet. Simple combinations of torchvision transforms will not work - MRI reconstruction is a substantially different application than where torchvision is used so you will need to reimplement most things to work with this data depending on how you want it preprocessed for your model.

mattnsoleil commented 3 years ago

Hello,

I have been always encountering TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'NoneType'> in Variational Network implementation not in UNET with fastmri multicoil knee test dataset. It works correctly in UNET. Thank you for sharing. But When searched for this error, it is always saying that dataset loading image error in PIL. I have seen all types were tuple but could not see the solution. Both UNET and Variational Network use mri_data.py and all types are tuple, but it just works only in UNET but not works in Variational Netwok. It is not about update of torchvision or transforms.ToTensor(). Is there anyone to overcome this problem?

Thanks,

mmuckley commented 3 years ago

Could you identify which script in the repository you ran to generate the error? I also need to know what transform function you used.

For example, one way this error might happen would be if you used a SliceDataset without the VarNetDataTransform. SliceDataset in this case will return a None for target. A None cannot be collated. This is fixed if you use the VarNetDataTransform which converts the None to a 0.

mattnsoleil commented 3 years ago

No, I have used VarNetDataTransform from fastmri/data/transforms.py. There is no problem in data_transform result. I could see it but in mri_data.py, SliceDataset does not give a dataset for DataLoader. Firstly, I saw TypeError: Caught TypeError in DataLoader worker process 0 and then faced TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'NoneType'. I thought there was a problem in converting tensor , made some modification but that were not a solution for this.

Have you got any idea why I have been facing this error?

Best,

mmuckley commented 3 years ago

@mattnsoleil unfortunately I don't think I can diagnose your case without a reproducible example.

mattnsoleil commented 3 years ago

python run_pretrained_varnet_inference.py --data_path 'G:\knee_multicoil_test_v2\multicoil_test_v2/' --output_path 'G:\Variational_Output_Test/' --challenge varnet_knee_mc command gives me this error.

Running inference: 0% 0/653 [00:00<?, ?it/s] Traceback (most recent call last): File "run_pretrained_varnet_inference.py", line 151, in torch.device(args.device), File "run_pretrained_varnet_inference.py", line 88, in run_inference for batch in tqdm(dataloader, desc="Running inference"): File "/usr/local/lib/python3.7/dist-packages/tqdm/std.py", line 1180, in iter for obj in iterable: File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py", line 521, in next data = self._next_data() File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py", line 1203, in _next_data return self._process_data(data) File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py", line 1229, in _process_data data.reraise() File "/usr/local/lib/python3.7/dist-packages/torch/_utils.py", line 425, in reraise raise self.exc_type(msg) TypeError: Caught TypeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop data = fetcher.fetch(index) File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 47, in fetch return self.collate_fn(data) File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/collate.py", line 76, in default_collate return elem_type((default_collate(samples) for samples in zip(batch))) File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/collate.py", line 76, in return elem_type((default_collate(samples) for samples in zip(batch))) File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/collate.py", line 86, in default_collate raise TypeError(default_collate_err_msg_format.format(elem_type)) TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class 'NoneType'>

mmuckley commented 3 years ago

I can reproduce this. Working on a fix.

mmuckley commented 3 years ago

@mattnsoleil this should be fixed by PR #181. Let me know if it works for you.

mattnsoleil commented 3 years ago

Thanks, It worked.

mmuckley commented 3 years ago

Closing this as it seems to be resolved.