Can't pickle local object 'BirdDataset.__init__.<locals>.<lambda>

Hi everyone,
I’m new to pytorch and the world of AI-coding. I have been working as part of a team on the BirdCLEF competition and have so far implemented several neural networks (that was how I got familiar with deep learning and image recognition). However, now that I’ve explored around, I must now work on the code my team-leader has written: GitHub - Arcadia24/CuiCuiProject. I have two problems when running the .ipynb in this code:

examples = next(iter(train_loader))
print(examples[0].shape)

this part of the code seems to be an infinite loop, and I don’t understand why because it works fine on GitHub (please note my team-leader made this on Linux and I am on Windows).

My second issue is the following:
In the train.fit() cell, I get the following error message: Can’t pickle local object 'BirdDataset.init..

Can someone maybe help me figure out what’s wrong? I would greatly appreciate it as I’m still not familiar with all the requirements and system errors that may come when using pytorch, pytorch_lightning and wandb.

By the way the dataset used is the BirdCLEF 2021 train dataset, and the transform function in the project converts the audio files to .png files of size 128*313. These pictures are stored as follows: spectrogram\label of species\filename.png

Thanks in advance,

Aksel

You might need to add the if-clause protection on Windows as described here.

Thank you for the response. I updated the cell to :

if name == “main”:

trainer.fit(model = model_pl, 
            train_dataloaders = train_loader, 
            val_dataloaders = valid_loader)

but I still get the can’t pickle local object error

I also tried with

def main():
     trainer.fit(model=model_pl,
                    train_dataloaders=train_loader,
                    val_dataloaders=valid_loader)

if __name__ == '__main__':
     trainer.fit(model = model_pl, 
                    train_dataloaders = train_loader, 
                    val_dataloaders = valid_loader)

I’m no a Windows expert so don’t know why the code work in Linux, but maybe this post could help as it has a few suggestions to fix similar issues.