It depends a bit on the current structure of your data.
Generally, if you are implementing a custom Dataset, you would need to implement:
the __getitem__(self, index) method, which uses the passed index to load a single “sample” of the dataset
the __len__(self) method, which returns the length of the dataset and thus defines the indices to be sampled from the range [0, self.__len__()]
as well as the __init__ method, if you want, to pass e.g. image paths, tansformations etc.
If your images are all in a single folder and can be loaded sequentially, you could define a window_length in the __init__ and load multiple frames in __getitem__. I assume the target would be a single class index for the complete sequence.
It’s a bit hard to give a good recommendation without knowing your use case.
We are attempting to classify gestures using a 3D CNN. Each gesture is captured as a series of JPG frames and indexed as a start_frame number and an end_frame number. There are 8 gestures to identify altogether.
Currently the data is saved in a separate directory for each Subject who performed the 8 gestures, but it’s our own dataset and we can alter the directory structure in any way we choose.
One aspect I don’t understand is how the network is made aware of the class labels. Are the classes (output targets) derived from the directory structure by DataLoader() somehow? And how can I separate my training and validation data appropriately?
The DataLoader is not responsible for the data and target creation, but allows you to automatically create batches, use multiprocessing to load the data in the background, use custom samplers, shuffle the dataset etc.
The Dataset defines how the data and target samples are created. torchvision.datasets provide some “standard approaches”, such as ImageFolder, which creates the targets based on the subfolders passed in the root argument (subfolders will be sorted and each folder will get an own class label).
However, this use case might be too limited for your use case, so that I would recommend to implement a custom Dataset. This tutorial gives you a good overview on creating a Dataset and use a DataLoader.
As described, the __getitem__ method would be responsible to load the data and target (or create the target based on some properties).
Before changing the data structure, let’s think about how the batches should be created.
I.e. would it be possible to create a batch given a single index using the current data structure?