Loading Dating without a separate TRAIN/TEST Directory : Pytorch (ImageFolder)
My data is not distributed in train and test directories but only in classes. I mean:
image-folders/
   ├── class_0/
   |   ├── 001.jpg
   |   ├── 002.jpg
   └── class_1/
   |   ├── 001.jpg
   |   └── 002.jpg
   └── class_2/
       ├── 001.jpg
       └── 002.jpg

Is it the right way to approach the problem (What this does is: take datafolder and than divide it into train, valid and test sets. However, i am worried if it is the samething as valid/dev set even though &quot;test set&quot; will not go through training and validation loop):
        data = datasets.ImageFolder('PATH', transform)
        # creating a train / valid split
# valid set will be further divided into valid and test sets
indices = list(range(len(data)))
np.random.shuffle(indices)
split = int(np.floor(valid_size * len(data)))
train_idx, valid_idx = indices[split:], indices[:split]

# Creating a valid and test set
valid_idx = valid_idx[int(np.floor(0.2*len(valid_idx))) : len(valid_idx)]
test_idx = valid_idx[0:int(np.floor (0.2 * len(valid_idx) ) )]

# define samplers for obtaining training and validation batches
train_sampler = SubsetRandomSampler(train_idx)
valid_sampler = SubsetRandomSampler(valid_idx)
test_sampler = SubsetRandomSampler(test_idx)    
    # prepare data loaders (combine dataset and sampler)
        train_loader = torch.utils.data.DataLoader(data, batch_size=batch_size, sampler=train_sampler, num_workers=num_workers)
        valid_loader = torch.utils.data.DataLoader(data, batch_size=batch_size, sampler=valid_sampler, num_workers=num_workers)
        test_loader = torch.utils.data.DataLoader(data, batch_size=batch_size, sampler=test_sampler  num_workers=num_workers)

Thanks in advance.

This seems ok to me. Alternatively you can create three separate datasets from data, using torch.utils.data.random_split. This has the benefit of not having to worry about implementing the samplers for your dataloaders:
from torch.utils.data import DataLoader, random_split

dl_args = dict(batch_size=batch_size, num_workers=num_workers)


With a train/validation split:
&gt;&gt;&gt; data = datasets.ImageFolder('PATH', transform)
&gt;&gt;&gt; n_val = int(np.floor(valid_size * len(data)))
&gt;&gt;&gt; n_train = len(data) - n_val

Datasets and dataloaders initialization:
&gt;&gt;&gt; train_ds, val_ds = random_split(data, [n_train, n_val])

&gt;&gt;&gt; train_dl = DataLoader(train_ds, **dl_args)
&gt;&gt;&gt; valid_dl = DataLoader(val_ds , **dl_args)


With a train/validation/test split:
&gt;&gt;&gt; data = datasets.ImageFolder('PATH', transform)
&gt;&gt;&gt; n_val = int(np.floor(valid_size * len(data)))
&gt;&gt;&gt; n_test = int(np.floor(test_size * len(data)))
&gt;&gt;&gt; n_train = len(data) - n_val - n_test

Datasets and dataloaders initialization:
&gt;&gt;&gt; train_ds, val_ds, test_ds = random_split(data, [n_train, n_val, n_test])

&gt;&gt;&gt; train_dl = DataLoader(train_ds, **dl_args)
&gt;&gt;&gt; valid_dl = DataLoader(val_ds, **dl_args)
&gt;&gt;&gt; test_dl = DataLoader(test_ds, **dl_args)



