Skip to content

How to get image file names from DataLoader #7850

@karllandheer

Description

@karllandheer

Hello, I would like to get the image filenames from the DataLoader. What's the easiest way to do this? Is it safe to assume the order of the images is the same as input when accessing the data by iterating through the data loader object as long as shuffle = False like this. I.e., will all_labels and local_train_images match in ordering?

train_ds = ImageDataset(image_files=local_train_images, labels=train_labels, transform=train_transforms) 
train_loader = DataLoader(train_ds, batch_size=8, shuffle=False, num_workers=2, pin_memory=pin_memory) 

all_labels = []
for batch_data in train_loader:
            step += 1
            inputs, labels = batch_data[0].to(device), batch_data[1].to(device)
            all_labels.append(labels)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions