I have the same problem when I try to introduce another module into Dataset Object. When I delete self.ds，it runs. But I have no idea about keeping self.ds and correct the code.
class Dataset(torch.utils.data.Dataset):
    def __init__(self, config, ds, index):
        self.input_res = config['train']['input_res']   
        self.output_res = config['train']['output_res']   
        self.generateHeatmap = GenerateHeatmap(self.output_res, config['inference']['num_parts'])
        self.ds = ds    # the error source
        self.index = index