I am not sure, why you were using slice in caffe.
After the training you can get the data and target from both datasets either by calling
data, target = train_dataset[0]
data_val, target_val = val_dataset[0]

or by wrapping it again in a DataLoader and iterate it.
I’m not sure, but it seems the caffe slice layer separates a blob along an axis.
You don’t need it in this case.
Also torch.slice does not exist. You can use narrow however.
Could you explain your use case a little bit more? I’m not sure I understand it correctly.