Get the App
SLTechnology News&Howtos  ›  Servers  › 

Analysis of dataset and dataloader examples of pytorch

Shulou Source: shulou.com Published: 2022-05-31 11:02:24 09月11日 Update

Most people do not understand the knowledge points of this "pytorch dataset and dataloader case Analysis" article, so the editor summarizes the following, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "pytorch dataset and dataloader case Analysis" article.

Dataset,dataloder analysis

Only the datasets downloaded from the Internet are stored in the cifar_data_test folder created by ourselves.

Cifar-10-python.tar.gz

Due to the existence of download=True: an extra cifar-10-batches-py

Dataset = torchvision.datasets.CIFAR10 (root='./cifar_data_test',download=True)

Print (dataset) can see that the dataset defaults to train=True

Train=False is used to select a training set or a test set.

Dataset = torchvision.datasets.CIFAR10 (root='./cifar_data_test',train=False,download=True) print (dataset) print (dataset.classes) print (dataset.data.shape, "\ n", dataset.data)

Transform

One: because CIFAR10 is tensor, it is useless to it.

Second: the transform added to dataset does not normalize the dataset, but only when dataloader

Import torchvision.datasetsimport torchvision.transforms as transformsfrom torch.utils.data import DataLoader#transform has two operations, one is to change it into tensor form that pythonj is easy to handle. The second is to normalize tensor transform= transforms.Compose ([transforms.ToTensor (), transforms.Normalize ((0.1307,), (0.3081,))]) dataset = torchvision.datasets.CIFAR10 (root='./cifar_data_test',train=True,download=True,transform=transform) print (dataset.data) # unnormalized train_loader = DataLoader (dataset,shuffle=False,batch_size=32) # dataloader has no transform parameter for img Target in train_loader:print (img) # data normalization above is the content of the article "dataset and dataloader instance Analysis of pytorch" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Tags: Content analysis data examples case analysis that is articles knowledge articles two values parameters only most forms files folders more steps knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Apple macOS Huawei MariaDB