never stops running

I am trying to create my own custom dataset to train a CNN.My dataset has images and corresponding annotations.
The code is as follows:

import ...

class Data(Dataset):
#    def _init_(self, annotation , root_dir , transform=None):   
    def __init__(self, root_dir,annotation):   
        self.annotations = annotation
        self.root_dir = ...
    def __len__(self):
        return len(self.annotations[0,:])
    def __getitem__(self,idx):
        image_name = ..
        image_mat = #images are saved as mat files                                                
        annotation = ...
        return image, annotation 
trainset = Data(root_dir = "....",annotation = annotation)
dataloader = DataLoader(trainset, batch_size=5,
                        shuffle=True, num_workers=4)

dataiter = iter(dataloader)

Now the iterable dataiter is created.
However, whenever I do : image,annotation = , the code just keeps on running , never giving a result .
Can someone please explain this ?
Thanks .

Could you try to get a sample directly with:

image, annotation = trainset[0]

Does it work?
If it’s working, could you try to set num_workers=0 in your DataLoader and run it again?

@ptrblck had the same issue. It worked with me when I set the num_workers to zero but I could not understand why increasing the number of workers will make the loading stuck?

If you are using Windows, you would need to if-clause protection as described in the Windows FAQ. If that’s not the case, other reasons might be insufficient shared memory or any other problem with multiprocessing on your system.
Also, if you are using a Jupyter Notebook, try to run the script directly in a terminal, as it might give you better error messages.