How to reshape a dataset in order to make it sequential?

Mrofsnart

I have a classic dataset of images and labels.

Here is a simple representation of the __getitem__ function :

def __getitem__(self, index):
        (img_path, label) = df.iloc[index].values
        img = Image.open(img_path).convert("RGB")
        y = torch.tensor(labels))

        return (img, y)

I have :

dataset = ClassDataset()
train_set, validation_set = random_split(dataset)
train_loader = DataLoader(dataset=train_set)

The size of one batch of the train loader would be : [32,3,256,256] With 32 being the batch size, 3 the number of channels and 256 the width and height of my image.

I want to modify the shape of one batch so that it is sequential [8,4,3,256,256] with 8 being the batch size and 4 the length of one sequence. I know that it could be easily done with torch.view() or torch.reshape() knowing that my data are already in the right order (they can be grouped directly into sequences).
But I want to know where is the most intelligent place to make this change, in the dataset class, in the dataloader class or in the train loop.
I already tried passing sequences into the getitem :

(img_path, coords) = df.iloc[4*(index-1):4*index].values

(assuming that sequence length is 4), but it didn't work.

Ivan

It is more relevant to do this kind of processing in the dataset layer. Indeed, what you are looking to implement there is "given a dataset index index return the corresponding input and its label". In your case you are dealing with a sequence as input, so something like this makes sense for your __getitem__ to return a sequence of images.

The data loader will automatically collate the data such that you get (batch_size, seq_len, channel, height, width) for your input, and (batch_size, seq_len) for your label (or (batch_size,) if there is meant to be a single label per sequence).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to make multiple API calls in sequential order

fping – How to make fping result always sequential in order of command line

How to make anyevent "sequential"?

How to reshape dataset using python like this

How to reshape input for training on CIFAR dataset?

How do I reshape this dataset in Python pandas?

How to reshape a variable to wide in my dataset?

How to reshape numpy array with specific indexing order?

Julia: How to reshape an array while preserving the order?

XSLT:How to Maintain Sequential Order of tag in XML

How to execute Vertx Future in sequential order

How to rename dictionary keys to follow sequential order?

How do I read images in their sequential order?

How to use RxJS observables in sequential order?

How to run test in sequential order in loadimpact?

How to change files in the sequential order of the loop

How to reshape the (image, label) dataset after py_function

How to reshape 3 channel dataset for input to neural network

How to reshape a dataset that's not aligned and throw away leftover data with numpy?

Reshape SAS dataset

reshape multiple variables in a dataset

R reshape dataset

How to make these sequential histogram/density estimates plots

How to make a sequential number columns in Vaadin

How to make Sequential Processing as simple as Parallel Processing

How to make sequential execution of setTimeout in this example?

How to make the equivalent of Tensorflow sequential model in PyTorch?

NodeJS - how to make forEach and for loop functions sequential

In SSRS How to make a sequential Group Column