Execution block when calling DataLoader with self-defined functions on the dataset class
I am running my code in Colab. I use Dataloader to load my dataset as batches for training and validation, and tqdm to visualize the training process. But every time I execute my code, I get stuck at a random point (in epoch 0, meaning the dataset has never been traversed), saying that the program is still running but the progress bar is frozen. An interesting phenomenon lies in the self-defined transformation functions of the inputs since once I drop these transformations, everything went smoothly. The functions are:
class Sharpen(object):
    def __init__(self, p=0.5):
        self.p = p
    
    def __call__(self, sample):
        if random.uniform(0.0, 1.0) &lt; self.p:
            return sample
        kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]], np.float32)
        for i in range(len(sample['img_list'])):
            sample['img_list'][i] = cv2.filter2D(sample['img_list'][i], -1, kernel=kernel)
            
        return sample


class Rotation(object):
    def __init__(self, angle=5, fill_value=0, p=0.5):
        self.angle = angle
        self.fill_value = fill_value
        self.p = p

    def __call__(self, sample):
        if random.uniform(0.0, 1.0) &lt; self.p:
            return sample
        for i in range(len(sample['img_list'])):
            ang_rot = np.random.uniform(self.angle) - self.angle / 2
            h, w, _ = sample[&quot;img_list&quot;][i].shape 
            if h*w == 0:
                continue 
            transform = cv2.getRotationMatrix2D((w / 2, h / 2), ang_rot, 1)
            sample[&quot;img_list&quot;][i] = cv2.warpAffine(sample[&quot;img_list&quot;][i], transform, (w, h),
                              borderValue=self.fill_value)
            
        return sample


class Translation(object):
    def __init__(self, fill_value=0, p=0.5):
        self.fill_value = fill_value
        self.p = p
        self.SIGMA = 1e-3

    def __call__(self, sample):
        rand_num = random.uniform(0.0, 1.0)
        if rand_num &lt;= self.p:
            return sample
        
        for i in range(len(sample['img_list'])):
            h, w, _ = sample[&quot;img_list&quot;][i].shape
            if h*w == 0:
                continue
            trans_range = (w / 10, h / 10)
            tr_x = trans_range[0] * rand_num - trans_range[0] / 2 + self.SIGMA
            tr_y = trans_range[1] * rand_num - trans_range[1] / 2 + self.SIGMA
            transform = np.float32([[1, 0, tr_x], [0, 1, tr_y]])
            sample[&quot;img_list&quot;][i] = cv2.warpAffine(sample[&quot;img_list&quot;][i], transform, (w, h), 
                                borderValue=self.fill_value)
        
        return sample

class Normalization(object):
    def __init__(self, mean=(0,0,0), std=(255,255,255)):
        self.mean = mean
        self.std = std
    
    def __call__(self, sample):
        # norm_func = transforms.Normalize(self.mean, self.std)
        for i in range(len(sample['img_list'])):
            for j in range(3):  # for colored image
                sample['img_list'][i][:,:,j] = np.array(list(map(lambda x: (x-self.mean[j])/self.std[j], sample['img_list'][i][:,:,j])),
                                     dtype=np.float32)
            # sample['img_list'][i] = norm_func(torch.Tensor(sample['img_list'][i]))
        return sample

The parameter sample is a dictionary, and the key: img_list represents a list of images (numpy.ndarray) processed by cv2.imread. The shape of each image is (h, w, c) and the size is not equal across images.
I created a Dataset Class and proceeded input images with Compose([Sharpen(), Rotation(), Translation(), Normalization()]). Now I don't know what's wrong with the transformation code. Any kind of help is appreciated!

Problem solved. It is because of the data. If the input image is an empty one, the loading procedure will get stuck.
