<jupyter_start><jupyter_text>Notes- Q. What's `transform` for!- A. Change PIL image to tensor, apply lambda, etc. (I think those are the key ones)  Visualization<jupyter_code>labels_map = {
    0: "T-Shirt",
    1: "Trouser",
    2: "Pullover",
    3: "Dress",
    4: "Coat",
    5: "Sandal",
    6: "Shirt",
    7: "Sneaker",
    8: "Bag",
    9: "Ankle Boot",
}
figure = plt.figure(figsize=(8, 8))
axes = figure.subplots(3, 3).flatten()
for i, ax in enumerate(axes):
    sample_idx = torch.randint(len(training_data), size=(1,)).item()
    img, label = training_data[sample_idx]
    ax.set_title(labels_map[label])
    ax.axis("off")
    ax.imshow(img.squeeze(), cmap="gray")
plt.show()<jupyter_output><empty_output><jupyter_text>Custom Dataset!Very similar to Keras DataGenerator, need to implement `init`, `len`, `getitem` (`__`).<jupyter_code>import os
import pandas as pd
from torchvision.io import read_image
class CustomImageDataset(Dataset):
    def __init__(self, annotations_file, image_dir, transform=None, target_transform=None):
        self.image_labels = pd.read_csv(annotations_file)  # path, label
        self.image_dir = image_dir
        self.transform = transform
        self.target_transfrom = target_transform
    
    def __len__(self):
        return len(self.image_labels)
    
    def __getitem__(self, idx):
        path, label = self.image_labels.iloc[idx]
        image_path = os.path.join(self.image_dir, self.image_labels.iloc[idx, 0])
        image = read_image(image_path)
        if self.transform:
            image = self.transform(image)
        if self.target_transform:
            label = self.target_transfrom(label)
            
        return {"image": image, "label": label}  # why this format<jupyter_output><empty_output><jupyter_text>DataLoaders<jupyter_code>from torch.utils.data import DataLoader
train_loader = DataLoader(train_data, batch_size=64)
test_loader = DataLoader(test_data, batch_size=64)
train_loader
train_loader.__iter__().__next__()[0].shape, \
train_loader.__iter__().__next__()[1].shape
for i, (x, y) in enumerate(train_loader):
    x, y = x[0], y[0]  # first in batch
    plt.imshow(x[0])
    print(labels_map[y.item()])
    break<jupyter_output>Ankle Boot
{'fraction_non_alphanumeric': 0.13246519982038618, 'fraction_numerical': 0.01122586439155815, 'mean_word_length': 3.8329718004338393, 'pattern_counts': {'":': 2, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '387132', 'license': 'WTFPL', 'n_tokens_mistral': 789, 'n_tokens_neox': 776, 'n_words': 165, 'path': 'basics/2 Datasets and DataLoaders.ipynb', 'repo_name': 'itsnamgyu/pytorch-tutorial-day', 'size': '2227'}