Beispiel #1
0
    device = torch.device('cuda' if args.cuda else 'cpu')

    torch.manual_seed(args.seed)
    if args.cuda:
        torch.cuda.manual_seed(args.seed)

    kwargs = {'num_workers': 1, 'pin_memory': True} if args.cuda else {}
    normalize = transforms.Normalize(mean=[0.4914, 0.482, 0.4465],
                                     std=[0.2023, 0.1994, 0.2010])

    train_loader = torch.utils.data.DataLoader(
        cifar.CIFAR100('./cifar-100', train=True, download=True,
                       transform=transforms.Compose([
                           transforms.RandomCrop(32, padding=4),
                           transforms.RandomHorizontalFlip(),
                           transforms.ToTensor(),
                           normalize
                       ])),
        batch_size=args.batch_size, shuffle=True, **kwargs)
    test_loader = torch.utils.data.DataLoader(
        cifar.CIFAR100('./cifar-100', train=False, transform=transforms.Compose([
                           transforms.ToTensor(),
                           normalize
                       ])),
        batch_size=args.test_batch_size, shuffle=True, **kwargs)

    model = archs[args.arch](num_classes=100)
    bn_names = []
    if args.l1_decay > 0:
        if not args.all_bn:
import os
import sys
import time
import numpy
import torch
from torchvision import transforms
from torchvision.datasets import cifar
from openvino.inference_engine import IECore, IENetwork

model_name = sys.argv[1]

normalize = transforms.Normalize(mean=[0.4914, 0.482, 0.4465],
                                 std=[0.2023, 0.1994, 0.2010])

test_loader = torch.utils.data.DataLoader(cifar.CIFAR100(
    './cifar-100',
    train=False,
    transform=transforms.Compose([transforms.ToTensor(), normalize])),
                                          batch_size=1,
                                          shuffle=True)

# Initialize inference engine core
ie = IECore()

# build network
net = IENetwork(model="{}.xml".format(model_name),
                weights="{}.bin".format(model_name))
input_name = next(iter(net.inputs))
output_name = next(iter(net.outputs))
exec_net = ie.load_network(network=net, device_name="CPU")

correct = 0
Beispiel #3
0
 def gen_val_datasets(self, transform=None, target_transform=None) -> Dataset:
     ds = cifar.CIFAR100(root="~/.cache/torch/data", train=True, download=True,
                         transform=transform, target_transform=target_transform)
     return Subset(OrderDataset(ds), list(range(40000, 50000)))
Beispiel #4
0
def train():
    import ubelt as ub
    root = ub.ensure_app_cache_dir('clab')
    train_dset = cifar.CIFAR100(root=root, download=True, train=True)
    test_dest = cifar.CIFAR100(root=root, download=True, train=False)
Beispiel #5
0
 def gen_test_datasets(self, transform=None, target_transform=None) -> Dataset:
     return cifar.CIFAR100(root="~/.cache/torch/data", train=False, download=True,
                           transform=transform, target_transform=target_transform)