1 Star 1 Fork 0

callmezhuo/pytorch-center-loss

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
datasets.py 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
KaiyangZhou 提交于 2018-03-21 17:56 . update comments
import torch
import torchvision
from torch.utils.data import DataLoader
import transforms
class MNIST(object):
def __init__(self, batch_size, use_gpu, num_workers):
transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.1307,), (0.3081,))
])
pin_memory = True if use_gpu else False
trainset = torchvision.datasets.MNIST(root='./data/mnist', train=True, download=True, transform=transform)
trainloader = torch.utils.data.DataLoader(
trainset, batch_size=batch_size, shuffle=True,
num_workers=num_workers, pin_memory=pin_memory,
)
testset = torchvision.datasets.MNIST(root='./data/mnist', train=False, download=True, transform=transform)
testloader = torch.utils.data.DataLoader(
testset, batch_size=batch_size, shuffle=False,
num_workers=num_workers, pin_memory=pin_memory,
)
self.trainloader = trainloader
self.testloader = testloader
self.num_classes = 10
__factory = {
'mnist': MNIST,
}
def create(name, batch_size, use_gpu, num_workers):
if name not in __factory.keys():
raise KeyError("Unknown dataset: {}".format(name))
return __factory[name](batch_size, use_gpu, num_workers)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/callmezhuo/pytorch-center-loss.git
git@gitee.com:callmezhuo/pytorch-center-loss.git
callmezhuo
pytorch-center-loss
pytorch-center-loss
master

搜索帮助