Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

How to slice Kinetics400 training dataset? (pytorch)

I am trying to run the official script for video classification. I want to tweak some functions and running through all examples would cost me too much time. I wonder how can I slice the training kinetics dataset based on that script. This is the code I added before train_sampler = RandomClipSampler(dataset.video_clips, args.clips_per_video) in the script: (let's say I just want to run 100 examples.)

tr_split_len = 100
dataset = torch.utils.data.random_split(dataset, [tr_split_len, len(dataset)-tr_split_len])[0]

Then when hitting train_sampler = RandomClipSampler(dataset.video_clips, args.clips_per_video) , it pops out the error:

AttributeError: 'Subset' object has no attribute 'video_clips'

Yeah, so the type of dataset converts from torchvision.datasets.kinetics.Kinetics400 to torch.utils.data.dataset.Subset. I understand. So how can I do it? (hopefully not the way using break in the dataloader loop). Thanks.

question from:https://stackoverflow.com/questions/65841394/how-to-slice-kinetics400-training-dataset-pytorch

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It seems that torchvision.datasets.kinetics.Kinetics400 internally uses an object of class VideoClips to store the information about the clips. It is stored in the member variable Kinetics4000().video_clips.

The VideoClips class has a function called subset, that takes a list of indices and returns a new VideoClips object with only the clips with the specified indices. You could then just replace the old VideoClips object with the new one in your dataset.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...