-
Notifications
You must be signed in to change notification settings - Fork 7k
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
UCF101 datasets with DataLoader returns error when stacking examples in mini-batches #2265
Comments
Thanks for the bug report! I see that you are using torchvision 0.5.0, would it be possible to try seeing if you reproduce the error with the latest stable release (0.6.0)? |
Yes, of course:
Same exact code as above returns:
On a side note, I tried to set Thank you for any help you may provide! |
Did you try rescaling the videos so that they have the same size? vision/references/video_classification/train.py Lines 121 to 127 in 11a39aa
|
Thanks for the tip. I tried to resize the video, without success. |
Oh, I see, yes, this is an issue with the audio signal. I would propose that you write a custom collate_fn that you pass to your DataLoader which will remove the def custom_collate(batch):
filtered_batch = []
for video, _, label in batch:
filtered_batch.append((video, label))
torch.utils.data.dataloader.default_collate(filtered_batch) |
Perfect, that's working! I just added def custom_collate(batch):
filtered_batch = []
for video, _, label in batch:
filtered_batch.append((video, label))
return torch.utils.data.dataloader.default_collate(filtered_batch) Final working code import torchvision.datasets as datasets
import torchvision.transforms as transforms
from torch.utils.data import DataLoader
tfs = transforms.Compose([
# scale in [0, 1]
transforms.Lambda(lambda x: x / 255.),
# reshape into (T, C, H, W)
transforms.Lambda(lambda x: x.permute(0, 3, 1, 2) )
])
# root, root_labels are the directories containing data and labels
d = datasets.UCF101(root, root_labels, frames_per_clip=25,
step_between_clips=25, train=False, transform=tfs)
dataset = DataLoader(d, batch_size=7, shuffle=True,
drop_last=True, collate_fn=custom_collate)
for i, (v, l) in enumerate(dataset):
print(v.size())
print(l)
break Thank you very much!! |
Hi @fmassa, could we somehow integrate this |
Probably even just mentioning this in the UCF101 dataset class documentation would be useful. |
🐛 Bug
UCF101
dataset returns aRunTimeError
when combined with standardDataLoader
class. It returns the error when trying to stack multiple tensors in batches.To Reproduce
Expected behavior
The iteration over the dataloader should return a video tensor of size
(B, T, C, H, W)
where B is batch size, T is the number of frames, C are the image channels and H and W the image dimensions.Environment
conda
,pip
, source): condaThe text was updated successfully, but these errors were encountered: