4441480fde64e42a9c4af205bf2ab8003511172e,test.py,,NN,#Any#Any#Any#Any#Any#Any#,9
Before Change
trainloader.dataset.transform = transform_bak
end = time.time()
for batch_idx, (inputs, targets, indexes) in enumerate(testloader):
inputs, targets = inputs.cuda(), targets.cuda()
inputs, targets = Variable(inputs, volatile=True), Variable(targets)
batchSize = inputs.size(0)
features = net(inputs)
net_time.update(time.time() - end)
end = time.time()
dist = torch.mm(features.data, trainFeatures)
yd, yi = dist.topk(1, dim=1, largest=True, sorted=True)
candidates = trainLabels.view(1,-1).expand(batchSize, -1)
retrieval = torch.gather(candidates, 1, yi)
retrieval = retrieval.narrow(1, 0, 1).clone().view(-1)
yd = yd.narrow(1, 0, 1)
total += targets.size(0)
correct += retrieval.eq(targets.data).cpu().sum()
cls_time.update(time.time() - end)
end = time.time()
print("Test [{}/{}]\t"
"Net Time {net_time.val:.3f} ({net_time.avg:.3f})\t"
"Cls Time {cls_time.val:.3f} ({cls_time.avg:.3f})\t"
"Top1: {:.2f}".format(
total, testsize, correct*100./total, net_time=net_time, cls_time=cls_time))
return correct/total
def kNN(epoch, net, lemniscate, trainloader, testloader, K, sigma, recompute_memory=0):
net.eval()
After Change
trainloader.dataset.transform = transform_bak
end = time.time()
with torch.no_grad():
for batch_idx, (inputs, targets, indexes) in enumerate(testloader):
inputs, targets = inputs.to(device), targets.to(device)
batchSize = inputs.size(0)
features = net(inputs)
net_time.update(time.time() - end)
end = time.time()
dist = torch.mm(features, trainFeatures)
yd, yi = dist.topk(1, dim=1, largest=True, sorted=True)
candidates = trainLabels.view(1,-1).expand(batchSize, -1)
retrieval = torch.gather(candidates, 1, yi)
retrieval = retrieval.narrow(1, 0, 1).clone().view(-1)
yd = yd.narrow(1, 0, 1)
total += targets.size(0)
correct += retrieval.eq(targets.data).cpu().sum().item()
cls_time.update(time.time() - end)
end = time.time()
print("Test [{}/{}]\t"
"Net Time {net_time.val:.3f} ({net_time.avg:.3f})\t"
"Cls Time {cls_time.val:.3f} ({cls_time.avg:.3f})\t"
"Top1: {:.2f}".format(
total, testsize, correct*100./total, net_time=net_time, cls_time=cls_time))
return correct/total
def kNN(epoch, net, lemniscate, trainloader, testloader, K, sigma, recompute_memory=0):
device = "cuda" if torch.cuda.is_available() else "cpu"
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 11
Instances
Project Name: zhirongw/lemniscate.pytorch
Commit Name: 4441480fde64e42a9c4af205bf2ab8003511172e
Time: 2018-07-26
Author: xavibrowu@gmail.com
File Name: test.py
Class Name:
Method Name: NN
Project Name: pytorch/examples
Commit Name: 645c7c386e62d2fb1d50f4621c1a52645a13869f
Time: 2018-04-24
Author: soumith@gmail.com
File Name: mnist_hogwild/train.py
Class Name:
Method Name: test_epoch
Project Name: zhirongw/lemniscate.pytorch
Commit Name: 4441480fde64e42a9c4af205bf2ab8003511172e
Time: 2018-07-26
Author: xavibrowu@gmail.com
File Name: test.py
Class Name:
Method Name: kNN