Your code should work.
Generally I would recommend to create a custom Dataset (where you can use transformations etc.) or pass your tensors to a TensorDataset.
However, in your simple example, it should work nevertheless to pass the data tensor directly to the DataLoader.