AttributeError: module 'pytorch_lightning' has no attribute 'data_loader'

Hello,
I am new at PyTorch Lightning. So, I am trying to learn the basics. When I am trying to run code from here (UNet implementation using PyTorch Lightning), I am getting an error AttributeError: module 'pytorch_lightning' has no attribute 'data_loader'.

The code is fully the same. I am getting the error in this block,

   @pl.data_loader
   def train_dataloader(self):
      return self.__dataloader()['train']

Could you tell me why I am getting this error and how can I solve this issue?
Thank you.

Hi! This code appears to be about a year old. We no longer use the pl.data_loader decorator, so everything should work fine once you remove it

Thank you very much @teddy

Should I remove the whole block of the code or only pl.data_loader?

Only the decorator (just that one line). Let me know if you run into any other issues (this code appears to be using a much older version, but I think everything else should still work in 1.0)

Thank you @teddy
Now, no compile-time error but showing run-time error only batches of spatial targets supported (3D tensors) but got targets of dimension: 4!

Looks to be an issue with the model, mind providing the full stack trace?

Hello, do you mean this?

File "/PyTorch/UNet-PyTorch/scripts/unet.py",
line 102, in training_step     loss = F.cross_entropy(y_hat, y) if self.n_classes > 1 else F.binary_cross_entropy_with_logits(y_hat, y)   
File "/PyTorch/UNet-PyTorch/scripts/train.py",
line 46, in main     trainer.fit(model)   
 File "/PyTorch/UNet-PyTorch/run_train.py",
line 14, in <module>     main(hparams)

I made a simple change of the main code is, I am running the train.py from another file run_train.py.

How many classes do your masks have? What is the value of self.n_classes. This may be the incorrect value

The value of n_classes is 1

I’m assuming your segmentation mask has an extra dimension for classes, you have to either .squeeze() this dimension if it is one class, change n_classes to be the actually number of classes.