Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get image file names from DataLoader #7850

Closed
karllandheer opened this issue Jun 14, 2024 · 1 comment
Closed

How to get image file names from DataLoader #7850

karllandheer opened this issue Jun 14, 2024 · 1 comment

Comments

@karllandheer
Copy link

karllandheer commented Jun 14, 2024

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)
@KumoLiu
Copy link
Contributor

KumoLiu commented Jun 25, 2024

Hi @karllandheer, you can get the file name by using inputs.meta["filename_or_obj"]. The info should be saved in the meta information.

Hope it helps, move to discussion for now.
Feel free to create another one if you have more issues.
Thanks.

@Project-MONAI Project-MONAI locked and limited conversation to collaborators Jun 25, 2024
@KumoLiu KumoLiu converted this issue into discussion #7878 Jun 25, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants