Hello,
ok then it means, it is possible to group the float values by 3 to get color pixels assuming the floats are gathered in a list and that this is the original intended format for the file.
Now a solution would be to subclass the torch.utils.data.Dataset class:
import itertools
from torch.utils.data import Dataset, DataLoader


def chunks(lst, n):
    """Yield successive n-sized chunks from lst."""
    for i in range(0, len(lst), n):
        yield lst[i:i + n]

class TextDataset(Dataset):
    def __init__(self, text_file_paths, other_arguments):
        self.paths = text_file_paths
        # other processing you may want
        ...

    def __len__(self):
        return len(self.paths)
    
    def __getitem__(self, idx):
        path = self.paths[idx]
        with open(path, "r") as fd: # EDIT 
            content = fd.readlines().strip()
        pixel_values = [map(float, row.split(" ")) for row in content]
        # all float values in one list
        all_float_values = list(itertools.chain.from_iterable(pixel_values)))
        # group the float values by 3
        color_pixels = list(chunks(all_float_values, 3))
        # again, split this color_pixels into a list of 28 elements
        image = list(chunks(color_pixels, 28))
        return torch.tensor(image)

StackOverflow links:

how-do-you-split-a-list-into-evenly-sized-chunks 1
join-list-of-lists-in-python 2

Finally
text_ds = TextDataset(your_text_file_paths_list, ...)
mydataloader = DataLoader(text_ds, batch_size=16, shuffle=True)

Hope it helps