本文整理匯總了Python中torch.utils.load方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.load方法的具體用法?Python utils.load怎麽用?Python utils.load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torch.utils
的用法示例。
在下文中一共展示了utils.load方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: parse_cycles
# 需要導入模塊: from torch import utils [as 別名]
# 或者: from torch.utils import load [as 別名]
def parse_cycles():
logging.debug(locals())
assert len(args.add_width) == len(args.add_layers) == len(args.dropout_rate) == len(args.num_to_keep)
assert len(args.add_width) == len(args.num_morphs) == len(args.grace_epochs) == len(args.epochs)
cycles = []
for i in range(len(args.add_width)):
try_load = args.try_load and i > 0
net_layers = args.layers + int(args.add_layers[i])
net_init_c = args.init_channels + int(args.add_width[i])
if len(cycles) > 0 and try_load:
if cycles[-1].net_layers != net_layers or cycles[-1].net_init_c != net_init_c:
try_load = False
cycles.append(Cycle(
num=i,
net_layers=args.layers + int(args.add_layers[i]),
net_init_c=args.init_channels + int(args.add_width[i]),
net_dropout=float(args.dropout_rate[i]),
ops_keep=args.num_to_keep[i],
epochs=args.epochs[i],
grace_epochs=args.grace_epochs[i] if not args.test else 0,
morphs=args.num_morphs[i],
init_morphed=try_load,
load=try_load,
is_last=(i == len(args.num_to_keep) - 1)))
return cycles
示例2: main
# 需要導入模塊: from torch import utils [as 別名]
# 或者: from torch.utils import load [as 別名]
def main():
if not torch.cuda.is_available():
logging.info('No GPU found!')
sys.exit(1)
np.random.seed(args.seed)
torch.manual_seed(args.seed)
torch.cuda.manual_seed(args.seed)
torch.cuda.manual_seed_all(args.seed)
cudnn.enabled = True
cudnn.benchmark = True
logging.info("Args = %s", args)
_, model_state_dict, epoch, step, optimizer_state_dict, best_acc_top1 = utils.load(args.output_dir)
train_queue, valid_queue, model, train_criterion, eval_criterion, optimizer, scheduler = build_imagenet(model_state_dict, optimizer_state_dict, epoch=epoch-1)
while epoch < args.epochs:
scheduler.step()
logging.info('epoch %d lr %e', epoch, scheduler.get_lr()[0])
train_acc, train_obj, step = train(train_queue, model, optimizer, step, train_criterion)
logging.info('train_acc %f', train_acc)
valid_acc_top1, valid_acc_top5, valid_obj = valid(valid_queue, model, eval_criterion)
logging.info('valid_acc_top1 %f', valid_acc_top1)
logging.info('valid_acc_top5 %f', valid_acc_top5)
epoch += 1
is_best = False
if valid_acc_top1 > best_acc_top1:
best_acc_top1 = valid_acc_top1
is_best = True
utils.save(args.output_dir, args, model, epoch, step, optimizer, best_acc_top1, is_best)
示例3: main
# 需要導入模塊: from torch import utils [as 別名]
# 或者: from torch.utils import load [as 別名]
def main():
if not torch.cuda.is_available():
logging.info('No GPU found!')
sys.exit(1)
random.seed(args.seed)
np.random.seed(args.seed)
torch.manual_seed(args.seed)
torch.cuda.manual_seed(args.seed)
torch.cuda.manual_seed_all(args.seed)
cudnn.enabled = True
cudnn.benchmark = False
cudnn.deterministic = True
args.steps = int(np.ceil(50000 / args.batch_size)) * args.epochs
logging.info("Args = %s", args)
_, model_state_dict, epoch, step, optimizer_state_dict, best_acc_top1 = utils.load(args.output_dir)
build_fn = get_builder(args.dataset)
train_queue, valid_queue, model, train_criterion, eval_criterion, optimizer, scheduler = build_fn(model_state_dict, optimizer_state_dict, epoch=epoch-1)
while epoch < args.epochs:
scheduler.step()
logging.info('epoch %d lr %e', epoch, scheduler.get_lr()[0])
train_acc, train_obj, step = train(train_queue, model, optimizer, step, train_criterion)
logging.info('train_acc %f', train_acc)
valid_acc_top1, valid_obj = valid(valid_queue, model, eval_criterion)
logging.info('valid_acc %f', valid_acc_top1)
epoch += 1
is_best = False
if valid_acc_top1 > best_acc_top1:
best_acc_top1 = valid_acc_top1
is_best = True
utils.save(args.output_dir, args, model, epoch, step, optimizer, best_acc_top1, is_best)
示例4: main
# 需要導入模塊: from torch import utils [as 別名]
# 或者: from torch.utils import load [as 別名]
def main():
if not torch.cuda.is_available():
logging.info('No GPU found!')
sys.exit(1)
np.random.seed(args.seed)
torch.manual_seed(args.seed)
torch.cuda.manual_seed(args.seed)
torch.cuda.manual_seed_all(args.seed)
cudnn.enabled = True
cudnn.benchmark = True
args.steps = int(np.ceil(50000 / args.batch_size)) * args.epochs
logging.info("Args = %s", args)
_, model_state_dict, epoch, step, optimizer_state_dict, best_acc_top1 = utils.load(args.output_dir)
build_fn = get_builder(args.dataset)
train_queue, valid_queue, model, train_criterion, eval_criterion, optimizer, scheduler = build_fn(model_state_dict, optimizer_state_dict, epoch=epoch-1)
while epoch < args.epochs:
scheduler.step()
logging.info('epoch %d lr %e', epoch, scheduler.get_lr()[0])
train_acc, train_obj, step = train(train_queue, model, optimizer, step, train_criterion)
logging.info('train_acc %f', train_acc)
valid_acc_top1, valid_obj = valid(valid_queue, model, eval_criterion)
logging.info('valid_acc %f', valid_acc_top1)
epoch += 1
is_best = False
if valid_acc_top1 > best_acc_top1:
best_acc_top1 = valid_acc_top1
is_best = True
utils.save(args.output_dir, args, model, epoch, step, optimizer, best_acc_top1, is_best)
示例5: main
# 需要導入模塊: from torch import utils [as 別名]
# 或者: from torch.utils import load [as 別名]
def main():
if not torch.cuda.is_available():
logging.info('no gpu device available')
sys.exit(1)
np.random.seed(args.seed)
torch.cuda.set_device(args.gpu)
cudnn.benchmark = True
torch.manual_seed(args.seed)
cudnn.enabled=True
torch.cuda.manual_seed(args.seed)
logging.info('gpu device = %d' % args.gpu)
logging.info("args = %s", args)
genotype = eval("genotypes.%s" % args.arch)
model = Network(args.init_channels, CIFAR_CLASSES, args.layers, args.auxiliary, genotype)
model = model.cuda()
utils.load(model, args.model_path)
logging.info("param size = %fMB", utils.count_parameters_in_MB(model))
criterion = nn.CrossEntropyLoss()
criterion = criterion.cuda()
_, test_transform = utils._data_transforms_cifar10(args)
test_data = dset.CIFAR10(root=args.data, train=False, download=True, transform=test_transform)
test_queue = torch.utils.data.DataLoader(
test_data, batch_size=args.batch_size, shuffle=False, pin_memory=True, num_workers=2)
model.drop_path_prob = args.drop_path_prob
test_acc, test_obj = infer(test_queue, model, criterion)
logging.info('test_acc %f', test_acc)
示例6: main
# 需要導入模塊: from torch import utils [as 別名]
# 或者: from torch.utils import load [as 別名]
def main():
if not torch.cuda.is_available():
logging.info('No GPU found!')
sys.exit(1)
np.random.seed(args.seed)
torch.manual_seed(args.seed)
torch.cuda.manual_seed(args.seed)
torch.cuda.manual_seed_all(args.seed)
cudnn.enabled = True
cudnn.benchmark = False
cudnn.deterministic = True
logging.info("Args = %s", args)
_, model_state_dict, epoch, step, optimizer_state_dict, best_acc_top1 = utils.load(args.output_dir)
train_queue, valid_queue, model, train_criterion, eval_criterion, optimizer, scheduler = build_imagenet(model_state_dict, optimizer_state_dict, epoch=epoch-1)
while epoch < args.epochs:
scheduler.step()
logging.info('epoch %d lr %e', epoch, scheduler.get_lr()[0])
train_acc, train_obj, step = train(train_queue, model, optimizer, step, train_criterion)
logging.info('train_acc %f', train_acc)
valid_acc_top1, valid_acc_top5, valid_obj = valid(valid_queue, model, eval_criterion)
logging.info('valid_acc_top1 %f', valid_acc_top1)
logging.info('valid_acc_top5 %f', valid_acc_top5)
epoch += 1
is_best = False
if valid_acc_top1 > best_acc_top1:
best_acc_top1 = valid_acc_top1
is_best = True
utils.save(args.output_dir, args, model, epoch, step, optimizer, best_acc_top1, is_best)
示例7: main
# 需要導入模塊: from torch import utils [as 別名]
# 或者: from torch.utils import load [as 別名]
def main():
if not torch.cuda.is_available():
logging.info('No GPU found!')
sys.exit(1)
np.random.seed(args.seed)
torch.manual_seed(args.seed)
torch.cuda.manual_seed(args.seed)
torch.cuda.manual_seed_all(args.seed)
cudnn.enabled = True
cudnn.benchmark = False
cudnn.deterministic = True
args.steps = int(np.ceil(50000 / args.batch_size)) * args.epochs
logging.info("Args = %s", args)
_, model_state_dict, epoch, step, optimizer_state_dict, best_acc_top1 = utils.load(args.output_dir)
build_fn = get_builder(args.dataset)
train_queue, valid_queue, model, train_criterion, eval_criterion, optimizer, scheduler = build_fn(model_state_dict, optimizer_state_dict, epoch=epoch-1)
while epoch < args.epochs:
scheduler.step()
logging.info('epoch %d lr %e', epoch, scheduler.get_lr()[0])
train_acc, train_obj, step = train(train_queue, model, optimizer, step, train_criterion)
logging.info('train_acc %f', train_acc)
valid_acc_top1, valid_obj = valid(valid_queue, model, eval_criterion)
logging.info('valid_acc %f', valid_acc_top1)
epoch += 1
is_best = False
if valid_acc_top1 > best_acc_top1:
best_acc_top1 = valid_acc_top1
is_best = True
utils.save(args.output_dir, args, model, epoch, step, optimizer, best_acc_top1, is_best)
示例8: main
# 需要導入模塊: from torch import utils [as 別名]
# 或者: from torch.utils import load [as 別名]
def main():
if not torch.cuda.is_available():
logging.info('No GPU found!')
sys.exit(1)
np.random.seed(args.seed)
torch.manual_seed(args.seed)
cudnn.enabled = True
cudnn.benchmark = False
cudnn.deterministic = True
torch.cuda.manual_seed(args.seed)
logging.info("Args = %s", args)
_, model_state_dict, epoch, step, optimizer_state_dict, best_acc_top1 = utils.load(args.output_dir)
train_queue, valid_queue, model, train_criterion, eval_criterion, optimizer, scheduler = build_imagenet(model_state_dict, optimizer_state_dict, epoch=epoch-1)
while epoch < args.epochs:
scheduler.step()
logging.info('epoch %d lr %e', epoch, scheduler.get_lr()[0])
train_acc, train_obj, step = train(train_queue, model, optimizer, step, train_criterion)
logging.info('train_acc %f', train_acc)
valid_acc_top1, valid_acc_top5, valid_obj = valid(valid_queue, model, eval_criterion)
logging.info('valid_acc_top1 %f', valid_acc_top1)
logging.info('valid_acc_top5 %f', valid_acc_top5)
epoch += 1
is_best = False
if valid_acc_top1 > best_acc_top1:
best_acc_top1 = valid_acc_top1
is_best = True
utils.save(args.output_dir, args, model, epoch, step, optimizer, best_acc_top1, is_best)
示例9: main
# 需要導入模塊: from torch import utils [as 別名]
# 或者: from torch.utils import load [as 別名]
def main():
if not torch.cuda.is_available():
logging.info('No GPU found!')
sys.exit(1)
np.random.seed(args.seed)
cudnn.benchmark = False
torch.manual_seed(args.seed)
cudnn.enabled = True
torch.cuda.manual_seed(args.seed)
args.steps = int(np.ceil(50000 / args.batch_size)) * args.epochs
logging.info("Args = %s", args)
_, model_state_dict, epoch, step, optimizer_state_dict, best_acc_top1 = utils.load(args.output_dir)
build_fn = get_builder(args.dataset)
train_queue, valid_queue, model, train_criterion, eval_criterion, optimizer, scheduler = build_fn(model_state_dict, optimizer_state_dict, epoch=epoch-1)
while epoch < args.epochs:
scheduler.step()
logging.info('epoch %d lr %e', epoch, scheduler.get_lr()[0])
train_acc, train_obj, step = train(train_queue, model, optimizer, step, train_criterion)
logging.info('train_acc %f', train_acc)
valid_acc_top1, valid_obj = valid(valid_queue, model, eval_criterion)
logging.info('valid_acc %f', valid_acc_top1)
epoch += 1
is_best = False
if valid_acc_top1 > best_acc_top1:
best_acc_top1 = valid_acc_top1
is_best = True
utils.save(args.output_dir, args, model, epoch, step, optimizer, best_acc_top1, is_best)
示例10: main
# 需要導入模塊: from torch import utils [as 別名]
# 或者: from torch.utils import load [as 別名]
def main():
if not torch.cuda.is_available():
logging.info('no gpu device available')
sys.exit(1)
np.random.seed(args.seed)
torch.cuda.set_device(args.gpu)
cudnn.benchmark = True
torch.manual_seed(args.seed)
cudnn.enabled=True
torch.cuda.manual_seed(args.seed)
logging.info('gpu device = %d' % args.gpu)
logging.info("args = %s", args)
genotype = eval("genotypes.%s" % args.arch)
model = Network(args.init_channels, CIFAR_CLASSES, args.layers, args.auxiliary, genotype)
model = model.cuda()
utils.load(model, args.model_path)
logging.info("param size = %fMB", utils.count_parameters_in_MB(model))
criterion = nn.CrossEntropyLoss()
criterion = criterion.cuda()
_, test_transform = utils._data_transforms_cifar10(args)
test_data = dset.CIFAR10(root=args.data, train=False, download=True, transform=test_transform)
test_queue = torch.utils.data.DataLoader(
test_data, batch_size=args.batch_size, shuffle=False, pin_memory=True, num_workers=2)
model.drop_path_prob = args.drop_path_prob
with torch.no_grad():
test_acc, test_obj = infer(test_queue, model, criterion)
logging.info('test_acc %f', test_acc)
示例11: main
# 需要導入模塊: from torch import utils [as 別名]
# 或者: from torch.utils import load [as 別名]
def main():
if not torch.cuda.is_available():
logging.info('no gpu device available')
sys.exit(1)
torch.cuda.set_device(args.gpu)
cudnn.enabled=True
logging.info("args = %s", args)
genotype = eval("genotypes.%s" % args.arch)
if args.dataset in LARGE_DATASETS:
model = NetworkLarge(args.init_channels, CLASSES, args.layers, args.auxiliary, genotype)
else:
model = Network(args.init_channels, CLASSES, args.layers, args.auxiliary, genotype)
model = model.cuda()
utils.load(model, args.model_path)
logging.info("param size = %fMB", utils.count_parameters_in_MB(model))
criterion = nn.CrossEntropyLoss()
criterion = criterion.cuda()
_, test_transform = utils.data_transforms(args.dataset,args.cutout,args.cutout_length)
if args.dataset=="CIFAR100":
test_data = dset.CIFAR100(root=args.data, train=False, download=True, transform=test_transform)
elif args.dataset=="CIFAR10":
test_data = dset.CIFAR10(root=args.data, train=False, download=True, transform=test_transform)
elif args.dataset=="sport8":
dset_cls = dset.ImageFolder
val_path = '%s/Sport8/test' %args.data
test_data = dset_cls(root=val_path, transform=test_transform)
elif args.dataset=="mit67":
dset_cls = dset.ImageFolder
val_path = '%s/MIT67/test' %args.data
test_data = dset_cls(root=val_path, transform=test_transform)
elif args.dataset == "flowers102":
dset_cls = dset.ImageFolder
val_path = '%s/flowers102/test' % args.tmp_data_dir
test_data = dset_cls(root=val_path, transform=test_transform)
test_queue = torch.utils.data.DataLoader(
test_data, batch_size=args.batch_size, shuffle=False, pin_memory=False, num_workers=2)
model.drop_path_prob = 0.0
test_acc, test_obj = infer(test_queue, model, criterion)
logging.info('Test_acc %f', test_acc)