Hi, sorry to continue to ask for help. I’ve done a bit more and get the error “OSError: [Errno 24] Too many open files”. I’ve tried adding some lines that seemed to work in fixing this error for other people, but it’s still not working.
I couldn’t figure out how to get the targets appended to each individual image so I created an array of the targets separated out and append that to each image file as it comes in. (Not sure if that will work).
data_loc = '.../sample_data/'
torch.multiprocessing.set_sharing_strategy('file_system')

target_counter = 0

"""
Getting the targets
"""
with open('.../annotations.txt') as f:
    content = f.readlines()
#makes each one a float
targets = [x.split(',') for x in content]
for a in targets:
    for ind,val in enumerate(a):
        #a[ind] = int(float(val))
        a[ind] = float(val)
targets = torch.FloatTensor(targets)


def load_file(file):
    temp = Image.open(file)
    keep = temp.copy()
    temp.close()
    data = tuple(keep,targets[target_counter])
    target_counter = target_counter + 1
    return data
    
class MyDataset(Data.Dataset):
    def __init__(self, data_files):
        self.data_files = sorted(data_files)

    def __getitem__(self, index):
        return load_file(self.data_files[index])

    def __len__(self):
        return len(self.data_files)
    
set_test = MyDataset(data_loc)
loader = Data.DataLoader(set_test,batch_size = BATCH_SIZE, num_workers=8)