I read the demo
from __future__ import print_function
import argparse
import os
import random
import torch
import torch.nn as nn
import torch.nn.parallel
import torch.backends.cudnn as cudnn
import torch.optim as optim
import torch.utils.data
import torchvision.datasets as dset
import torchvision.transforms as transforms
import torchvision.utils as vutils
from torch.autograd import Variable
parser = argparse.ArgumentParser()
parser.add_argument('--dataset', required=True, help='cifar10 | lsun | imagenet | folder | lfw | fake')
parser.add_argument('--dataroot', required=True, help='path to dataset')
parser.add_argument('--workers', type=int, help='number of data loading workers', default=2)
This file has been truncated. show original
I don’t understand this correct += pred.eq(target.data).cpu().sum().
Why do you use .cpu() function?
apaszke
(Adam Paszke)
March 1, 2017, 4:01pm
2
I can’t see that line in the link you posted.
from __future__ import print_function
import argparse
import os
import random
import torch
import torch.nn as nn
import torch.nn.parallel
import torch.backends.cudnn as cudnn
import torch.optim as optim
import torch.utils.data
import torchvision.datasets as dset
import torchvision.transforms as transforms
import torchvision.utils as vutils
parser = argparse.ArgumentParser()
parser.add_argument('--dataset', required=True, help='cifar10 | lsun | mnist |imagenet | folder | lfw | fake')
parser.add_argument('--dataroot', required=False, help='path to dataset')
parser.add_argument('--workers', type=int, help='number of data loading workers', default=2)
parser.add_argument('--batchSize', type=int, default=64, help='input batch size')
This file has been truncated. show original
Can you see the link?
It is the mnist example in pytorch example!
Thanks very much
smth
March 2, 2017, 3:20am
4
as you see in the comment of the line above the one you highlighted, pred
has the index of the max log-probability
. Hence, checking pred
== target
and summing total correct predictions in the mini-batch adds up to total correctly predicted.
But why use cpu() ?
It seems that using correct += pred.eq(target.data).sum() would be faster
smth
March 2, 2017, 3:40pm
6
hmmm, cpu()
can probably be removed.