Random sampling from pixels of an image

Hi All

I have a dataset that has the shape [65536,1,94], which 65536 is number of my samples, 1 is num of the channel and 94 is length of the signal.(my dataset is 65536 signals).

Dose anyone know how I can split this dataset to test dataset and train dataset randomly? Randomly splitting is so important for me because the number of datasets (65536) is actually pixels of an image (256*256).

tnx

Hi,

You can use torch.utils.data.random_split:

import torch
from torch.utils.data import random_split

data = torch.arange(0, 1000*94).reshape((1000, 1, 94))

train, test= random_split(data, [int(len(data)*0.9), int(len(data)*0.1)])

print(len(train))  # 900
print(len(test))  # 100

Bests

1 Like