MNIST 数据加载
import numpy as np from matplotlib import pyplot as plt from torchvision import datasets, transforms def softmax_t(x, t): x_exp = np.exp(x /t) return x_exp / np.sum(x_exp) DATA = datasets.MNIST('dengyexun', train=False, download=False, transform=transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.1307,),(0.3081,))])) # 生成一个数据data_loader test_loader_bs1 = torch.utils.data.DataLoader(DATA, batch_size=1, shuffle=True) print(DATA) print(test_loader_bs1) # 封装成一个迭代器 print(iter(test_loader_bs1)) # 取迭代器中的数据 print(next(iter(test_loader_bs1)))
随取随用
时刻记着自己要成为什么样的人!