python apache benchmark_Python cudnn.benchmark方法代码示例

本文整理汇总了Python中torch.backends.cudnn.benchmark方法的典型用法代码示例。如果您正苦于以下问题:Python cudnn.benchmark方法的具体用法?Python cudnn.benchmark怎么用?Python cudnn.benchmark使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块torch.backends.cudnn的用法示例。

在下文中一共展示了cudnn.benchmark方法的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: main_inference

​点赞 6

# 需要导入模块: from torch.backends import cudnn [as 别名]

# 或者: from torch.backends.cudnn import benchmark [as 别名]

def main_inference():

print("Loading config...")

opt = TestOptions().parse()

print("Loading dataset...")

dset = TVQADataset(opt, mode=opt.mode)

print("Loading model...")

model = STAGE(opt)

model.to(opt.device)

cudnn.benchmark = True

strict_mode = not opt.no_strict

model_path = os.path.join("results", opt.model_dir, "best_valid.pth")

model.load_state_dict(torch.load(model_path), strict=strict_mode)

model.eval()

model.inference_mode = True

torch.set_grad_enabled(False)

print("Evaluation Starts:\n")

predictions = inference(opt, dset, model)

print("predictions {}".format(predictions.keys()))

pred_path = model_path.replace("best_valid.pth",

"{}_inference_predictions.json".format(opt.mode))

save_json(predictions, pred_path)

开发者ID:jayleicn,项目名称:TVQAplus,代码行数:23,

示例2: test_voc

​点赞 6

# 需要导入模块: from torch.backends import cudnn [as 别名]

# 或者: from torch.backends.cudnn import benchmark [as 别名]

def test_voc():

# load net

num_classes = len(VOC_CLASSES) + 1 # +1 background

net = build_ssd('test', 300, num_classes) # initialize SSD

net.load_state_dict(torch.load(args.trained_model))

net.eval()

print('Finished loading model!')

# load data

testset = VOCDetection(args.voc_root, [('2007', 'test')], None, VOCAnnotationTransform())

if args.cuda:

net = net.cuda()

cudnn.benchmark = True

# evaluation

test_net(args.save_folder, net, args.cuda, testset,

BaseTransform(net.size, (104, 117, 123)),

thresh=args.visual_threshold)

开发者ID:soo89,项目名称:CSD-SSD,代码行数:18,

示例3: extract_features

​点赞 6

# 需要导入模块: from torch.backends import cudnn [as 别名]

# 或者: from torch.backends.cudnn import benchmark [as 别名]

def extract_features(model, data_loader, print_freq=1, metric=None):

cudnn.benchmark = False

model.eval()

batch_time = AverageMeter()

data_time = AverageMeter()

features = OrderedDict()

labels = OrderedDict()

fcs = OrderedDict()

print("Begin to extract features...")

for i, (imgs, fnames, pids, _, _) in enumerate(data_loader):

_fcs, pool5s = extract_cnn_feature(model, imgs)

for fname, fc, pool5, pid in zip(fnames, _fcs, pool5s, pids):

features[fname] = pool5

fcs[fname] = fc

labels[fname] = pid

cudnn.benchmark = True

return features, labels, fcs # 2048 pool5 feature, labels, 1024 fc layers

开发者ID:gddingcs,项目名称:Dispersion-based-Clustering,代码行数:22,

示例4: run

​点赞 6

# 需要导入模块: from torch.backends import cudnn [as 别名]

# 或者: from torch.backends.cudnn import benchmark [as 别名]

def run(self):

self.build_model()

self.resume_and_evaluate()

cudnn.benchmark = True

for self.epoch in range(self.start_epoch, self.nb_epochs):

self.train_1epoch()

prec1, val_loss = self.validate_1epoch()

is_best = prec1 > self.best_prec1

#lr_scheduler

self.scheduler.step(val_loss)

# save model

if is_best:

self.best_prec1 = prec1

with open('record/spatial/spatial_video_preds.pickle','wb') as f:

pickle.dump(self.dic_video_level_preds,f)

f.close()

save_checkpoint({

'epoch': self.epoch,

'state_dict': self.model.state_dict(),

'best_prec1': self.best_prec1,

'optimizer' : self.optimizer.state_dict()

},is_best,'record/spatial/checkpoint.pth.tar','record/spatial/model_best.pth.tar')

开发者ID:CMU-CREATE-Lab,项目名称:deep-smoke-machine,代码行数:26,

示例5: set_gpu

​点赞 6

# 需要导入模块: from torch.backends import cudnn [as 别名]

# 或者: from torch.backends.cudnn import benchmark [as 别名]

def set_gpu(args, model):

assert torch.cuda.is_available(), "CPU-only experiments currently unsupported"

if args.gpu is not None:

torch.cuda.set_device(args.gpu)

model = model.cuda(args.gpu)

elif args.multigpu is None:

device = torch.device("cpu")

else:

# DataParallel will divide and allocate batch_size to all available GPUs

print(f"=> Parallelizing on {args.multigpu} gpus")

torch.cuda.set_device(args.multigpu[0])

args.gpu = args.multigpu[0]

model = torch.nn.DataParallel(model, device_ids=args.multigpu).cuda(

args.multigpu[0]

)

cudnn.benchmark = True

return model

开发者ID:allenai,项目名称:hidden-networks,代码行数:22,

示例6: main

​点赞 6

# 需要导入模块: from torch.backends import cudnn [as 别名]

# 或者: from torch.backends.cudnn import benchmark [as 别名]

def main():

cudnn.benchmark = False

test_video=Test_video(short_side=[224,256])

model = slowfastnet.resnet50(class_num=Config.CLASS_NUM)

assert Config.LOAD_MODEL_PATH is not None

print("load model from:", Config.LOAD_MODEL_PATH)

pretrained_dict = torch.load(Config.LOAD_MODEL_PATH, map_location='cpu')

try:

model_dict = model.module.state_dict()

except AttributeError:

model_dict = model.state_dict()

pretrained_dict = {k: v for k, v in pretrained_dict.items() if k in model_dict}

model_dict.update(pretrained_dict)

model.load_state_dict(model_dict

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值