PyTorch is one of the widely used deep learning libraries .Learning it has many benefits. Today we will start to learn about basic of pyTorch.
Importing Libraries
import torch
from torch import nn
from torch.utils.data import DataLoader
from torchvision import datasets
from torchvision.transforms import ToTensor
- importing torch
- then we are importing the Dataloader form torch.utils.data which help to iter over the data
- then importing dataset from pytorchvision
- lastly importing the transforms function that will transform the data to tensor of we could say array
Loading Dataset
# Download training data from open datasets.
training_data = datasets.FashionMNIST(
root="data",
train=True,
download=True,
transform=ToTensor(),
)
# Download test data from open datasets.
test_data = datasets.FashionMNIST(
root="data",
train=False,
download=True,
transform=ToTensor(),
)
- Making two variables training and testing to load the dataset of fashion items and transforming it
## Create the dataloader
We will create the data loader to iterate through
batch_size = 64
# Create data loaders.
train_dataloader = DataLoader(training_data, batch_size=batch_size)
test_dataloader = DataLoader(test_data, batch_size=batch_size)
for X, y in test_dataloader:
print(f"Shape of X [N, C, H, W]: {X.shape}")
print(f"Shape of y: {y.shape} {y.dtype}")
break
Will be continue from part-2
Top comments (0)