How can I solve it ,TypeError: cannot pickle 'dict_keys' object?

Tariq_Hussain: <pre><code>class spatial_dataset(Dataset):  
    def __init__(self, dic, root_dir, mode, transform=None):


    self.keys = dic.keys()
    self.values=dic.values()
    self.root_dir = root_dir
    self.mode =mode
    self.transform = transform

def __len__(self):
    return len(self.keys)

def load_ucf_image(self,video_name, index):
        path = self.root_dir + '/' + video_name.split('_')[0] + '/' + 'v_' + video_name + '/'

    print(path+'Image'+str(index)+'.jpg')
    img = Image.open(path+'Image'+str(index)+'.jpg')
    transformed_img = self.transform(img)
    img.close()

    return transformed_img

def __getitem__(self, idx):
    print(idx)
    if self.mode == 'train':
        video_name, nb_clips = list(self.keys)[idx].split(' ')
        print(video_name, nb_clips)
        num_clip = int(nb_clips)
        print(num_clip)
        clips = []
        clips.append(random.randint(1, int(num_clip/3)))
        clips.append(random.randint(int(num_clip/3), int(num_clip*2/3)))
        clips.append(random.randint(int(num_clip*2/10), num_clip+1))
        # for i in range(10):
        #     clips.append(random.randrange(1, num_clip, 1))
        print(clips)
        

    label = list(self.values)[idx]
    label = int(label)-1

    if self.mode=='train':
        data =[]
        for i in range(len(clips)):
            key = 'img'+str(i)
            index = clips[i]
            data.append(self.load_ucf_image(video_name, index))
        data = np.array(data)
        label = np.array(label)
        sample = (data, label)

    return sample
</code></pre>
<p><code>dic.training is dictionary</code>, which have;<br>
{‘videoname_1 framecount_1’: label1,‘videoname_2 framecount_2’ : label2, …}</p>
<pre><code>training_set = spatial_dataset(dic=dic_training, root_dir=data_path, mode='train', transform = transforms.Compose([
                transforms.RandomCrop(224),
                transforms.RandomHorizontalFlip(),
                transforms.ToTensor(),
                transforms.Normalize(mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225])
                ]))
        print('==&gt; Training data :',len(training_set),'frames')
        print("training_set: ",training_set[1][0])
</code></pre>
<p>Till Above, it is running but when I use this below code it shows me error (mentioned below)</p>
<pre><code>train_loader = DataLoader(
            dataset=training_set,
            batch_size=BATCH_SIZE,
            shuffle=True,
            num_workers=num_workers)

    for z,i in train_loader:
        print(i)
</code></pre>
<p>This is error it is showing me;</p>
<p><a href="https://i.stack.imgur.com/rY2cv.png" rel="noopener nofollow ugc"><img src="https://i.stack.imgur.com/rY2cv.png" alt="enter image description here" width="690" height="140"></a></p>
<p>It is something because I am using dictionary to store values, I then converted it into the numpy arrays and list but still it is showing me this error I don’t know where it is going wrong.</p>

ptrblck: <p>Maybe your issue is related to <a href="https://discuss.pytorch.org/t/dataloader-multiprocessing-error-cant-pickle-odict-keys-objects-when-num-workers-0/43951/4">this one</a>, so you might want to take a look at it.</p>

Trantow: <p>That is the thing that I was searching for, what a data present here at this site, thank you administrator<a href="https://www.prepaidcardstatus.biz/" rel="noopener nofollow ugc">.</a></p>