Why dataloader can not use global vatiable?

Suppose the following is python script

import torch
import os
import scipy.io as sio
from torch.utils.data import TensorDataset
root = '.'
data_img = sio.loadmat(os.path.join(root, 'mirflickr25k-iall-vgg-rand.mat'))['XAll']
data_txt = sio.loadmat(os.path.join(root, 'mirflickr25k-yall-rand.mat'))['YAll']
labels = sio.loadmat(os.path.join(root, 'mirflickr25k-lall-rand.mat'))['LAll']
def MIRFlickr25K_fea(partition):
    test_size = 2000
    train_size = 10000
    if 'test' in partition.lower():
        data_img, data_txt, labels = data_img[-test_size::], data_txt[-test_size::], labels[-test_size::]
    elif 'train' in partition.lower():
        data_img, data_txt, labels = data_img[0: train_size], data_txt[0: train_size], labels[0: train_size]
        data_img, data_txt, labels = data_img[0: -test_size], data_txt[0: -test_size], labels[0: -test_size]

    return torch.from_numpy(data_img), torch.from_numpy(data_txt), torch.from_numpy(labels)

d1,d2,d3 = MIRFlickr25K_fea('test')
mydata= TensorDataset(d1,d2,d3)
c = torch.utils.data.DataLoader(

Why DataLoader can not find the global variable even though VSCODE debuger can find these values.